Repository navigation
fix(ssh): start a stopped managed server whose recycled PID hid it on hosts without ps - #34519
Conversation
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>
Walkthrough
Priority: Severity of issue fixed: Medium Merge Risk:
|
There was a problem hiding this comment.
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
Files selected for processing: 4-
src/main/managed-server/install/orcad-remote-host-support.tssrc/main/managed-server/install/orcad-remote-launch.tssrc/main/managed-server/install/orcad-remote-shell-commands.integration.test.tstests/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##*") "}; ' + |
There was a problem hiding this comment.
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" ] && ' + |
There was a problem hiding this comment.
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.
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
pstool, 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/procwhenpsis missing.What Changed
ps(for exampledebian:bookworm-slim), after a reboot the slot's.orcad-pidoften names a new process.ps -o args=. A recycled PID therefore read asLIVEwhen the process belonged to the same user, orUNKNOWNwhen it was root-owned (EPERM).psis missing or prints nothing, the probe reads argv from/proc/<pid>/cmdlineand the zombie state from/proc/<pid>/stat.pspresent, nothing changes.DEAD, so the existing wake starts the active slot and the update check runs against a live server.Why
boot_idin.orcad-pid-machineas 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 theboot_id.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-pidat a live non-orcad process, hidesps, then reconnects.serving: { state: 'unverifiable', detail: 'This host’s Orca server process is live but is not answering.' }.New Linux-only integration test: with
psshadowed, a recycled PID readsDEADand a live slot readsLIVE. The zombie test also checks the no-pspath.Generated probe in containers: I ran it in dash, bash and busybox ash (
node:22-bookworm,debian:bookworm-slim,busybox,--pid=hostfor kernel threads). Results are identical across shells:LIVEwithps, withoutps, and withoutpsortr.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-lineserror interminal-send-method.ts, which this PR doesn't touch; that file is the same length on the base.Notes
ps, so their behavior is unchanged.psbehave as before.Checklist
N/Awith reasonpnpm lint,pnpm typecheck,pnpm test, andpnpm buildpass (or CI will cover; local preferred)