Repository navigation
fix(orcad): a snapshot restore past the exec timeout keeps its fence instead of racing a second restore - #25811
Merged
OrcaWin merged 7 commits intoOct 6, 2026
Conversation
OrcaWin
marked this pull request as draft
October 6, 2026 07:35
OrcaWin
marked this pull request as ready for review
October 6, 2026 07:40
OrcaWin
force-pushed
the
OrcaWin/node-rt-p3-restore-timeout
branch
from
October 6, 2026 07:40
15f4694 to
9995ef1
Compare
OrcaWin
marked this pull request as draft
October 6, 2026 07:47
OrcaWin
marked this pull request as ready for review
October 6, 2026 07:50
OrcaWin
marked this pull request as draft
October 6, 2026 07:51
OrcaWin
marked this pull request as ready for review
October 6, 2026 07:55
6 of 9 tasks
OrcaWin
marked this pull request as draft
October 6, 2026 08:09
added 6 commits
October 6, 2026 01:11
…instead of racing a second restore A capture, restore or clear ran under the generic 30s exec timeout. On ssh2 the timeout closes the channel and reads as a confirmed failure, but sshd leaves a pty-less command running, so rollback ran its rescue restore and recover orphaned the fence for a second one, both in the same stage. - State mutations run through execOrcadStateMutation: no abort, a client wait past the host's deadline, and any closed channel or busy/deadline answer is unconfirmed, so the fence stays fresh. - POSIX hosts wrap each one in `timeout -s KILL` (where present) and a pid-checked lock dir under ~/.orca-remote; the Windows host script takes the same lock.
The fence goes stale by its lock dir's mtime after 20 minutes, and a capture, restore or clear can now run up to 15 under it, so a rollback's rescue capture plus restore could outlast the window and let a recovery steal the fence from a live run. While a mutation runs, the host now touches the fence every 60s (POSIX: a background beat that stops with its shell; Windows: an interval in the host script, whose mutations are now async so the timer runs). A dead process stops refreshing, so stale takeover still recovers it.
…'s fence A wake writes .orca-wake-owner into the fence dir and lets its fence age toward takeover; the heartbeat now skips a fence that holds that token, and only ever changes the dir's mtime.
… and names its holder by pid and start time On Windows answer() exits in the stdout write callback, so an op that answered before its first await (MISSING, EMPTY, FAILED) exited before the wrapper's finally and leaked the lock; a reused pid then read as alive and every later capture, restore and clear answered busy. Ops now return their token and the wrapper answers after releasing the lock. The holder is pid plus creation time (the slot's process-tree addon); one that cannot be identified is stale once its lock misses five heartbeats. POSIX gets the same heartbeat-age check for a reused pid.
…s group The lock named only the shell's pid, so a shell killed while its rm or tar ran let the next mutation take the lock and race that child. Each mutation now runs in its own process group (setsid, or perl setpgrp on macOS), with timeout inside it so a deadline KILL reaches the children too. The lock records the group, and is taken over only once no member is alive; a host that can start no group records none, and its lock is never taken over. Windows ops run in-process, with no children to outlive the holder.
…d never hold a groupless lock forever BusyBox ps has no -p, so Alpine hosts recorded no group and their lock read busy forever after a timeout kill, reboot or OOM. The group now comes from /proc/<pid>/stat (read after the comm field's last paren), with ps -o pgid= -p as the fallback. A lock that still names no group is taken over once its pid is dead and its heartbeat has missed three beats.
OrcaWin
marked this pull request as ready for review
October 6, 2026 08:11
OrcaWin
force-pushed
the
OrcaWin/node-rt-p3-restore-timeout
branch
from
October 6, 2026 08:11
0145efa to
85d364c
Compare
OrcaWin
marked this pull request as draft
October 6, 2026 08:11
A Windows holder whose creation time could not be read was taken over after five quiet minutes though its pid was alive, so a suspended clear could resume and delete freshly restored profiles. Both platforms now free the lock only on proof of exit: a dead pid, a different creation time, or (POSIX) a group with no live member. A live holder of unknown identity stays busy until it exits. The owner record is written exclusively, so a run that resumes after a takeover backs off.
OrcaWin
marked this pull request as ready for review
October 6, 2026 08:15
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
Before Orca rolls back or recovers a managed server, it restores the server's saved profile data from a snapshot. That restore can take longer than 30 seconds. When it did, Orca gave up waiting and assumed it had failed. In fact it was still running on the host. Orca then started a second restore into the same scratch folder, and the server came back up on a mix of old and new files while Orca reported "restored and serving". Now a restore that outlives Orca's wait keeps the host locked until someone checks it. Only one restore can run on a host at a time, and the host itself puts a time limit on the work.
What Changed
Before: snapshot capture, restore and clear went through the generic SSH command helper, which has a 30-second timeout. On the usual SSH library, that timeout closes the channel. Once the server acknowledges the close, Orca records "the command definitely ended". But sshd does not kill a command that has no terminal attached, so the restore kept going. As a result:
Both restores extract into
<root>/.orcad-state-restore-stage, so each one'srmandmvacted on the other's half-extracted files.After:
Client side: the three state operations (capture, restore, clear) go through a new helper,
execOrcadStateMutation. It is never cancelled mid-command. It waits longer than the host's own deadline (15 min + 1 min). Any channel close, timeout, "busy" answer or "deadline" answer counts as unconfirmed. Unconfirmed means the activation lock stays fresh: no rescue restore, no launch, no abandoned lock, so the next Recover waits instead of restoring a second time. Only the command's own answer, or a finished non-zero exit, counts as a result.Host side, macOS and Linux:
timeout -s KILL 900where the host hastimeout. GNU timeout kills the whole process group, sotarandrmstop too.~/.orca-remote(orcad-state-mutation.lock) holding the running shell's process id. A second operation answersSTATE_MUTATION_BUSYwhile that process is alive. A lock left behind by a process that has exited is taken over.Host side, Windows: the host script takes the same lock, with no host-side deadline. Two details:
MISSING,EMPTY,FAILED) used to exit before cleanup and leave the lock behind.windows-process-tree.node, so a reused process id doesn't count as the holder.The lock is owned by the operation's whole process group (macOS and Linux). Each operation runs in its own process group:
setsidwhere available, orperl -e setpgrpon macOS, withtimeoutrunning inside that group so its KILL reachestarandrmtoo. The lock records the group id, read from/proc/<pid>/stat(parsed after the last), because the command name can contain spaces and parentheses) or, where there's no/proc, fromps -o pgid= -p. BusyBoxps(Alpine) has no-p, which is why/proccomes first. A lock with a group id is taken over only once no process in that group is still alive, so a killed shell whosermkeeps running still holds it. A lock with no group id (a host that couldn't start a group) is taken over only once its holder's process id is dead, and its heartbeat has also missed three beats. On those hosts only, a leftover child process remains possible. Windows operations run inside the script's own Node process and start no child processes, so nothing can outlive the holder.Only proof of exit frees the lock, on every platform. Proof means:
A live holder whose identity can't be read stays "busy" however long it has been quiet. Elapsed time is never permission. The owner record is written exclusively (
set -Con POSIX,wxon Windows), so a run that resumes after its lock was taken over backs off.The one way out: a host that can't prove a holder's identity (Windows without the process-tree add-on, or POSIX without
setsid,perland/proc) keeps a live holder's lock "busy" until that process exits, or until an operator runs Recover.Reused process ids on macOS and Linux: a reused group id can only make the lock read "busy" for longer, never let it be taken over too early.
The activation lock stays fresh while an operation runs. The lock counts as abandoned once its directory's timestamp is 20 minutes old, and these operations can now take up to 15 minutes each. So while one runs, the host refreshes the lock's timestamp every 60 seconds. On macOS and Linux a background loop stops within one beat of its shell exiting. On Windows a timer runs in the host script; its copy and delete steps are now asynchronous so the timer actually fires. A run that is still working can't have its lock taken over by Recover, Stop or another desktop's connect, while a run whose process died stops refreshing and can still be taken over. The refresh never creates a lock that has already gone.
Capture had the same flaw, and this fixes it too. A slow pre-activation capture used to read as failed, and Orca restarted the old server while the copy was still running. It now keeps the lock like a slow restore does.
Why
flock, because macOS and busybox hosts don't reliably haveflock.Linked Issue
Fixes #
Visual Proof
N/A. This changes host-side behaviour; nothing in the interface changes.
Testing
orcad-state-mutation-timeout.test.ts: drives the real deploy, rollback and recovery code against the fake orcad host, with the capture or restore outliving the client's wait. The host keeps applying it, and the client sees ssh2's confirmed 30s timeout. All three tests fail on the base commit:pendingwith no second restore.orcad-state-mutation-exec.test.ts: realexecCommandagainst a fake SSH channel whose remote command answers late, with fake timers:orcad-state-mutation-fence-heartbeat.test.ts: real shell with a one-second refresh and the real lock-takeover command (3-second abandon threshold). The lock's timestamp is backdated while a long operation runs, the refresh puts it back, and takeover answers BUSY. After the operation's process is killed with SIGKILL, the backdated lock stays old and takeover succeeds. A finished operation stops refreshing, and a missing lock is never created. A Windows host-script test checks that an operation refreshes a held lock and never creates one.Real shell, process group: a mutation's shell is killed while its child keeps running, and the next mutation answers "busy". Once the whole group is killed, it runs. A lock with no group id waits on a live process id or a recent heartbeat, and is taken over once both are gone. The group id is read correctly from a
/procstat line whose command name contains spaces and parentheses. On Linux, with apsthat rejects-p, the group is still recorded through/proc. These pass under both macOSshanddash(Linux's usual/bin/sh), and fail on the previous wrapper.Real shell (
orcad-state-snapshot-shell.test.ts): a restore answers busy and leaves state alone while a live process holds the lock. It takes over a lock whose holder exited, then releases it.Windows host script, run under this machine's Node with a stand-in
windows-process-treeadd-on:MISSING,EMPTYandFAILED(this fails on the previous script);Windows host script, under this machine's Node (
orcad-windows-host-state-ops.test.ts): the same two lock cases for restore, capture and clear.Existing crash-recovery, rollback, deploy, snapshot and shell-integration suites pass.
tscfor the Node project, the changed-code quality gate, and an unchangedpnpm-lock.yamlwere all verified locally.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
timeoutsignals only the shell, not its whole process group. Atarstill running after the deadline would then outlive the lock. The client still reports that run as unconfirmed, so the lock stays held until an operator recovers.Checklist
N/Awith reasonpnpm lint,pnpm typecheck,pnpm test, andpnpm buildpass (or CI will cover; local preferred)