Skip to content

fix(ssh): start a stopped managed server whose recycled PID hid it on hosts without ps - #34519

Merged
nwparker merged 3 commits into
mainfrom
fix/34149-orcad-deferred-start
Oct 27, 2026
Merged

nwparker merged 3 commits into
mainfrom
fix/34149-orcad-deferred-start

Conversation

@nwparker

@nwparker nwparker commented Oct 27, 2026 •

Copy link
Copy Markdown
Contributor

ELI5

When an SSH host restarts, Orca checks whether its old server is still running by looking up the process number it saved. On small Linux images that don't include the ps tool, Orca couldn't tell that this number now belonged to a different program. It assumed the old server was still alive, so it never started a new one, and the host stayed unreachable. Orca now reads the same information from /proc when ps is missing.

What Changed

  • Before: on a host without ps (for example debian:bookworm-slim), after a reboot the slot's .orcad-pid often names a new process.
    • The liveness probe's PID-reuse check reads argv only through ps -o args=. A recycled PID therefore read as LIVE when the process belonged to the same user, or UNKNOWN when it was root-owned (EPERM).
    • The wake path only starts a slot that is proven exited, so it refused every time.
    • The update check then uploaded the new slot and deferred with "couldn't confirm what's running", because the census needs a running server. The host was left with nothing running.
  • After: when ps is missing or prints nothing, the probe reads argv from /proc/<pid>/cmdline and the zombie state from /proc/<pid>/stat.
    • Kernel threads and zombies have no argv, so their stat line names them instead.
    • A failed read stays unproven. A live server is never reported as exited.
    • With ps present, nothing changes.
    • The probe now reports the recycled PID as DEAD, so the existing wake starts the active slot and the update check runs against a live server.
  • Same fix applies to: the stop command's zombie check and slot GC, which share the same shell helpers.

Why

  • Why this approach: the probe already proves PID reuse by argv identity. This applies the same rule using the kernel's own record, so the safety model does not change: only positive evidence proves exit.
  • Alternatives considered:
    • Treating a different boot_id in .orcad-pid-machine as proof of exit was rejected. Hostname plus boot cannot rule out another machine that shares the home directory, and it does not help Docker container restarts, which keep the boot_id.
    • Starting a server whenever an update defers was rejected. It would double-run the server when the old one really is alive.

Linked Issue

Refs #34149

Thanks to @AISIN-KosukeHirano for the detailed report: the stale PID, boot ID and lock observations made this reproducible.

Visual Proof

N/A: no UI change. The host now connects instead of showing "Unreachable / update deferred".

Testing

  • I manually tested these changes locally

  • Automated tests added/updated, or explained why not below

  • New Docker e2e (ssh-orcad-idle-exit.spec.ts: "after a reboot on a host without ps, a recycled server PID does not keep the server down"): it kills the server, points .orcad-pid at a live non-orcad process, hides ps, then reconnects.

    • On origin/main it fails with serving: { state: 'unverifiable', detail: 'This host’s Orca server process is live but is not answering.' }.
    • With the fix it passes.
  • New Linux-only integration test: with ps shadowed, a recycled PID reads DEAD and a live slot reads LIVE. The zombie test also checks the no-ps path.

  • Generated probe in containers: I ran it in dash, bash and busybox ash (node:22-bookworm, debian:bookworm-slim, busybox, --pid=host for kernel threads). Results are identical across shells:

    • Live slot reads LIVE with ps, without ps, and without ps or tr.
    • A stranger PID, a zombie, a kernel thread and a missing PID all read DEAD.
  • Docker managed-orcad lane subset (idle-exit, update-anyway, shared-home-machines, retained-upgrade-state, terminal-journeys): 11/11 passed locally.

  • Static job: typecheck and the full static job pass locally. The one exception is a max-lines error in terminal-send-method.ts, which this PR doesn't touch; that file is the same length on the base.

