Repository navigation
fix(ssh): a briefly held fence is retried, not a failed update; terminate keeps unverifiable leases; idle-wake fence race - #25420
Conversation
…a failed update; terminate keeps held leases - The activation fence is retried for a few seconds. A fence still held answers orcad_activation_fence_busy (a waiting deferral, never an update failure) unless a journal or a lock past its stale age shows an interrupted run, which stays recovery-required. - acquireInstallLock reports Busy only when a holder answered; a lock command that only ever failed surfaces its own error. - Terminate detaches instead of disposing when any PTY was unverifiable, so the final teardown never bulk-marks a lease an older relay may hold as terminated. - A wake whose connection dropped while holding the fence releases that fence on this client's next wake (no journal, slot proven exited), so a relaunch-then-connect is not left fenced. - The orcad e2e reconnect helper surfaces a connect's error text instead of a JSON parse error.
There was a problem hiding this comment.
Important
The idle-wake fence auto-release can drop an activation fence it does not own. One inline finding; the rest of the PR reads sound.
Reviewed changes
- Fence-hold classification split — new
orcad-activation-fence-hold.tsresolves a held fence toorcad_activation_fence_busy(retry later) ororcad_activation_recovery_required(journal present, or lock past its stale age); deploy, rollback, and stop all route theirheld()through it, replacing the singleorcad_activation_recovery_requiredcode. - Short fence wait —
withOrcadActivationLocknow waits 5s (ORCAD_ACTIVATION_FENCE_WAIT_MS) before reportingheld(), and exportsreleaseOrcadActivationFence. - Auto-update waits on a held fence —
orcad_activation_fence_busyjoinsWAITING_CODES, so a briefly held fence defers instead of being recorded as a failed update for the app version. - Idle-wake fence recovery — a wake whose slot start lost its connection now releases the journal-less fence it left, tracked in a module-global
interruptedWakesset. - Terminate keeps unverifiable leases — the final teardown detaches instead of disposing when any PTY was unverifiable, so only leases this run proved terminated are marked terminated.
- Install-lock failure classification — a lock command that only ever failed now surfaces its own error rather than
RemoteInstallLockBusyError, and new tests plus an e2e helper that reports the connect error text round it out.
deepseek-v4.1-flash (free via Pullfrog for OSS) | 𝕏
| async function releaseOwnInterruptedWakeFence( | ||
| options: OrcadSlotOptions, | ||
| host: string | ||
| ): Promise<boolean> { | ||
| if (!interruptedWakes.has(host) || (await readOrcadActivationTransaction(options))) { | ||
| return false | ||
| } | ||
| await releaseOrcadActivationFence(options) | ||
| interruptedWakes.delete(host) | ||
| return true | ||
| } |
There was a problem hiding this comment.
This guard treats "key present + no journal" as proof the fence is this client's own, but neither half proves ownership. interruptedWakes is mutated only here and never cleared by any other fence-removal path, so a key survives a fence removed elsewhere (operator Recover, stop-cancel); the next wake on that target then deletes a journal-less fence a different run or client currently holds — another client's in-progress wake, or a deploy in the window between orcad-remote-deploy.ts:106 and the first journal write at orcad-installed-activation.ts:144. Consider proving ownership (a token written alongside the fence, verified before release) or clearing the key whenever the fence is absent, and add a test with a stale key rather than a fresh target id.
Technical details
# Wake fence release is not ownership-scoped
## Affected sites
- `src/main/ssh/orcad-managed-wake.ts:64` — `interruptedWakes.add(host)`, keyed by local `${conn.getTarget().id}\0${remoteHome}`.
- `src/main/ssh/orcad-managed-wake.ts:88` — the only check is `interruptedWakes.has(host) || readOrcadActivationTransaction(options)`.
- `src/main/ssh/orcad-managed-wake.ts:92` — the key is deleted only on a successful own-release, so it leaks process-lifetimes.
- Fence-removal paths that never clear the key: `orcad-activation-lock.ts:106`, `:112`, `:138`, `:162` (reached via `orcad-activation-recovery.ts:53` and `orcad-runtime-decommission.ts:165`).
- `src/main/ssh/orcad-remote-deploy.ts:106` → `src/main/ssh/orcad-installed-activation.ts:144` — a deploy holds a journal-less fence across preflight and admission before writing its journal.
- `src/main/ssh/orcad-managed-wake.test.ts:130` — the "never releases a fence another client may hold" test only passes a fresh target id, so it never exercises a stale key.
## Required outcome
- A wake may release only a fence it can prove it left. Either persist an owner token with the fence and verify it on release, or drop the auto-release and route the interrupted wake through the existing Recover path.
- On the shorter path: clear `interruptedWakes` for the host whenever `orcadActivationFenceExists` is false, and wrap the `readOrcadActivationTransaction(options)` call in `.catch(() => null)` (or treat an unreadable journal as `fenced`) so an unreadable journal does not reject the whole wake.
## Open questions for the human
- Is the auto-release the intended mechanism, or should an interrupted wake leave the fence for operator Recover?
ELI5
This fixes two problems the final review found, plus a race in the idle-server end-to-end test:
What Changed
A briefly held activation fence no longer blocks updates for the app version. This is a regression from round 2.
orcad_activation_recovery_required. So did a single failed lock command, which was counted as "busy". Auto-update treated that code as a failed update and skipped every later connect for this app version.orcad_activation_fence_busy. That code is a waiting deferral, so it is never recorded as a failed update, and the update is retried on a later connect.acquireInstallLockreports Busy only when a holder actually answered (the BUSY marker, or a GC claim). A lock command that only ever failed surfaces its own error.Terminate keeps leases it could not verify.
Idle-exit e2e (
ssh-orcad-idle-exit.spec.ts:50), which also failed on other PRsWhy
Linked Issue
N/A (Phase 3 round-3 review)
Visual Proof
N/A. There is no UI change.
Testing
pnpm tc:nodepasses.pnpm test src/main/ssh src/main/ipcpasses: 793 files, 8875 tests.The changed-code gate passes.
New tests:
I manually tested these changes locally
Automated tests added/updated, or explained why not below
AI Disclosure
Review
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
Checklist
N/Awith reasonpnpm lint,pnpm typecheck,pnpm test, andpnpm buildpass (or CI will cover; local preferred)