Skip to content

fix(orcad): a fence this desktop's exited process left is cleared without the 20-minute wait - #25941

Merged
OrcaWin merged 2 commits into
OrcaWin/node-rt-phase3from
OrcaWin/node-rt-p3-own-dead-fence
Oct 6, 2026
Merged

OrcaWin merged 2 commits into
OrcaWin/node-rt-phase3from
OrcaWin/node-rt-p3-own-dead-fence

Conversation

@OrcaWin

@OrcaWin OrcaWin commented Oct 6, 2026 •

Copy link
Copy Markdown
Collaborator
Files Added Deleted Net
Test 1 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​233 0 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​233
Prod 5 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​203 $\color{#cf222e}{\Huge{\mathbf{−}}}$​2 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​201

ELI5

If you quit Orca while it was updating the server on an SSH host, the next launch couldn't update or stop that server for up to 20 minutes. It was waiting for its own leftover "busy" marker to expire. Now Orca recognises a marker it left itself and clears it straight away, but only when nothing from the old session can still be running on the host.

What Changed

  • Before: an update, rollback or stop holds the host's activation fence while it works. If the desktop quits mid-run (BUG-23), the fence stays on the host. Every later attempt from the same desktop was told "another run is changing this host" until the fence aged past the 20-minute stale window.
  • After: the desktop records the fence token each of its processes holds, in orcad-held-fence-tokens.json beside the profile.
    • The token is written before the lock command and removed once the release or orphaning is confirmed.
    • On a later attempt, if the host's fence carries a token recorded by a process that has positively exited (the pid answers ESRCH), a single host command checks two more things:
      • the fence has been quiet (unrefreshed) for at least 3 minutes, which is three state-mutation heartbeats;
      • no state mutation is live: its process group, shell and heartbeat are all gone.
    • Only then does it backdate the fence. The existing stale rules then apply at once: a bare fence is cleared and the attempt retried, and a fence over a journal goes to Recover.
  • The backdate re-checks the owner afterwards. A successor that took the fence in between gets its freshness back.
  • The token record is best effort. A write that fails is logged and never breaks a fence operation; losing an entry only costs the early reclaim.
  • Each entry also stores the machine's hostname and boot time, and both must match before an exited pid is trusted. A profile shared across machines (NFS, sync) or a reboot falls back to the normal stale rule.
  • Entries older than 24 hours are pruned.

Why

  • Process exit alone is not proof the work stopped. Orca runs remote steps without a terminal, so sshd keeps them running after the connection drops. A snapshot restore can run for up to 15 minutes, and a shared ControlMaster can outlive Orca entirely.
  • The quiet window covers every other fenced step: slot stop is at most 20 s, a readiness wait at most 20 s per call, and managed-stop completion about 20 s. A live mutation refreshes the fence every 60 s while it still owns it.
  • The mutation-lock check catches the case where a mutation's shell died but its tar/rm children survived.
  • Backdating reuses the existing stale-takeover and Recover paths, instead of adding a second takeover protocol.
  • Out of scope:
    • Another desktop's fence never carries our token, so it is never touched.
    • Accepted limit: Windows hosts keep the 20-minute wait after a quit mid-update. This early reclaim is POSIX only for now. The old server keeps serving meanwhile, so the host is not stuck.
    • Accepted limit: non-mutation steps. The quiet check only sees a state mutation's heartbeat. Any other fenced step that ran more than 3 minutes after the session dropped would go unseen. Today every such step is bounded well below that: slot stop, readiness wait and managed-stop completion are each about 20 s, and the bundle upload happens before the fence is taken.
    • Remote cleanup of old slots runs under its own cleanup claim with plain exec, not under the activation fence, so it is unaffected.

Linked Issue

Fixes # (maintainer: BUG-23, fence half; the quit-time crash is #25922)

Visual Proof

N/A: no UI change. This changes how an SSH host's activation fence is classified on the next attempt.

Testing

  • I manually tested these changes locally

  • Automated tests added/updated, or explained why not below

  • Added orcad-exited-own-fence.test.ts, 13 tests that run the real host commands in a local shell:

    • an exited own process, a quiet fence and no mutation: cleared at once, and the token forgotten;
    • kept in every other case: a live state mutation, a fence not yet quiet, a foreign token, a live process of this desktop, an entry from another machine, or a Windows host;
    • a fence over a journal goes to Recover, and the journal is kept;
    • a successor that takes the fence during the backdate gets its freshness back (this fails without the re-check);
    • the token record across a release, a superseded release, a busy lock (forgotten) and a lost connection (kept);
    • an unwritable record never fails a fence operation.
  • src/main/ssh: 4022 passed.

  • tc:node and typecheck:cli: clean.

  • Changed-code quality gate: passed.

  • Tested on macOS.

Review

Agent skill upstream boundary

  • Not applicable, or this change follows docs/reference/agent-skill-sharing-upstream-boundary.md and copies or mechanically translates no upstream skill-installer source, tests, fixtures, registry entries, path tables, comments, or documentation.

Notes

  • SSH: there is no wire or protocol change. The host-side check is a POSIX shell command run only by this desktop, only for its own recorded token.
  • Execution boundary: a live or unverifiable mutation always keeps the fence in place. Nothing infers exit from silence.

Checklist

  • This PR is small and focused
  • I explained what changed and why (ELI5, the user-facing before/after, the mechanism, and why over the alternatives)
  • Before/after screenshots or videos attached for UI changes, or N/A with reason
  • Self-reviewed for correctness, security, and performance
  • Cross-platform, SSH/remote, and path/shortcut impact considered (or N/A)
  • pnpm lint, pnpm typecheck, pnpm test, and pnpm build pass (or CI will cover; local preferred)

m4air added 2 commits October 6, 2026 13:56
…hout the 20-minute wait

The client records the fence tokens its processes hold beside the profile. On
a later launch, a POSIX fence carrying a token from a process that has exited,
quiet for three heartbeats and with no live state mutation, is backdated so
the existing stale rules clear it or hand it to Recover at once. Another
desktop's fence, a live holder's, or one with a mutation still running keeps
the normal stale window.
… and boot, and pruned after a day

A token-file write that fails no longer breaks a fence operation; an entry
recorded on another machine sharing the profile, or before a reboot, never
proves its holder exited; entries older than 24 hours are dropped. Tests cover
a journal kept for Recover, a successor freshened back after a racing backdate,
a Windows host, and the record across release, supersession, busy and a lost
connection.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant