Skip to content

fix(orcad): a liveness probe must not mistake its own shell for orcad - #33158

Merged
nwparker merged 5 commits into
mainfrom
nwparker/orcad-liveness-own-shell
Oct 24, 2026
Merged

nwparker merged 5 commits into
mainfrom
nwparker/orcad-liveness-own-shell

Conversation

@nwparker

@nwparker nwparker commented Oct 24, 2026 •

Copy link
Copy Markdown
Contributor
Files Added Deleted Net
Test 1 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​71 0 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​71
Prod 1 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​4 $\color{#cf222e}{\Huge{\mathbf{−}}}$​1 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​3

ELI5

To decide whether Orca's server on a remote machine is still running, Orca reads the process number it saved at launch and checks whether that process is alive. After the machine restarts, that number is free, and the shell running the check itself can be given it. The check then saw itself, decided the server was running, and didn't start it. The connection failed, and you had to try again. Now the check never counts itself, or any shell, as the server.

What Changed

  • Before: orcadLivenessProbeCommand identified orcad by PID plus argv: the process's arguments had to contain the slot's launcher or server path.
    • The probe runs as sh -c '<script>', and the script itself contains those paths.
    • When the recorded PID was the probe shell's own PID, ps -o args= matched and kill -0 succeeded, so the answer was LIVE.
    • This is possible after a reboot, when PIDs restart and a deterministic startup sequence can land on the same number.
  • After: orcad_reused treats a recorded PID as reused when it is the probe's own shell ($$), or the shell that wraps it ($PPID, as with an SSH or wsl.exe command wrapper). Everything else is unchanged, and Windows uses its own creation-time check.
    • On purpose, other shells are not excluded:
      • Launchers from before exec was added recorded a shell that waits on a live orcad.
      • The setsid launch path briefly holds an sh between writing the PID and exec.
    • Calling those reused would turn a live orcad into DEAD, and DEAD permits GC and relaunch.
  • Who's affected: any managed orcad on a POSIX host, so SSH hosts after a restart and WSL hosts after a distro restart.
    • The wake path read LIVE and skipped the start.
    • The readiness probe a moment later, in a different shell, read DEAD.
    • The connect failed with "orcad … is recorded active but its process has exited."

Why

  • This is the narrowest identity fix: the probe already relies on argv, and this only excludes the probe's own process chain, which is the one thing that is sure to carry those paths without being orcad.
  • Alternatives considered:
    • Compare the recorded boot id. It doesn't help a WSL distro restart, where the kernel stays up and boot_id doesn't change.
    • Record the process start time. That's a launch-format change for older slots.

Linked Issue

Internal: WSL via orcad D3 startup (a cold wake that needed a click); also affects managed SSH hosts after a reboot.

Visual Proof

N/A. This changes the remote liveness probe; the user-visible effect is that a reconnect after a host restart no longer fails with "recorded active but its process has exited".

Testing

  • I manually tested these changes locally: seen on a real Windows box (WSL 2.7.10, systemd distro) as an intermittent cold-start connect failure. The milestone logs showed the wake reading "serving" and the probe reading "exited" 0.4 s apart.

  • Automated tests added/updated: orcad-remote-launch.test.ts now runs the real probe in sh.

    • A recorded PID held by the probe's own shell, or by the shell wrapping it, reads DEAD. Both read LIVE before this change, and the test fails without each clause.
    • A live node <slot>/orcad.js still reads LIVE, and so does an older launcher's waiting shell.
    • The tests poll ps for the process's argv instead of sleeping.
  • An independent review found a blocking issue in the first version, which also excluded every shell; it's fixed as described above.

  • Reproduced live in Docker. A fresh container stands in for a rebooted host, and its recorded PID is the one the next probe shell gets. The probe from main reads LIVE on both debian (dash) and alpine (busybox ash), and the probe from this PR reads DEAD on both.

  • The wrapped-shell case keeps its outer shell alive (; :), so the $PPID clause is exercised on dash as well, not only on bash 3.2. With that clause removed, the test fails.

  • The older-launcher fixture now runs in its own process group, and cleanup kills the whole group, so no idle node child is left behind after the test.

  • PR checks, including both shards of ssh on managed orcad (Docker), passed on the previous head.

Review

Agent skill upstream boundary

  • Not applicable, or this change copies or mechanically translates no upstream skill-installer source, tests, fixtures, registry entries, path tables, comments, or documentation.

Notes

  • POSIX probe only, and no wire change.
  • SSH and WSL both benefit; Windows hosts are unchanged.

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)

@coderabbitai

coderabbitai Bot commented Oct 24, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

Note

Reviews paused

It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review

No actionable comments were generated in the recent review.

Recent 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: 0d14be1a-996d-41bc-a2fa-bf26d4febc83
Commits

Reviewing files that changed from the base of the PR and between 928a9c6 and 8817106.

