Repository navigation
fix(ssh): reclaim this desktop's own exited lock on Windows hosts too - #26087
Merged
Merged
Conversation
added 5 commits
October 6, 2026 22:50
The relaunch after a quit mid-update now frees the activation fence and the version-dir install lock on a Windows SSH host the same way it does on POSIX, instead of waiting out the 20-minute stale window. The host script ages the lock only when its token belongs to a desktop process proven exited, it has been quiet for three heartbeats, and (for the fence) no state mutation is live, where a mutation holder counts as gone only by pid plus creation time.
…tion Review found the reclaim backdated the lock by path after checking it, so a live successor that replaced the lock in between could be aged and then stolen, and an interrupted or failed restore left it aged for good. The exited-holder check is now read-only. The steal command itself accepts the proven token and, inside its steal claim and identity recheck, also takes a lock whose owner file still names that token and that has been quiet for three heartbeats. Nothing is written to a lock before the steal owns it. POSIX uses the same path.
…can start Review round 2 found the fence's live-mutation guard ran only in the read-only proof, so a mutation admitted after the proof, or one whose first heartbeat landed after the steal sampled the fence's age, kept running under a fence the steal had replaced. For the fence, the steal now takes the state-mutation lock inside its claim (mkdir on POSIX, the exclusive owner.json on Windows) and holds it until the takeover is done; it refuses when any mutation lock exists. Holding it, it rereads the owner and only then re-samples the fence identity. A mutation now rechecks its fence token right after it takes the mutation lock and stops with the fence-lost marker if it changed. The Windows proof also falls back to the stale window when its command line would not fit cmd.exe.
Review round 3 found the POSIX steal held the state-mutation lock as an empty directory, which a mutation reclaims after a minute without any liveness check; a steal stalled that long lost its exclusion and could replace the fence under a running mutation. The steal now writes its pid (and group, under the same rule) with the mutation's own noclobber owner writer, so only proof of its exit frees the lock, and it removes the lock only while the lock still names it. On Windows the owner record is moved into place whole, so it never exists empty, and is removed only while it still names the steal's pid.
… graph The mutation-lock owner writers moved into a leaf module, so the relay's install-lock commands no longer import orcad-state-snapshot and, through it, the Windows host script, orcad-instance-lock and the daemon process query. Those modules evaluate imports at load time that existing suites mock partially. No behavior change.
OrcaWin
marked this pull request as ready for review
October 7, 2026 08:27
This was referenced Oct 7, 2026
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
If you quit Orca partway through updating the server on a Windows machine you reach over SSH, Orca leaves a "someone is working here" lock behind. When you reopen Orca, it now checks whether the lock was left by its own earlier run that has definitely exited, and if so clears it right away. Before this change that check only ran on Linux and macOS hosts, so Windows hosts made you wait about 20 minutes.
What Changed
Before: after a quit mid-update, the relaunch cleared its own leftover lock in about 13 seconds on a Linux host. On a Windows host it waited for the 20-minute stale window, both for the activation fence and for the version folder's install lock.
After: Windows hosts get the same early reclaim, under the same rules.
Mechanism. The desktop already records
{token, pid, hostname, bootedAt}for each lock it takes. That pid belongs to the desktop process, and the exit check (process.kill(pid, 0)returningESRCH, same machine, same boot) runs on the desktop. So nothing about it depends on the remote OS. What did depend on the remote OS was the host-side half: a POSIX shell command checks that the lock still carries the token, that it has been quiet for 3 minutes, and that no state mutation is live (kill -0on the mutation's process group). Windows had no equivalent, so the Windows path was skipped.This PR splits the reclaim into a read-only proof and a conditional steal.
1. Proof (read-only).
fence-exited-owner, runs on the pinnednode.exe. It reads the lock's owner token and checks that the lock has been quiet for three heartbeats. For the fence, it also checks that no state-mutation lock exists at all.2. Steal (the only writer).
BUSY. Nothing is ever backdated.EXITED_OWNER_OKanswer tells the caller to forget the token it reclaimed.3. Fence only: the steal and state mutations never overlap.
posixStateMutationPidRecord/posixStateMutationGroupRecord), which writes a noclobber pid record.{"pid": N}record into place asowner.json, so the file never exists empty. While that pid is alive, the host script reads the holder as unverifiable and treats the lock as busy.serializedStateMutationCommandand the WindowswithStateMutationLock. If the token changed, the mutation stops with the fence-lost marker before doing any work.BUSY, and one that takes the lock after the steal finds the fence gone. The version install keeps no mutation guard.Callers.
acquireInstallLocktakes this through a newexitedOwneroption, which replaces #25991'sbeforeStaleCheckhook. The version-folder install, the fence refusal's clear path, and Recover's stale-takeover lock all use it.Both POSIX and Windows use this path. On POSIX it replaces the older backdate-then-steal pattern, which had the same race.
Why
node.exeand the staging that already exists, with one call per check and no new PowerShell process. That matters for the Windows EDR posture.Linked Issue
N/A (follow-up to #25941 and #25991)
Visual Proof
N/A. No UI change; the relaunch simply stops waiting.
Testing
Steal command (
ssh-relay-install-lock-exited-owner.test.ts, real/bin/sh; the same cases run under PowerShell 5.1 on Windows CI). It:Successor race (regression for the review's race fixtures): a live successor that replaces the lock right after the proof is never aged or taken, and its token is kept. Covered for the install lock (
orcad-exited-own-install-lock.test.ts) and the fence (orcad-exited-own-fence.test.ts).Late-mutation races (review round 2 fixtures, real
/bin/sh,orcad-exited-own-fence-mutation-race.test.ts):BUSY;BUSYand the mutation runs under the old fence, or meets the steal's lock and runs nothing.Stalled steal: a steal paused just before it moves the fence still holds the mutation lock against a mutation, even with the lock backdated past every ownerless and quiet threshold in place of a 2-minute wait. This test fails against the previous empty-directory version.
Windows mutation recheck: a Windows mutation that takes its lock after its fence was replaced stops before touching state and frees the lock.
Windows proof length: a proof command that would not fit cmd.exe falls back to the stale window without running anything.
Proof never writes: the lock's mtime is unchanged after the proof, on both POSIX and the Windows host script. This covers the interrupted-restore and failed-restore fixtures, because no write or restore exists any more.
Windows host script (
orcad-windows-host-fence-ops.test.ts): quiet and token checks, and any mutation lock (live, ownerless, or with an exited holder) keeps the fence.Windows client (
orcad-exited-own-lock-windows.test.ts): only exited tokens are offered, and an unoffered orKEPTanswer is ignored.Command-line limit: the Windows steal command with an exited owner stays under cmd.exe's limit including the fence's mutation-lock path.
pnpm test src/main/ssh/(318 files, 4034 tests),pnpm tc,oxlintandpnpm run check:code-quality:changedpass.No manual run on a Windows SSH host yet.
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
live/unverifiable/exited. Onlyexitedfrees a lock.Checklist
N/Awith reasonpnpm lint,pnpm typecheck,pnpm test, andpnpm buildpass (or CI will cover; local preferred)