Repository navigation
feat(ssh): remote orcad stop by request file and journaled decommission (#16741 T6-4) - #24449
Conversation
…on (#16741 T6-4) Clients stop an orcad that advertises health.stopRequests through its slot-local request file and keep SIGTERM for older builds. Decommission runs through the activation journal and fence: it refuses while the terminal census is live or uncounted, stops the instance with an instance-bound managed request, cancels a stop orcad never acted on, and deactivates the record only on proven exit. orcad gains --cancel-managed-stop and an exclusive per-transaction decision file so a cancel can never race a dispatched stop. POSIX-only and inert: no production caller.
|
| const census = censusRefusal(options.census) | ||
| if (census) { | ||
| return census | ||
| } |
There was a problem hiding this comment.
Late terminal bypasses refusal If a terminal starts after the caller counts zero sessions, this check still allows decommission to send the stop request. The daemon detects the live terminal and stays up, but its
live retirement result does not prevent the code from committing active: null. Decommission reports success while a terminal is still running and no orcad version is active.
Knowledge Base Used: Remote connectivity and execution
There was a problem hiding this comment.
ℹ️ No critical issues — one coverage note worth a look before merge.
Reviewed changes
- Capability advertisement —
orcadpublisheshealth.stopRequests: 1so clients can tell a stop-request-aware build from an older one (optional, additive field). - Stop by request file —
stopOrcadCommandreads the readiness PID aspid:modeand, for capable builds, writes the slot-local.orcad-stop-requestinstead of sendingSIGTERM; older builds keepSIGTERM. Launch clears a stale request first. - Cancel command — new
orcad --cancel-managed-stop, arbitrated against the running orcad by an exclusivelinkSyncon<transactionId>.decision.json, so exactly one side wins and a cancel can never claim success for a stop orcad already began. - Journaled decommission —
decommissionRemoteOrcadruns under the existing activation fence/journal, refuses on a leftover journal / changed record / no active version / live-or-uncounted terminal census, and writes the deactivated record (active: null) only after exit is proven. - Crash recovery —
keep-serving/resume-stop/confirm-decommissionedrecovery plans, withconfirm-decommissionedre-provingDEADvia the slot liveness probe before committing. - Remote-wire tolerance — completion and cancellation schemas switched from
.extendtoz.object({...shape})so a newer host's extra fields don't break an older client.
I traced the deactivation gate, the hard-link decision arbitration, and the phase/recovery mapping against the surrounding code, and confirmed the two load-bearing invariants: the deactivated record is never written without proven exit (and recovery independently re-proves DEAD), and the decision file gives exactly one winner. The crash-sweep tests in orcad-remote-decommission.test.ts are genuine — they assert a specific end state (expectExactlyTheRecordedSlot) for every mutation, not a tautology.
ℹ️ The "unknown operation" recovery tests no longer exercise an unknown operation
This PR adds decommission as a member of OrcadActivationTransaction's discriminated union. Two existing tests use operation: 'decommission' precisely because it used to be unknown, and they still pass — but now only because their JSON is an invalid decommission (missing activeVersion, request, and, in the crash test, every common field), not because the operation is unrecognized. The forward-compatibility path they were written to pin (an older client reading a newer host's operation must keep the fence, docs/reference/remote-wire-compatibility.md) is effectively untested.
Technical details
# Unknown-operation recovery coverage is now silently invalid
## Affected sites
- `src/main/ssh/orcad-activation-transaction.test.ts:90` — `['an unknown operation, so an older client keeps a newer fence', { operation: 'decommission' }]`. After this PR, the union matches `decommission`, and the patched object fails the decommission branch for *missing required fields*, so it reads `unreadable`.
- `src/main/ssh/orcad-activation-crash-recovery.test.ts:218` — `host.journal = JSON.stringify({ schemaVersion: 1, operation: 'decommission' })`. Same: rejected as a malformed decommission, not as an unknown operation.
## Required outcome
Coverage for "a newer host writes an operation this client does not know, so the client keeps the fence" must be restored, distinct from "a malformed transaction reads as unreadable".
## Suggested approach
Use a value that cannot become a real operation (e.g. `operation: 'reanimate'`) for the unknown-operation cases, and/or add a valid `decommission` journal to the crash test to cover the newly-introduced recovery path. Both sites are outside the diff hunks, so they could not be anchored inline.ℹ️ Nitpicks
OrcadTerminalCensusSchema(src/shared/orcad-terminal-census.ts) is exported but never parsed anywhere — only the TS type is consumed. Likely a forward contract for T6-5/T6-6; flagging so it isn't assumed to be enforcing anything at runtime today.
deepseek-v4.1-flash (free via Pullfrog for OSS) | 𝕏
|
Navigate logical layers of code changes, visualize relationships, and explore their blast radius. 🧰 Additional context used📚 Code guidelines (1)No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Repository UI Review profile: CHILL Plan: Advanced Run ID: 📒 Files selected for processing (33)
Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 8 remain after this review. 📝 WalkthroughWalkthroughThe change adds managed-stop cancellation with an exclusive decision between cancellation and dispatch. Orcad health advertises stop-request support, which remote process control uses for supported builds. Remote slot decommissioning now uses an activation transaction, checks terminal census results, settles managed stops, and updates the active version only after process exit is confirmed. Priority: ⬇️ Low Merge Risk: ⚪ Minimal · up to This change adds managed-stop cancellation and journaled decommissioning that no production code calls yet, and it keeps SIGTERM for older builds. No concrete merge-blocking risk was found in the supplied material. Security Architecture ReviewSecurity architecture risk: 🔵 Low · up to Managed decommissioning targets a specific running instance and preserves the recovery fence when shutdown is uncertain. No introduced security vulnerability was established in the inspected paths. Terminal-daemon retirement remains best effort, so a stopped server does not guarantee that all terminals are gone. Caller and deployment coverage remains incomplete. Retained concerns Security review detailsSecurity Blast Radius
Trust Boundaries and Controls
Resilience and Maintainability Implications
Hardening Proposals
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
Full details: Docstring CoverageExplanation Docstring coverage is 33.93% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 56 functions across 32 files. (1 skipped: 1 unsupported.)
✨ Finishing Touches 💡 2📝 Generate docstrings 💡
🛠️ Fix failing CI checks 💡
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. Comment |
* Revert "feat(orcad): source-side dormant export of a relay-hosted SSH target (#16741 T6-8) (#24519)" This reverts commit 783101b. * Revert "feat(ssh): update, roll back, recover and stop a managed orcad server (#16741 T6-5 follow-up) (#24463)" This reverts commit 38c2d1d. * Revert "feat(ssh): deploy and pair an empty managed orcad server over SSH (#16741 T6-5) (#24453)" This reverts commit 8b76683. * Revert "fix(ssh): orcad GC honors the activation journal; readiness requires proven daemon coverage (#16741 T6 follow-up) (#24451)" This reverts commit d3f8c50. * Revert "feat(ssh): remote orcad stop by request file and journaled decommission (#16741 T6-4) (#24449)" This reverts commit 43d9b43. * Revert "feat(orcad): supervisable server: stop requests, managed stop receipts and a lifetime that keeps its lock on failed teardown (#16741 T6-3) (#24433)" This reverts commit b093d3a. * Revert "feat(ssh): crash-safe orcad activation, rollback and recovery (#16741 T6-2) (#24423)" This reverts commit 1a9ac0e. * Revert "feat(runtime): SSH access links for paired servers in a downgrade-safe sidecar (#16741 T5-1+T5-2) (#24420)" This reverts commit 99db2bf. * Revert "feat(relay): capability-gated owner reset with a durable preparation journal (#16741 T3 R1) (#24418)" This reverts commit 34a582b. * Revert "feat(ssh): track connection-manager drains, test probes and provider continuations (#16741 T2 P3+P8a) (#24407)" This reverts commit d53063d. * Revert "feat(daemon): idle retirement, session census and recovery-only provider (#16741 T2 P4b) (#24409)" This reverts commit ff212db. * Revert "feat(ssh): add pty.resumeClient and split SSH PTY process listing (#16741 T2 P5+P6) (#24414)" This reverts commit 92cb717. * Revert "feat(relay): await owned watcher and agent children on shutdown (#16741 T2 P1) (#24400)" This reverts commit 6b36e4f. * Revert "feat(session): retry failed renderer session writes and verify local folder PTYs (#16741 T2 P9) (#24406)" This reverts commit d23ecef. * Revert "feat(ssh): remote orcad primitives on the pinned Node runtime (#16741 T6-1) (#24419)" This reverts commit dd87ae5. * Revert "fix(runtime): fence runtime-environment subscriptions and status probes by identity (#16741 T5-3) (#24421)" This reverts commit ece9e4d. * Revert "feat(orcad): migration manifest and dormant-state contracts (#16741 T6-7) (#24422)" This reverts commit 3fbdaba. * Revert "feat(ssh): wire SshConnection through the work and transport close ledgers (#16741 T2 P2) (#24401)" This reverts commit 4e8edc8. * Revert "feat(profiles): carry markdown frontmatter visibility in project transfers (#16741 T2 P7) (#24405)" This reverts commit 60c9326. * Revert "fix(runtime): project the PTY incarnation onto mobile session tabs (#24413)" This reverts commit 99e0303. * Revert "feat(daemon): tag daemon stream data with the PTY incarnation id (#16741 T2 P4a) (#24402)" This reverts commit 817af76. * Revert "feat(ssh): port the SSH connection work ledger and transport close ledger (#16741 T2) (#24210)" This reverts commit c991893. * Revert "feat(relay): fence and drain file and git response streams on shutdown (#24185)" This reverts commit dc08ffe. * Revert "refactor(runtime-rpc): extract the Node WebSocket lifecycle; opt-in pinned port (#24186)" This reverts commit a789233. * Revert "feat(relay): route relay handlers through work admission; producer publication drain (#24181)" This reverts commit 0b812bd. * Revert "feat(relay): land the #16741 T1 seam (work drain, publication drain, release gate) (#24156)" This reverts commit 3aa2d3a. --------- Co-authored-by: m4air <[email protected]>

ELI5
Orca can now stop a remote
orcadserver, and "decommission" it so no version is left running, without ever sending a signal to a process ID that the operating system may have handed to another program.Nothing calls this code yet, so users see no change.
What Changed
Before:
orcadwithSIGTERMto a PID, even though T6-3 madeorcadconsume stop-request files.After:
Stopping a slot
orcad-remote-process-control.ts:stopOrcadCommandreads the slot's readiness line, as before, to confirm that its PID matches the launcher's. If that readiness advertiseshealth.stopRequests: 1, the command writes.orcad-stop-requestin the slot directory and waits for the process to exit.SIGTERM. Builds without that field are stopped withSIGTERMexactly as before. So does a candidate this client has just launched, which has published no readiness yet.orcadpublishesstopRequests: 1in its readinesshealth, throughorcad-health.ts. The field is optional and additive.Decommission
New files:
orcad-remote-stop.ts,orcad-decommission-transaction.ts,orcad-decommission-stop.ts,orcad-decommission-recovery.ts.decommissionRemoteOrcadruns under T6-2's activation fence and journal, in this order:live), or could not count them (unverifiable).orcad-managed-remote-stop.tsidentifies the running process from two host files that must agree: the slot's readiness line (runtime ID, PID, stop-request support) and the data root'sorcad.lock(PID, start time, nonce). If they don't agree, or the build predates stop requests, it refuses before writing anything.decommissionjournal entry, then journals the exact stop request before sending it anywhere.orcad --complete-managed-stopwithretireIdleDaemon: true. This retires the daemon too when the daemon is idle.exiteddoes it set the activation record to deactivated:active: null, with the stopped version kept aspreviousso cleanup (GC) leaves that slot alone. The result reports the daemon's retirement outcome.liveorunverifiable), it runsorcad --cancel-managed-stop:canceled:orcadnever acted on the request and keeps serving. The fence is released and the record is unchanged.dispatched, or no answer: the fence is kept for recovery.Recovery (
recoverInterruptedOrcadActivation) acts on the journal phase:prepared(nothing was sent)stop-dispatchedprocess-exited, or the record already committedCancelling a managed stop
orcad's side:orcad --cancel-managed-stop '<request>'is added inorcad-managed-stop-cancellation.tsandorcad-managed-stop-command.ts, and dispatched frommain.ts.orcad's request listener and the canceller each try to create<transactionId>.decision.jsonwith a hard link, which fails if the file already exists (orcad-managed-stop-decision.ts). Whichever creates it first wins. The other reads the winner's decision. A cancel therefore never reports success for a stop thatorcadalready began.Shared contracts
src/shared/orcad-terminal-census.tsholds the census contract (now a zod schema).orcad-update-plan.tsre-exports its type.src/shared/orcad-decommission.tsdefines the decommission result.src/shared/orcad-stop-request.tsgains the cancel flag, the decision and cancellation schemas, and the capability constant.Not included
orcad, so nothing here needs it.orcad.decommissionRPC and the T7 delegated parts. Here the instance-bound managed stop does that job.Why
The SSH execution boundary:
unverifiable.exitedpermits the record change.File-based arbitration instead of an RPC: the completion and cancel commands run as separate processes on the host. An exclusive file is the one decision both processes can see, and it survives
orcadexiting.Inert and POSIX-only: no production code calls
decommissionRemoteOrcaduntil T6-5/T6-6, and every command refuses Windows hosts.Linked Issue
Part of the Node runtime plan (Phase 3), T6 exit-gate track, porting #16741.
Visual Proof
N/A. There's no UI change and no production caller.
Testing
orcad-remote-decommission.test.ts(new). Uses the stateful fake host from T6-2. It covers:orcadserving;It also drops the connection at every mutation, both before and after the host applies it. Recovery always ends with exactly the recorded slot serving, and no journal or fence left behind.
orcad-decommission-transaction.test.ts(new). Journal round-trips; journals with defects are read as unreadable, which keeps the fence; and the recovery plan for each phase.orcad-managed-stop-cancellation.test.ts(new, real filesystem):dispatched;orcadrunning;orcad-remote-shell-commands.integration.test.ts(run on a real shell): a build that advertises stop requests is stopped by the file and never bySIGTERM, and a launch clears a stale request. The existingSIGTERMcases still pass.Smaller updates: the completion line carries the retirement outcome, and
main-preflight-order.test.tschecks that both commands skip preflights.Regression: every
src/main/orcad,src/main/sshandsrc/main/daemontest, plus the import boundary test and the protocol crossing test.ssh-relay-incumbent-process.test.tstimed out once under full load and passes on its own (9/9). It doesn't touch this change.Static checks:
node config/scripts/check-changed-code-quality.mjs origin/mainpasses. A scopedtsc --noEmitover the changed files is clean (the full typecheck was not run).oxlintis clean,pnpm-lock.yamlis unchanged, and there is no new directchild_processimport.I manually tested these changes locally
Automated tests added/updated, or explained why not below
Agent skill upstream boundary
docs/reference/agent-skill-sharing-upstream-boundary.mdand copies or mechanically translates no upstream skill-installer source, tests, fixtures, registry entries, path tables, comments, or documentation.Notes
health.stopRequestsand the completion line'sretirementare new optional fields. Older clients ignore them, and a client facing an olderorcadkeepsSIGTERM. Completion and cancellation output is parsed leniently, so a newer host's extra fields don't break an older client.docs/reference/orcad-operations.mddocuments the cancel command, the decision file, the capability, and decommission.