Files selected for processing: 1
  • src/main/managed-server/install/orcad-remote-launch.test.ts

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

Walkthrough

The liveness probe now treats its own PID and its parent shell’s PID as reused PIDs and classifies them as DEAD. For other PIDs, it checks launcher or server arguments and then process liveness. POSIX integration tests check dead results for probe-owned PIDs and live results for a running orcad.js process and a shell waiting on Node. The tests clean up temporary files and spawned processes.

Priority: Normal

Merge Risk: Minimal · up to 88171

The liveness classification and POSIX test cleanup are sound; no actionable merge-blocking risk remains.

Pre-merge checks: Passed 4 · Failed 1

Failed Failed checks: 1 warning

Check name Status Explanation Resolution
Docstring Coverage Warning Docstring coverage is 33.33% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 3 functions across 2 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
Passed Passed checks: 4 passed
Check name Status Explanation
Title check Passed The title clearly and concisely describes the primary change: preventing the liveness probe from treating its own shell as the orcad process.
Description check Passed The description is comprehensive and follows the template. It explains the failure, implementation, scope, alternatives, testing, and cross-platform impact. The linked issue is described but no actual…
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Full details: Description check

Explanation

The description is comprehensive and follows the template. It explains the failure, implementation, scope, alternatives, testing, and cross-platform impact. The linked issue is described but no actual issue link is provided, and the standard command checklist remains unchecked.

Finishing Touches: 💡 1
📝 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: 1


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: 17b05690-8115-487b-b526-41ae24e9c31a
Commits

Reviewing files that changed from the base of the PR and between 0f91578 and 506aed1.

Files selected for processing: 2
  • src/main/managed-server/install/orcad-remote-launch.test.ts
  • src/main/managed-server/install/orcad-remote-launch.ts

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

@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: b3a94a59-379e-45dd-ad8b-85ffffb132a4
Commits

Reviewing files that changed from the base of the PR and between 506aed1 and 1a7105b.

Files selected for processing: 2
  • src/main/managed-server/install/orcad-remote-launch.test.ts
  • src/main/managed-server/install/orcad-remote-launch.ts

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

Comment on lines +176 to +177
orcad.kill()
waiting.kill()

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 · Stability & Availability · Quick win

Terminate the waiting shell’s Node child.

The ; : command keeps the waiting shell alive while a separate Node process runs. waiting.kill() signals only the shell PID. The Node child can continue running after withSlot removes its temporary directory. Start the waiting shell in its own process group and terminate the group during cleanup.

nwparker added a commit that referenced this pull request Oct 24, 2026
After a host or distro restart the recorded orcad PID is free, and the probe's own
'sh -c' (whose argv carries the slot paths) can be given it. The argv identity
check matched and kill -0 succeeded, so the probe answered LIVE: a wake skipped
the start and the next probe found nothing. The probe now treats its own PID, or
any shell process, as a reused PID.
…r shell

Review: an older launcher (before exec) recorded a shell that waits on a live
orcad, and the setsid launch path holds an sh between the PID write and exec;
calling every shell reused turned those into DEAD, which permits GC and relaunch.
Only the probe's own shell and the shell wrapping it are now excluded.
@nwparker
nwparker force-pushed the nwparker/orcad-liveness-own-shell branch from 033e8a9 to 928a9c6 Compare October 24, 2026 20:41

@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.

🧹 Nitpick comments: 1
src/main/managed-server/install/orcad-remote-launch.test.ts: 1

152-152: Trivial · Maintainability & Code Quality · Quick win

Keep the wrapper shell as the parent in the parent-PID test.

When the outer shell runs its final command, it can replace itself with that command. The inner sh -c then takes the recorded PID, so its $$ equals the recorded value. The DEAD assertion can pass through the $$ check alone. Removing the $PPID check would not fail this test.

Appending ; : makes the inner sh -c a non-final command. The outer shell then stays alive as the inner shell's parent. The inner probe's $PPID equals the recorded PID, so this test exercises the $PPID guard.

This is a test-coverage gap. The production probe already treats both $$ and $PPID as reused PIDs, so this change does not fix a current production failure.

Suggested fix
-            `echo $$ > '${slot}/.orcad-pid'; sh -c ${JSON.stringify(probe).replace(/\$/g, '\\$')}`
+            `echo $$ > '${slot}/.orcad-pid'; sh -c ${JSON.stringify(probe).replace(/\$/g, '\\$')}; :`

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: bf84517d-4b56-40f6-885f-4f6cce9e0f38
Commits

Reviewing files that changed from the base of the PR and between 033e8a9 and 928a9c6.

Files selected for processing: 1
  • src/main/managed-server/install/orcad-remote-launch.test.ts

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

@nwparker
nwparker merged commit 08ec2b3 into main Oct 24, 2026
92 of 95 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