Repository navigation
fix(orcad): every activation fence holder carries a generation token its steps and release must match - #25834
Merged
OrcaWin merged 10 commits intoOct 6, 2026
Conversation
OrcaWin
commented
Oct 6, 2026
OrcaWin
left a comment
Collaborator
Author
There was a problem hiding this comment.
Review of the #25811 wiring in bfa24a19dc. It looks right to me: no blockers, and two nits.
I checked:
- The order is guard, then the mutation process group and lock, then the work. The guard runs outermost, before
orca_state_group, so a superseded holder never takes the mutation lock or reachestarorrm. - A fence-lost answer becomes
OrcadFenceLostError, andexecOrcadStateMutationOrrethrows it instead of falling back to FAILED. The lock wrapper's release and orphan paths are token-guarded (posixReleaseFenceCommandanswers SUPERSEDED, and the Windowsfence-releaseop checks the token), so that throw can't delete a successor's journal or fence. - The heartbeat refreshes only while the owned-test passes, and never with no fence. On Windows,
FENCE_TOKENcomes from--fence. - The wake-owner constant is gone. One owner file is used everywhere.
I ran the heartbeat, state-snapshot, Windows state-ops and crash-recovery suites at this head: 84 tests pass. The heartbeat and real-shell snapshot tests also pass with dash as both the outer and inner sh.
Nits, both optional:
- The heartbeat tests ownership against
owned.lockDirbut touches$fence, which is rebuilt frombaseDir. On Windows,refreshFencelikewise readsFENCE, built from__dirname, rather than the--fencelock dir. They name the same directory today. Touching the directory you just checked (owned.lockDir, or the--fenceargument) would rule out a path-spelling mismatch. owneddefaults tocurrentOrcadFence(), so a future caller outside a fence scope silently gets no guard and no heartbeat. Every current caller (activation capture, rollback rescue capture and restore, recovery restore) is fenced. A one-line comment or a dev-only warning whenownedis null in a non-test build would make a regression visible.
OrcaWin
force-pushed
the
OrcaWin/node-rt-p3-fence-generation
branch
from
October 6, 2026 08:17
2514e09 to
3390920
Compare
OrcaWin
marked this pull request as draft
October 6, 2026 08:29
OrcaWin
marked this pull request as ready for review
October 6, 2026 08:34
added 10 commits
October 6, 2026 02:32
… Recover, and report a restarting update from status BUG-21: a wake cut short leaves a stale fence with no journal. Every update then answered 'Recover it first' while Recover answered 'none'. The fence-hold check now takes such a fence over and drops it, and the update retries once; Recover is asked for only over a journal. The CLI also treats a connection closed by the server's own restart during update or rollback as expected and reports what status shows once the runtime answers.
…lock exists The idle-exit e2e still read 'fenced' on reconnect: the launch-time wake's lock landed on the host but its connection dropped before the client saw OK, so the wake body never ran and never wrote its owner token, leaving a fence nothing could prove. The token is now claimed before the lock and written by the same command that creates it, and a wake registers itself before any remote step so a reconnected wake waits for it instead of racing it.
…its steps and release must still match Astra pass 8: a holder suspended past the stale window resumed, kept acting, and its unconditional release deleted the successor's fence and recovery journal mid-update. Every holder (activation, rollback, stop, recover, wake) now writes a token into the lock it creates or takes over. Each remote step it issues checks that token on the host, in the same command on POSIX and inside the host script for Windows host ops; release is conditional on the token and moves the lock aside instead of removing the root. A superseded holder aborts with OrcadFenceLostError and its release is a no-op.
…and refresh only a fence they still own On POSIX the fence guard runs outermost in serializedStateMutationCommand, before the mutation lock and the work, and the heartbeat touches the fence only while the token is still this run's. The Windows host script records the --fence token and refreshFence compares it. A fence-lost answer from a state mutation is a refusal, never a FAILED fallback. One owner-file constant replaces the wake-owner copies.
…tory it checked ownership of (review)
… its own generation's Astra pass 9: a release that passed its token check and stalled before deleting could, once a takeover and a successor came and went, delete the successor's journal and lock. The journal is now stamped with the writing run's fence token (a recovery takeover re-stamps the journal it adopts), and the release renames the journal and the lock aside, deletes each only if it carries this run's token, and otherwise moves it straight back.
…the Windows host script
…ver the error message The real exec error quotes the command, and every fenced command carries the guard's marker text, so any failed or timed-out fenced step read as a lost fence and dropped its unconfirmed flag. execCommand now attaches exitCode and stdout to its exit error; execOrcadRemote rethrows unconfirmed terminations before any reclassification.
A disconnect fails a wake's next step without the unconfirmed flag, and the fence release then fails over the dead connection. Forgetting the token on that error left a fence the reconnected wake could not prove its own, so it reported the host as held by an update.
OrcaWin
force-pushed
the
OrcaWin/node-rt-p3-fence-generation
branch
from
October 6, 2026 09:41
6f54cac to
c1896cb
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
ELI5
Only one run at a time may change a managed Orca server's host, and that run holds a lock on the host (the "fence"). If a desktop holding the fence goes to sleep for more than 20 minutes, Orca treats the fence as abandoned, and another desktop can take it over. When the first desktop woke up, it still believed it held the fence: it could keep starting its server version, and when it finished it deleted the other desktop's fence and its recovery record mid-update. Now every holder stamps the fence with its own random token, and the host refuses any step or release from a holder whose token is no longer there.
This PR also includes #25802 (BUG-21): Orca clears a stale fence that has no interrupted run behind it by itself, instead of telling the user to run Recover. It is only safe because of the token check.
What Changed
.install-lock/.orca-fence-owner. The same command that creates the lock writes it, building on fix(ssh): a wake's fence carries its owner token from the moment the lock exists #25825's token-at-creation, and so does the stale-takeover command. The file name is one constant,ORCAD_FENCE_OWNER_FILENAME, inorcad-activation-fence-scope.ts.runWithOrcadFence). Inside that scope:execOrcadRemoteprefixes each command with[ "$(cat …/.orca-fence-owner)" = '<token>' ] || { echo __ORCAD_FENCE_LOST__; exit 75; }, so the check and the step are one remote command.orcadWindowsHostOpCommandpasses--fence <lockDir> <token>, and the host script checks the token before it dispatches the operation.fence-checkhost op immediately before it. That leaves one exec of check-then-step gap on Windows. It is accepted, because a holder would have to be suspended past the 20-minute stale window exactly inside that gap.OrcadFenceLostError. The run aborts,execOrcadRemoteOrnever turns it into a fallback, and the readiness wait doesn't retry it.writeOrcadActivationTransactionadds the writing run'sfenceToken; older readers ignore the extra field. A recovery takeover re-stamps the journal it adopts, so its own release removes that journal.fence-releaseop does the same.SUPERSEDED. On Windows this is the newfence-releasehost op.Wired into #25811's state mutations (snapshot capture, restore and clear):
serializedStateMutationCommand, so a superseded run never takes the mutation lock or touches state.--fencebefore the op runs.beat_fencechecks the token on every beat. On WindowsrefreshFencecompares the--fencetoken, and without one it refreshes nothing.OrcadFenceLostError), never aFAILEDfallback.ORCAD_FENCE_OWNER_FILENAME.Stacked on #25825 and #25811. This branch contains #25825's commit and a merge of #25811's head. Both merge first; this PR then rebases, and their commits drop out.
Why
Linked Issue
Astra review pass 8, P1 #1, plus BUG-21. Internal. Supersedes #25802, which closes when this merges. Built on #25825.
Visual Proof
N/A. No UI changes.
Testing
I manually tested these changes locally
Automated tests added/updated, or explained why not below
orcad-activation-fence-generation.test.tsis Astra's suspend-and-resume scenario, run in a real shell:OrcadFenceLostError, and the command it tried to run never happens;This test fails without the fix.
In the same file, the Astra pass 9 cases:
clearOrcadStateSnapshotMembersCommand) is refused withOrcadFenceLostError, and profile state is untouched.orcad-windows-host-fence-ops.test.tsruns the real Windows host script under Node. It runs an operation only for the current token holder, and its release removes only its own generation.ssh-remote-commands.test.ts: the stale takeover writes the new holder's token.orcad-state-mutation-fence-heartbeat.test.ts, real shell:orcad-windows-host-state-ops.test.ts: the Windows heartbeat refreshes only an owned fence, and a superseded run is refused with exit 75.The fake hosts in the activation, crash-recovery, wake, decommission and Windows lifecycle tests now follow the guard and the conditional release.
Ran locally:
pnpm tc:node,typecheck:cliand the changed-code gate pass.src/main/ssh, the remaining failures are 27 tests across six files. All of them fail the same way without this change, in my local environment. Two of the files fail with "AppEnvironment not initialized".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)