Notes

  • Platforms:
    • Windows remote hosts use their own probe and are unchanged.
    • macOS and FreeBSD hosts always have ps, so their behavior is unchanged.
    • Linux hosts with ps behave as before.
  • Compatibility: desktop-side only. There is no wire or protocol change, so mixed client and host versions are unaffected.

Checklist

  • This PR is small and focused
  • I explained what changed and why (ELI5, the user-facing before/after, the mechanism, and why over the alternatives)
  • Before/after screenshots or videos attached for UI changes, or N/A with reason
  • Self-reviewed for correctness, security, and performance
  • Cross-platform, SSH/remote, and path/shortcut impact considered (or N/A)
  • pnpm lint, pnpm typecheck, pnpm test, and pnpm build pass (or CI will cover; local preferred)

nwparker and others added 3 commits October 26, 2026 21:48
On slim Linux images that ship no ps, the managed server's liveness probe
could not read the recorded PID's argv, so after a reboot a PID that now
named another process read as LIVE (same user) or UNKNOWN (root). The wake
then refused to start the stopped server, the update deferred on the
terminal census, and the host stayed unreachable. Read argv and the
zombie state from /proc when ps is missing.

Fixes #34149

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
Kernel threads and zombies have an empty cmdline, so a recycled PID owned
by one stayed UNKNOWN on hosts without ps. Quote the stat pattern so the
probe also parses inside command substitution on older bash.

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
A failed tr must stay unproven rather than make a live server's PID look
recycled.

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
@coderabbitai

coderabbitai Bot commented Oct 27, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

Walkthrough

