Repository navigation
feat(ssh): update, roll back, recover and stop a managed orcad server (#16741 T6-5 follow-up) - #24463
Conversation
…#16741 T6-5 follow-up) Builds managed-server maintenance on T6-2's deploy, rollback and recovery and T6-4's journaled decommission. Each step reads a terminal census through the server's tunnel; orcad answers it through a new capability-gated orcad.terminalCensus RPC, and an older host or lost answer is unverifiable. Update defers over live or uncounted terminals and status reports the last deferral. A stop unlinks the server (deployment record, tunnel, SSH claim) only after a proven exit. Inert until the T6-6 settings UI. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
|
| writeRuntimeEnvironmentSidecarEntry(userDataPath, environments, next, { | ||
| ...state, | ||
| orcadDeployment: deployment | ||
| }) | ||
| writeEnvironmentStore(userDataPath, { version: 1, environments }) |
There was a problem hiding this comment.
Pairing refresh can lose deployment link
When an update or rollback changes the pairing offer, this writes the new sidecar entry before the environment store. If the process exits or the second write fails between those writes, the store keeps the old pairing revision and ignores the newly bound sidecar. The managed server then loses its deployment link, so maintenance actions can no longer resolve it.
| const updated = result.readiness | ||
| ? refreshPairing(userDataPath, environment, result.readiness, deployment.localPort) | ||
| : environment | ||
| if (result.activeVersion) { | ||
| await ensureOrcadManagedTunnel(userDataPath, environment.id) | ||
| } | ||
| return { | ||
| outcome: 'recovered', | ||
| resolution: result.resolution, | ||
| activeVersion: result.activeVersion, | ||
| environment: redactRuntimeEnvironment(updated) |
There was a problem hiding this comment.
Recovered stop leaves server linked
When recovery confirms that an interrupted decommission has stopped the server, it returns activeVersion: null but does not remove the environment or release its tunnel and SSH target claim. Unlike the stop path, this leaves a server that is no longer serving registered as managed, with its target still claimed until someone explicitly stops it again.
|
Navigate logical layers of code changes, visualize relationships, and explore their blast radius. 🧰 Additional context used📚 Code guidelines (1)📝 WalkthroughWalkthroughThe changes add protocol-aware terminal census collection and expose it through RPC and managed runtime status. They add managed Orcad update, rollback, recovery, stop, and stop-cancellation operations. The changes also add pairing refresh and environment removal behavior, update IPC registration and cleanup, and define shared result and status types. Priority: ➖ Normal Merge Risk: 🟡 Moderate · up to A terminal opened during an update or rollback can be interrupted or orphaned, and an update can miss a terminal opened during artifact preparation. Close these census and admission windows before merging. Security Architecture ReviewSecurity architecture risk: 🟡 Moderate · up to Authentication and conservative handling of unavailable session counts limit exposure. However, session counts can become stale before an update or rollback commits, potentially interrupting running terminals or separating them from their saved state. These maintenance actions are not yet exposed through the renderer bridge, which limits immediate exposure but does not resolve the transition risk. Retained concerns
Security review detailsSecurity Blast Radius
Security Findings and Attack Paths
Trust Boundaries and Controls
Resilience and Maintainability Implications
Hardening Proposals
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing Touches 💡 1📝 Generate docstrings 💡
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 |
There was a problem hiding this comment.
Actionable comments posted: 1
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Advanced
Run ID: 01be5702-8fc1-4ded-a03c-06a1692706af
⛔ Files ignored due to path filters (1)
src/shared/rpc-contract/rpc-params-catalog.generated.tsis excluded by!**/*.generated.*
📒 Files selected for processing (32)
src/main/daemon/daemon-provider-census.test.tssrc/main/daemon/daemon-provider-state.tssrc/main/ipc/orcad-runtime-lifecycle-handlers.tssrc/main/ipc/orcad-runtime-maintenance-handlers.test.tssrc/main/ipc/orcad-runtime-maintenance-handlers.tssrc/main/ipc/runtime-environment-connectivity-handlers.tssrc/main/ipc/runtime-environment-handler-channels.tssrc/main/ipc/runtime-environment-removal-cleanup.tssrc/main/ipc/runtime-environments-pairing.test.tssrc/main/ipc/runtime-environments.tssrc/main/orcad/orcad-terminal-census.test.tssrc/main/orcad/orcad-terminal-census.tssrc/main/runtime/rpc/methods/index.tssrc/main/runtime/rpc/methods/orcad-terminal-census.tssrc/main/ssh/orcad-managed-lifecycle-test-fixture.tssrc/main/ssh/orcad-managed-runtime-context.tssrc/main/ssh/orcad-managed-update-deferrals.tssrc/main/ssh/orcad-runtime-decommission.test.tssrc/main/ssh/orcad-runtime-decommission.tssrc/main/ssh/orcad-runtime-deployment.test.tssrc/main/ssh/orcad-runtime-deployment.tssrc/main/ssh/orcad-runtime-lifecycle.tssrc/main/ssh/orcad-runtime-maintenance.test.tssrc/main/ssh/orcad-runtime-maintenance.tssrc/main/ssh/orcad-runtime-status.tssrc/main/ssh/orcad-terminal-census-client.test.tssrc/main/ssh/orcad-terminal-census-client.tssrc/shared/orcad-managed-runtime.tssrc/shared/orcad-terminal-census.tssrc/shared/protocol-version.tssrc/shared/runtime-environment-managed-orcad-store.test.tssrc/shared/runtime-environment-managed-orcad-store.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.
| export function updateManagedOrcadEnvironment( | ||
| userDataPath: string, | ||
| args: LifecycleArgs & { force?: boolean } | ||
| ): Promise<OrcadManagedDeployResult> { | ||
| return withManagedOrcadLifecycle(userDataPath, args.selector, async ({ environment, deployment }) => { | ||
| const context = await resolveLinkedOrcadContext(environment, deployment, args.signal) | ||
| const census = await collectManagedTerminalCensus( | ||
| userDataPath, | ||
| environment, | ||
| context.activationRecord | ||
| ) | ||
| const localOrcadDir = await materializeOrcadArtifact(context.serverTarget, { | ||
| signal: args.signal | ||
| }) | ||
| const result = await deployOrcad({ | ||
| ...managedOrcadSlot(context, deployment.remotePort, args.signal), | ||
| localOrcadDir, | ||
| target: context.serverTarget, | ||
| census, | ||
| force: args.force | ||
| }) | ||
| if (result.outcome === 'installed-not-activated') { | ||
| const deferral = { | ||
| outcome: 'deferred' as const, | ||
| candidateVersion: result.fullVersion, | ||
| code: result.code, | ||
| reason: result.reason, | ||
| forceable: isForceableOrcadDeferral(result.code) | ||
| } | ||
| recordManagedOrcadUpdateDeferral(environment.id, deferral) | ||
| return deferral | ||
| } | ||
| clearManagedOrcadUpdateDeferral(environment.id) | ||
| const readiness = await probeManagedOrcadReadiness( | ||
| context, | ||
| localOrcadDir, | ||
| result.fullVersion, | ||
| args.signal | ||
| ) | ||
| const updated = refreshPairing(userDataPath, environment, readiness, deployment.localPort) | ||
| return { | ||
| outcome: result.outcome === 'already-active' ? 'already-current' : 'updated', | ||
| environment: redactRuntimeEnvironment(updated), | ||
| activeVersion: result.fullVersion | ||
| } | ||
| }) | ||
| } |
There was a problem hiding this comment.
🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win
🔎 Supported by static analysis
🏁 Script executed:
sed -n '71,117p' src/main/ssh/orcad-runtime-maintenance.ts
rg -n 'liveSessions|sessionsStartedSinceActivation|terminalCensus|force' src/main/orcadRepository: stablyai/orca
Length of output: 7777
🏁 Script executed:
set -eu
printf '%s\n' '--- revisions ---'
for rev in 8b76683b400911b6348623d60e29f8ff5e21cbe7 afab3c90dfb88368dc5d2b41c6a083af1583929f; do
if git cat-file -e "$rev^{commit}" 2>/dev/null; then
git rev-parse "$rev^{commit}"
else
printf 'UNAVAILABLE %s\n' "$rev"
fi
done
printf '%s\n' '--- diff stat ---'
git diff --stat 8b76683b400911b6348623d60e29f8ff5e21cbe7 afab3c90dfb88368dc5d2b41c6a083af1583929f
printf '%s\n' '--- changed paths ---'
git diff --name-only 8b76683b400911b6348623d60e29f8ff5e21cbe7 afab3c90dfb88368dc5d2b41c6a083af1583929f | sed -n '1,120p'
printf '%s\n' '--- deployment symbols ---'
rg -n --glob '*.{ts,tsx}' 'deployOrcad|materializeOrcadArtifact|collectManagedTerminalCensus|withManagedOrcadLifecycle|updateManagedOrcadEnvironment' src
printf '%s\n' '--- candidate outlines ---'
ast-grep outline src/main/ssh/orcad-runtime-maintenance.ts
ast-grep outline src/main/orcad/orcad-terminal-census.ts
ast-grep outline src/main/orcad/orcad-managed-stop-decision.tsRepository: stablyai/orca
Length of output: 14330
🏁 Script executed:
set -eu
printf '%s\n' '--- revisions ---'
for rev in 8b76683b400911b6348623d60e29f8ff5e21cbe7 afab3c90dfb88368dc5d2b41c6a083af1583929f; do
if git cat-file -e "$rev^{commit}" 2>/dev/null; then git rev-parse "$rev^{commit}"; else printf 'UNAVAILABLE %s\n' "$rev"; fi
done
printf '%s\n' '--- diff stat ---'
git diff --stat 8b76683b400911b6348623d60e29f8ff5e21cbe7 afab3c90dfb88368dc5d2b41c6a083af1583929f
printf '%s\n' '--- changed paths ---'
git diff --name-only 8b76683b400911b6348623d60e29f8ff5e21cbe7 afab3c90dfb88368dc5d2b41c6a083af1583929f | sed -n '1,120p'
printf '%s\n' '--- deployment symbols ---'
rg -n --glob '*.{ts,tsx}' 'deployOrcad|materializeOrcadArtifact|collectManagedTerminalCensus|withManagedOrcadLifecycle|updateManagedOrcadEnvironment' src
printf '%s\n' '--- candidate outlines ---'
ast-grep outline src/main/ssh/orcad-runtime-maintenance.ts
ast-grep outline src/main/orcad/orcad-terminal-census.ts
ast-grep outline src/main/orcad/orcad-managed-stop-decision.tsRepository: stablyai/orca
Length of output: 14330
🏁 Script executed:
set -eu
printf '%s\n' '--- remote deploy ---'
cat -n src/main/ssh/orcad-remote-deploy.ts | sed -n '1,230p'
printf '%s\n' '--- runtime deployment ---'
cat -n src/main/ssh/orcad-runtime-deployment.ts | sed -n '1,155p'
printf '%s\n' '--- census client ---'
cat -n src/main/ssh/orcad-terminal-census-client.ts | sed -n '1,150p'
printf '%s\n' '--- lifecycle and maintenance entrypoints ---'
cat -n src/main/ssh/orcad-runtime-lifecycle.ts
cat -n src/main/ipc/orcad-runtime-maintenance-handlers.ts | sed -n '1,100p'
printf '%s\n' '--- focused base-to-head diff ---'
git diff --unified=35 8b76683b400911b6348623d60e29f8ff5e21cbe7 afab3c90dfb88368dc5d2b41c6a083af1583929f -- \
src/main/ssh/orcad-runtime-maintenance.ts \
src/main/ssh/orcad-remote-deploy.ts \
src/main/ssh/orcad-runtime-deployment.ts \
src/main/ssh/orcad-terminal-census-client.ts \
src/main/ipc/orcad-runtime-maintenance-handlers.ts
printf '%s\n' '--- deployment tests around safety cases ---'
cat -n src/main/ssh/orcad-remote-deploy.test.ts | sed -n '270,350p;420,535p;570,655p'
printf '%s\n' '--- maintenance tests ---'
cat -n src/main/ssh/orcad-runtime-maintenance.test.ts | sed -n '1,155p'Repository: stablyai/orca
Length of output: 42548
🏁 Script executed:
set -eu
printf '%s\n' '--- activation symbols ---'
rg -n --glob '*.ts' 'activateInstalledOrcad|OrcadTerminalCensus|startedSinceActivation|orcad_update_terminals_running|terminal.*census|force' src/main/ssh src/main/orcad src/shared
printf '%s\n' '--- activation implementation ---'
cat -n src/main/ssh/orcad-installed-activation.ts | sed -n '1,280p'
printf '%s\n' '--- update plan and gate candidates ---'
fd -i -t f 'orcad-update-plan|orcad-activation-gate|activation-gate|installed-activation' src/main/ssh
for f in $(fd -i -t f 'orcad-update-plan|orcad-activation-gate|activation-gate' src/main/ssh); do
printf '%s\n' "--- $f ---"
cat -n "$f" | sed -n '1,240p'
done
printf '%s\n' '--- exact maintenance diff ---'
git diff --unified=12 8b76683b400911b6348623d60e29f8ff5e21cbe7 afab3c90dfb88368dc5d2b41c6a083af1583929f -- src/main/ssh/orcad-runtime-maintenance.ts
printf '%s\n' '--- activation-related tests ---'
rg -n -C 8 'startedSinceActivation|orcad_update_terminals_running|force|census' src/main/ssh/*activation*.test.ts src/main/ssh/orcad-remote-deploy.test.ts src/main/ssh/orcad-runtime-maintenance.test.tsRepository: stablyai/orca
Length of output: 42548
🏁 Script executed:
set -eu
printf '%s\n' '--- exact activation binding ---'
rg -n --glob '*.ts' 'function activateInstalledOrcad|const activateInstalledOrcad|export .*activateInstalledOrcad|from .*/orcad-installed-activation' src
printf '%s\n' '--- installed activation outline ---'
ast-grep outline src/main/ssh/orcad-installed-activation.ts
printf '%s\n' '--- installed activation focused reads ---'
rg -n -C 12 'planOrcadUpdate|census|liveSessions|startedSinceActivation|force|stop|snapshot|activate' src/main/ssh/orcad-installed-activation.ts
printf '%s\n' '--- update plan ---'
cat -n src/main/ssh/orcad-update-plan.ts | sed -n '1,155p'
printf '%s\n' '--- daemon census ---'
cat -n src/main/orcad/orcad-terminal-census.ts | sed -n '1,100p'
printf '%s\n' '--- maintenance header and update ---'
cat -n src/main/ssh/orcad-runtime-maintenance.ts | sed -n '1,118p'Repository: stablyai/orca
Length of output: 26917
🏁 Script executed:
set -eu
printf '%s\n' '--- daemon preservation symbols ---'
rg -n -C 12 'shouldPreserveDaemonWithLiveSessions|live sessions|liveSessions|disconnectDaemon|shutdownDaemon|daemon-init|entry-path|version mismatch|preserve' src/main
printf '%s\n' '--- daemon supervision and init candidates ---'
fd -i -t f 'daemon-supervision|daemon-init|daemon-provider|orcad.*daemon' src/main
for f in $(fd -i -t f 'daemon-supervision|daemon-init|daemon-provider|orcad.*daemon' src/main); do
printf '%s\n' "--- $f ---"
rg -n -C 8 'shouldPreserveDaemonWithLiveSessions|disconnectDaemon|shutdownDaemon|live|version|entry' "$f"
done
printf '%s\n' '--- related tests ---'
rg -n -C 12 'preserv|mixed pair|entry.path|live session|daemon.*version|disconnectDaemon|shutdownDaemon' src/main/daemon src/main/ssh src/main/orcadRepository: stablyai/orca
Length of output: 45626
🏁 Script executed:
set -eu
printf '%s\n' '--- protocol crossing ---'
cat -n src/main/ssh/orcad-daemon-protocol-crossing.ts | sed -n '1,180p'
printf '%s\n' '--- bounded exact searches ---'
rg -n 'shouldPreserveDaemonWithLiveSessions|preserveDaemonWithLiveSessions|daemon-init|entry-path|mixed pair|live terminal|live sessions' src/main/ssh src/main/orcad src/main/daemon -g '*.ts' | sed -n '1,240p'
printf '%s\n' '--- daemon launch/adoption calls from Orcad path ---'
rg -n -C 5 'launchOrcad|launchOrcadSlot|disconnectDaemon|shutdownDaemon|daemon.*preserv|preserv.*daemon|listLiveDaemon' src/main/ssh/orcad-*.ts src/main/ssh/*daemon*.ts | sed -n '1,260p'Repository: stablyai/orca
Length of output: 40384
🏁 Script executed:
set -eu
cat -n src/main/daemon/daemon-replacement-preflight.ts | sed -n '88,145p;245,285p'Repository: stablyai/orca
Length of output: 4411
Collect the census after artifact materialization.
A non-forced update can collect zero sessions, then a terminal can start while materializeOrcadArtifact runs. activateInstalledOrcad uses that stale zero without another census and proceeds with the restart. The later daemon gate preserves the old daemon, but the candidate Orcad then runs against it until the terminal exits instead of deferring as required.
Suggested fix
- * Every step reads the terminal census through the server's tunnel first; an unanswered census
+ * Every update reads the terminal census through the server's tunnel immediately before deployment; an unanswered census
* is unverifiable, never zero, so an update over live or uncounted terminals defers (D7).
...
- const census = await collectManagedTerminalCensus(
- userDataPath,
- environment,
- context.activationRecord
- )
const localOrcadDir = await materializeOrcadArtifact(context.serverTarget, {
signal: args.signal
})
+ const census = await collectManagedTerminalCensus(
+ userDataPath,
+ environment,
+ context.activationRecord
+ )📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| export function updateManagedOrcadEnvironment( | |
| userDataPath: string, | |
| args: LifecycleArgs & { force?: boolean } | |
| ): Promise<OrcadManagedDeployResult> { | |
| return withManagedOrcadLifecycle(userDataPath, args.selector, async ({ environment, deployment }) => { | |
| const context = await resolveLinkedOrcadContext(environment, deployment, args.signal) | |
| const census = await collectManagedTerminalCensus( | |
| userDataPath, | |
| environment, | |
| context.activationRecord | |
| ) | |
| const localOrcadDir = await materializeOrcadArtifact(context.serverTarget, { | |
| signal: args.signal | |
| }) | |
| const result = await deployOrcad({ | |
| ...managedOrcadSlot(context, deployment.remotePort, args.signal), | |
| localOrcadDir, | |
| target: context.serverTarget, | |
| census, | |
| force: args.force | |
| }) | |
| if (result.outcome === 'installed-not-activated') { | |
| const deferral = { | |
| outcome: 'deferred' as const, | |
| candidateVersion: result.fullVersion, | |
| code: result.code, | |
| reason: result.reason, | |
| forceable: isForceableOrcadDeferral(result.code) | |
| } | |
| recordManagedOrcadUpdateDeferral(environment.id, deferral) | |
| return deferral | |
| } | |
| clearManagedOrcadUpdateDeferral(environment.id) | |
| const readiness = await probeManagedOrcadReadiness( | |
| context, | |
| localOrcadDir, | |
| result.fullVersion, | |
| args.signal | |
| ) | |
| const updated = refreshPairing(userDataPath, environment, readiness, deployment.localPort) | |
| return { | |
| outcome: result.outcome === 'already-active' ? 'already-current' : 'updated', | |
| environment: redactRuntimeEnvironment(updated), | |
| activeVersion: result.fullVersion | |
| } | |
| }) | |
| } | |
| export function updateManagedOrcadEnvironment( | |
| userDataPath: string, | |
| args: LifecycleArgs & { force?: boolean } | |
| ): Promise<OrcadManagedDeployResult> { | |
| return withManagedOrcadLifecycle(userDataPath, args.selector, async ({ environment, deployment }) => { | |
| const context = await resolveLinkedOrcadContext(environment, deployment, args.signal) | |
| const localOrcadDir = await materializeOrcadArtifact(context.serverTarget, { | |
| signal: args.signal | |
| }) | |
| const census = await collectManagedTerminalCensus( | |
| userDataPath, | |
| environment, | |
| context.activationRecord | |
| ) | |
| const result = await deployOrcad({ | |
| ...managedOrcadSlot(context, deployment.remotePort, args.signal), | |
| localOrcadDir, | |
| target: context.serverTarget, | |
| census, | |
| force: args.force | |
| }) | |
| if (result.outcome === 'installed-not-activated') { | |
| const deferral = { | |
| outcome: 'deferred' as const, | |
| candidateVersion: result.fullVersion, | |
| code: result.code, | |
| reason: result.reason, | |
| forceable: isForceableOrcadDeferral(result.code) | |
| } | |
| recordManagedOrcadUpdateDeferral(environment.id, deferral) | |
| return deferral | |
| } | |
| clearManagedOrcadUpdateDeferral(environment.id) | |
| const readiness = await probeManagedOrcadReadiness( | |
| context, | |
| localOrcadDir, | |
| result.fullVersion, | |
| args.signal | |
| ) | |
| const updated = refreshPairing(userDataPath, environment, readiness, deployment.localPort) | |
| return { | |
| outcome: result.outcome === 'already-active' ? 'already-current' : 'updated', | |
| environment: redactRuntimeEnvironment(updated), | |
| activeVersion: result.fullVersion | |
| } | |
| }) | |
| } |
There was a problem hiding this comment.
ℹ️ No critical issues — one wire field that cannot currently carry a value, plus one design point worth confirming.
Reviewed changes
Initial review of all 33 files: the managed-orcad maintenance lifecycle (update, rollback, recover, stop, cancel-stop) built on T6-2/T6-4. Main process only; the new IPC channels have no renderer caller until T6-6.
- Terminal census. New
orcad.terminalCensusRPC behindorcad.terminal-census.v1;listLiveDaemonSessionsWithProtocollabels each live session with its daemon generation's protocol; the client reads every failure (older host, method-not-found, malformed, lost contact, tunnel failure) as an all-null unverifiable census, never zero. - Update / rollback / recover (
orcad-runtime-maintenance.ts) run main's journaleddeployOrcad/rollbackOrcad/recoverInterruptedOrcadActivation, deferring an update over live or uncounted terminals, refusing rollback unless the census is zero, and re-pairing through the same tunnel after a successful change. - Stop / cancel-stop (
orcad-runtime-decommission.ts) run T6-4's decommission, finish an interrupted stop from its journal, refuse the Active Server before contacting the host, and unlink only on proven orcad exit; cancel withdraws a not-yet-dispatched stop under the stale-recovery lock. - Store & IPC:
removeManagedOrcadEnvironmentandrefreshManagedOrcadPairing; newupdateOrcad/rollbackOrcad/recoverOrcad/stopOrcad/cancelOrcadStopchannels; sharedruntime-environment-removal-cleanup.tsextracted so server removal and stop share the client-side cleanup.
ℹ️ Stop unlinks on orcad exit, not daemon idleness
stopManagedOrcadEnvironment proves orcad exited before unlinking; it does not require the host's terminal daemon to be idle. decommissionRemoteOrcad already refuses a non-zero census at dispatch, but the settle can still come back retirement: 'live' (a terminal started inside the window, or a daemon it could not settle), and stopRemote then returns a Stopped result that unlinks while reporting verdict: 'exited' with retirement: 'live'. Two branches also skip the census entirely: the !record.active shortcut (src/main/ssh/orcad-runtime-decommission.ts:107-110) and the interrupted-decommission recovery branch (:81-86). withDeactivatedVersion (src/main/ssh/orcad-activation-record.ts:157-168) documents that a null active version keeps previous precisely because "the slot whose daemon may still own terminals", and collectRemoteOrcadTerminalCensus reports zero for that record shape. Both branches read like they resume an already-authorized stop, so this may well be intended — it would just be worth stating that unlink is gated on orcad exit alone (not daemon idleness), and that terminals surviving the unlink in that window is accepted.
Technical details
# Unlink proof is orcad exit, not daemon idleness
## Affected sites
- `src/main/ssh/orcad-runtime-decommission.ts:106-110` — `!record.active` returns `{version: null, retirement: null}` with no census and no liveness probe; the caller unlinks.
- `src/main/ssh/orcad-runtime-decommission.ts:81-86` — interrupted decommission recovered to `activeVersion === null` (orcad slot proven `DEAD` only) unlinks without consulting `census.liveSessions`.
- `src/main/ssh/orcad-runtime-decommission.ts:111-116` — normal path passes the census, but `decommissionRemoteOrcad` can return `retirement: 'live'` and the stop still unlinks.
- `src/main/ssh/orcad-activation-record.ts:157-168` / `src/main/ssh/orcad-decommission-transaction.ts:52` — the deactivated record shape (`active: null`, `previous` pinned) that the shortcut treats as "nothing running".
- `src/main/ssh/orcad-terminal-census-client.ts:33-35,71-73` — census is hard-coded to `liveSessions: 0` whenever `!record.active`.
## Required outcome
- Confirm (in a comment or the PR body) whether unlinking on proven orcad exit alone — accepting that a live daemon may keep terminals the client can no longer reach — is the intended contract, since the result type already reports `retirement: 'live'`.
- If the `!record.active` / recovery-unlink paths are meant only to resume an already-authorized stop, say so; otherwise they need a daemon census before unlinking.
## Open questions for the human
- Is a deactivated-but-linked environment (crash between host commit and client unlink) the only way these two branches are reached in production?deepseek-v4.1-flash (free via Pullfrog for OSS) | 𝕏
| const timestampsKnown = sessions.every( | ||
| (session) => Number.isFinite(session.createdAt) && session.createdAt > 0 | ||
| ) | ||
| const protocols = new Set(sessions.map((session) => session.protocolVersion)) | ||
| const [protocol] = protocols | ||
| return { | ||
| liveSessions: sessions.length, | ||
| startedSinceActivation: timestampsKnown | ||
| ? sessions.filter((session) => session.createdAt >= activatedAt).length | ||
| : null, |
There was a problem hiding this comment.
startedSinceActivation is unreachable as a real count: the daemon's only live-session listing hardcodes createdAt: 0 (src/main/daemon/terminal-host-session-listing.ts:27), so timestampsKnown is false for any non-empty daemon and this field is always null. The activatedAt param is therefore inert over the new wire.
Nothing misbehaves today — rollbackManagedOrcadEnvironment refuses on liveSessions !== 0 before the census reaches rollbackOrcad, so assessOrcadRollback's startedSinceActivation branches never run through the managed flow. But the PR's own test calls createdAt: 0 an edge case when it is every real session, and if the rollback gate is ever relaxed to the semantics assessOrcadRollback was written for (allow pre-activation sessions, refuse only post-activation ones), every non-empty daemon would read orcad_rollback_census_unavailable and the orphan-detection branch could never fire. Either populate createdAt from the live session, or drop the field and the param.
…s not pull in the xterm window polyfill Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
There was a problem hiding this comment.
✅ No new issues found in this delta.
Reviewed changes
Incremental re-review of afab3c90df..475efa1c6b: one commit that fixes a module-load-order regression introduced by the initial commit.
- Lazy census import.
src/main/runtime/rpc/methods/orcad-terminal-census.tsnow loadscollectOrcadTerminalCensusvia a dynamicawait import(...)inside the handler instead of a static top-level import. The census module reaches the daemon modules, whosexterm-env-polyfilldefines a globalwindow(src/main/daemon/headless-emulator.ts:1), so the static import pulled that polyfill into every process that imports the RPC dispatcher. The chain was verified end to end, and the handler already returns a promise at that seam, so the change is behavior-neutral for callers.
The prior inline thread on startedSinceActivation (src/main/orcad/orcad-terminal-census.ts:25-34) is unaffected by this commit and remains open; it is informational and not re-raised here.
deepseek-v4.1-flash (free via Pullfrog for OSS) | 𝕏
There was a problem hiding this comment.
Caution
Some comments are outside the diff and can’t be posted inline due to GitHub limitations.
🟠 Major · Fence terminal admission before replacing the daemon. · orcad-runtime-maintenance.ts:77-91
src/main/ssh/orcad-runtime-maintenance.ts:77-91
🩺 Stability & Availability | 🟠 Major | 🏗️ Heavy liftFence terminal admission before replacing the daemon.
The update path can pass a zero census to
deployOrcad. The later replacement preflight performs another point-in-time count, but it does not userequestIdleDaemonRetirement()to fence new terminals. A terminal can be admitted after that count returns zero and before cleanup replaces the daemon. Because daemon replacement kills its child PTYs, the newly admitted terminal can be interrupted and lost.Route the zero-session replacement decision through the existing atomic idle-retirement mechanism, and hold its admission fence until replacement completes.
🟠 Major · Rollback can orphan a terminal admitted after the census. · orcad-runtime-maintenance.ts:134-159
src/main/ssh/orcad-runtime-maintenance.ts:134-159
🩺 Stability & Availability | 🟠 Major | 🏗️ Heavy liftRollback can orphan a terminal admitted after the census.
collectManagedTerminalCensusis a point-in-time check. After it returns zero, rollback does not fence daemon admission or collect another census beforestopOrcadSlotand snapshot restoration. A terminal admitted in that interval can remain owned by the incumbent while rollback restores a snapshot that does not contain it.Rollback must atomically prevent new terminal admission before the final idle check and keep that fence through incumbent shutdown and snapshot restoration.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Advanced
Run ID: bb371e6c-7472-417e-a805-f49e6132fbeb
📒 Files selected for processing (1)
src/main/runtime/rpc/methods/orcad-terminal-census.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.
* 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
#24453 lets Orca create a managed
orcadserver on an empty SSH host. This PR adds the actions that come after creation:Every action first asks the server how many terminals it is running. If any are running, or the server can't say, the action holds off rather than risk them.
Nothing in the UI calls this yet. The settings screens arrive in T6-6, so users see no change.
What Changed
Before: a managed server could be created and its status read, but nothing could update, roll back, recover or stop it.
After (main process only, through new IPC channels with no renderer caller yet):
orcad.terminalCensus, is advertised as theorcad.terminal-census.v1capability and returns the daemon's live session count, how many started since activation, and the owning daemon protocol.listLiveDaemonSessionsWithProtocollabels each session with its daemon generation's protocol. Sessions spread over several protocols leave the protocol unknown.orcad-terminal-census-client.ts): the client calls it through the server's tunnel, with a status preflight, and only when the capability is advertised. All of these give an unverifiable census, never zero:orcad-runtime-maintenance.ts):deployOrcadwith that census, so the existing update plan defers over live or uncounted terminals (D7).getOrcadStatusnow reportsdeferredUpdateand the liveterminalscensus.rollbackOrcadagainst the previous slot's installed bytes, using that slot's build hash as read from the host.recoverInterruptedOrcadActivationand re-opens the tunnel once a serving slot is restored.orcad-runtime-decommission.ts):decommissionRemoteOrcadwith the census.exited:orcadDeploymentrecord;liveorunverifiableverdict, everything stays linked.cancelRemoteOrcadManagedStopand keeps the server on its recorded slot. If orcad already acted on the stop, or already exited, it says so and changes nothing.runtime-environment-managed-orcad-store.ts):removeManagedOrcadEnvironment.refreshManagedOrcadPairing, which rewrites only when the tunneled offer changed and keeps the deployment link bound to the new pairing revision.updateOrcad,rollbackOrcad,recoverOrcad,stopOrcad,cancelOrcadStop.runtime-environment-removal-cleanup.ts, soruntimeEnvironments:removeand stop share it.Why
Wire compatibility
There is one new RPC method,
orcad.terminalCensus, behind theorcad.terminal-census.v1capability.rpc-params-catalog.generated.tsis regenerated, and--checkpasses.Linked Issue
Part of #16741.
Visual Proof
N/A: no UI change. The new IPC channels have no renderer caller until T6-6.
Testing
New tests, 9 files and 84 tests:
Broad run over all
src/main/ipc/ssh*,src/main/ssh/*, runtime-environment, RPC, daemon and orcad tests: 847 files, 9066 passed, 74 skipped, 1 failed. The one failure wasssh-relay-incumbent-process.test.ts("real generated incumbent probe"); it passes 9/9 on its own and this PR doesn't touch it.A scoped
tscover the changed files and their main/shared importers (335 files) is clean.oxlint, the changed-code quality gate, the max-lines ratchet and the runtime-electron ratchet are clean.POSIX hosts only, as with the rest of the orcad deploy core.
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
live/unverifiable/exited, and onlyexitedunlinks.Checklist
N/Awith reasonpnpm lint,pnpm typecheck,pnpm test, andpnpm buildpass (or CI will cover; local preferred)