The change adds /proc fallbacks for process state and argument checks when ps is unavailable or returns no result. The liveness probe uses the shared argument helper to inspect candidate PIDs. Linux integration and Docker-gated end-to-end tests cover PID reuse and zombie detection without `ps.

Priority: Normal

Severity of issue fixed: Medium

Merge Risk: Moderate · up to 73865

The change fixes recycled-PID detection on Linux hosts without ps. If /proc reads fail, for example under hidepid, the probe can still report a live server that is not the managed one. That can leave the managed server down after a reboot. These cases need to report UNKNOWN before merge.

Pre-merge checks: Passed 5
Check name Status Explanation
Title check Passed The title names the main change: a stopped managed server whose recycled PID hid it is now started on hosts without ps. It matches the /proc fallback, the probe change, and the e2e scenario. It uses a…
Description check Passed The description follows the template closely. It has ELI5, What Changed (before/after and mechanism), Why (with alternatives considered), Linked Issue (Refs #34149, not the 'Fixes #' form), Visual Pro…
Linked Issues check Passed For [#34149], the PR adds a Linux /proc fallback for process arguments and process state when ps is missing or empty. The liveness probe now identifies a recycled PID as DEAD and keeps failed re…
Out of Scope Changes check Passed The changed source files support the [#34149] liveness fix. The shared helper change also updates the stop and garbage-collection checks that use the same process probes. The integration and end-to-en…
Docstring Coverage Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Documentation-only edits and deletions within survi…
Full details: Title check

Explanation

The title names the main change: a stopped managed server whose recycled PID hid it is now started on hosts without ps. It matches the /proc fallback, the probe change, and the e2e scenario. It uses a conventional fix(ssh) prefix and is specific. The title is 86 characters, which is longer than ideal for a concise title, but the content is accurate.

Full details: Description check

Explanation

The description follows the template closely. It has ELI5, What Changed (before/after and mechanism), Why (with alternatives considered), Linked Issue (Refs #34149, not the 'Fixes #' form), Visual Proof marked N/A with a reason, Testing with checked boxes and detailed steps, Notes covering platforms and compatibility, and a completed checklist. The AI Disclosure section is left blank, which is acceptable only if the author is a StablyAI team member. The Review section and the Agent skill upstream boundary checkbox are not addressed. The Linked Issue section uses 'Refs' rather than 'Fixes', which the template says is insufficient for outside contributors. The author's membership status is not stated, so the AI Disclosure section cannot be confirmed as correctly omitted.

Resolution

Confirm whether the author is a StablyAI team member. If not, fill in the AI Disclosure section. Also, the template says outside contributors must link an actual issue with 'Fixes #', but the description uses 'Refs #34149'. Change this to a 'Fixes' link or confirm the author qualifies as an internal contributor. Address the empty Review section and the unchecked Agent skill upstream boundary item, or mark it not applicable.

Full details: Linked Issues check

Explanation

For [#34149], the PR adds a Linux /proc fallback for process arguments and process state when ps is missing or empty. The liveness probe now identifies a recycled PID as DEAD and keeps failed reads unproven. The existing wake path can therefore restart the active slot before the update census runs. The added Linux integration coverage checks recycled and live PIDs and the no-ps zombie path. The added Docker end-to-end test covers reconnection with a recycled PID on a host without ps.

Full details: Out of Scope Changes check

Explanation

The changed source files support the [#34149] liveness fix. The shared helper change also updates the stop and garbage-collection checks that use the same process probes. The integration and end-to-end tests verify the reported failure mode and related safety behavior. No unrelated product behavior or protocol change is shown.

Full details: Docstring Coverage

Explanation

Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Documentation-only edits and deletions within surviving functions are included; unchanged diff context and fully deleted functions are excluded. Analyzed 3 functions across 4 files.

Finishing Touches
📝 Generate docstrings
  • Commit to this branch
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2


Review info
Run configuration
  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Repository UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 0e1c7d25-4e49-4b41-9d05-0495de3abade
Commits

Reviewing files that changed from the base of the PR and between 32a9b3b and 7386502.

Files selected for processing: 4
  • src/main/managed-server/install/orcad-remote-host-support.ts
  • src/main/managed-server/install/orcad-remote-launch.ts
  • src/main/managed-server/install/orcad-remote-shell-commands.integration.test.ts
  • tests/e2e/ssh-orcad-idle-exit.spec.ts

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 7 remain after this review.

'case "$(ps -o stat= -p "$1" 2>/dev/null)" in Z*) return 1;; esac; return 0; };'
'orcad_stat=$(ps -o stat= -p "$1" 2>/dev/null) && [ -n "$orcad_stat" ] || ' +
// Field 3 of /proc/<pid>/stat follows the last ")": comm itself may hold spaces or parens.
'orcad_stat=$(cat "/proc/$1/stat" 2>/dev/null) && orcad_stat=${orcad_stat##*") "}; ' +

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Minor · Functional Correctness · Quick win

Keep a failed stat read unproven.

If ps supplies no status and /proc/$1/stat cannot be read, orcad_alive still returns success. The probe can report LIVE without checking whether the PID is a zombie. Return UNKNOWN when both status reads fail; do not turn the read failure into DEAD. Linux reports zombie state in the stat file. (man7.org)

// restart either can hold the old PID. A shell elsewhere may be an older launcher's live parent.
'orcad_reused() { { [ "$1" = "$$" ] || [ "$1" = "$PPID" ]; } && return 0; ' +
'args=$(ps -o args= -p "$1" 2>/dev/null) && [ -n "$args" ] && ' +
'args=$(orcad_args "$1") && [ -n "$args" ] && ' +

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Major · Functional Correctness · Quick win

Do not report LIVE when argv inspection fails.

On a host without ps, a failed tr command makes orcad_args fail. orcad_reused then returns false, and a successful kill -0 and stat read make the probe report LIVE even if the PID belongs to another process. The recorded slot can remain down because the probe never establishes PID identity. Propagate the argument-read failure as UNKNOWN instead of treating it as a matching process.

@nwparker
nwparker merged commit 9a51b98 into main Oct 27, 2026
63 of 64 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant