Skip to content

fix(orcad): a retained activation fence is ownerless, so recovery can always take it over (BUG-17) - #25698

Merged
OrcaWin merged 3 commits into
OrcaWin/node-rt-phase3from
OrcaWin/node-rt-p3-bug17
Oct 6, 2026
Merged

OrcaWin merged 3 commits into
OrcaWin/node-rt-phase3from
OrcaWin/node-rt-p3-bug17

Conversation

@OrcaWin

@OrcaWin OrcaWin commented Oct 5, 2026 •

Copy link
Copy Markdown
Collaborator
Files Added Deleted Net
Test 6 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​90 $\color{#cf222e}{\Huge{\mathbf{−}}}$​3 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​87
Prod 4 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​88 $\color{#cf222e}{\Huge{\mathbf{−}}}$​28 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​60

ELI5

A managed Orca server could get stuck in a state where orca environment recover always answered "still fresh, try again later", forever. This is BUG-17: two test hosts served nothing for 7.5 hours. This PR makes a fence (the per-host lock that stops two update, rollback or stop runs overlapping) that nobody is working under any more something recovery can take over immediately. It also fixes a small wrong message from #25598.

What Changed

Recovery could never take the fence over (BUG-17, part b)

  • Before:
    • A run that couldn't prove the host was back to one serving server kept the activation fence (.install-lock) and its journal.
    • Recovery may take over a fence only once it is older than 20 minutes, because a fresh one may belong to a run still working.
    • When recovery took over a stale fence, the takeover recreated the lock with a fresh time. If that recovery then failed and kept the fence, the next recovery read it as fresh for another 20 minutes.
    • In BUG-17, every reconcile failed with orcad_recovery_changed_state: the candidate build had started and changed profile state. So each recovery that runs on connect took the fence over, refused and reset the clock. The explicit recover that would accept the changed state only ever saw a fresh lock.
  • After:
    • A run that keeps the fence once it has finished marks the lock as ownerless by backdating its time. This covers an explicit retain(), a kept error, and any failure inside the recovery lock.
    • The next recovery can then take it over immediately, through the existing stale-takeover command. That command still guarantees only one of two simultaneous recoveries wins.
    • A run whose SSH command ended unconfirmed (a remote step may still be running) keeps the lock fresh, as before.
    • Normal update, rollback and stop runs still never take over a fence.
  • The new orphanInstallLockCommand uses touch -m -t 200001010000 on POSIX and sets LastWriteTimeUtc on Windows.

#25598 follow-up (round-7 review, low)

  • A forced update on a degraded host whose terminals all run inside orcad (the daemon has no sessions) reached the "daemon did not report its protocol, retry" refusal first.
  • The orcad_update_ends_in_process_terminals deferral now runs before any protocol checks.

Not in this PR yet: BUG-17 part (a). That is why the update rejected a candidate that had reached ready right after the from-idle restart. The code path matches: the activation check rejected the candidate, which was stopped silently, and the restore was refused because the candidate had changed state. The rejection code needs test-linux's logs from the kept hosts, so it follows in a separate commit.

Why

  • Backdate the lock rather than add a separate "kept" marker or heartbeat file. The existing stale-takeover command already compares the lock's identity, which includes its time, so a backdated lock is taken over exactly once, and no new shell protocol or Windows host operation is needed.
  • The lock's age is still the right signal for a run that crashed. Only a run that is done can say it is done.

Linked Issue

BUG-17 (real-host, test-linux) and the Phase 3 round-7 review (internal).

Visual Proof

N/A. No UI changes.

Testing

  • I manually tested these changes locally

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

  • orcad-retained-fence-takeover.test.ts runs the real POSIX lock commands in a shell. A held lock refuses stale takeover, and once it is marked ownerless the takeover succeeds.

  • orcad-activation-transaction.test.ts checks the wiring:

    • the ownerless mark is applied after retain(), a kept error, and a recovery that keeps the fence or throws;
    • it is not applied after an unconfirmed termination.
  • orcad-update-plan.test.ts adds the forced case with an empty daemon.

  • The wiring and update-plan tests fail without their fixes; I checked by restoring the original files.

Ran locally: pnpm tc:node, the changed-code gate, the format check, and the activation, crash-recovery, decommission, deploy and remote-command tests. Three orcad-runtime-maintenance.test.ts cases fail with "AppEnvironment not initialized", and they fail the same way on the base commit.

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 execution boundary: a fence is marked ownerless only by the run that held it, and only once nothing of that run can still be executing on the host. Cross-platform: POSIX touch, and the Windows timestamp is set through the same PowerShell path the other lock commands already use.

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)

@pullfrog pullfrog Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Important

pnpm tc:node fails on this branch. The acquireFence return-type change is not propagated to two acquireInstallLock mocks, so the static-analysis/typecheck job will go red. See the inline comment for the exact sites and fix.

Reviewed changes

  • A retained fence is now backdated ownerless. withOrcadActivationLock and withStaleOrcadActivationRecoveryLock (orcad-activation-lock.ts) call the new orphanRetainedFence on every retain path (retain(), a kept retainOnError error, a recovery refusal or throw), which runs orphanInstallLockCommand (ssh-relay-install-lock-commands.ts) — POSIX touch -m -t 200001010000, Windows LastWriteTimeUtc. The existing stale-takeover path then reclaims it immediately instead of the retain resetting the 20-minute window; unconfirmed SSH termination still keeps the fence fresh.
  • Forced-update deferral reordered. planOrcadUpdate (orcad-update-plan.ts) now checks inProcessSessions > 0 before the daemon-protocol crossing checks, so a forced update on a degraded host names in-process terminals rather than reading the empty daemon as an unreported protocol.
  • Tests. New real-POSIX lock-command test orcad-retained-fence-takeover.test.ts; the crash-recovery harness models a takeover (acquireFence(options): boolean, fenceFresh) and the crash-recovery mock now threads it; transaction/crash-recovery assertions for the ownerless mark; a new forced empty-daemon update-plan case.

ℹ️ Nitpicks

  • The Windows branch of orphanInstallLockCommand has no test: orcad-retained-fence-takeover.test.ts runs the real commands only on POSIX (describe.skipIf(process.platform === 'win32')). The PowerShell timestamp assignment is the one new host-side operation with no coverage; a command-shape assertion (as the other Windows lock commands use) would pin it.

Pullfrog  | Fix all ➔ | Fix 👍s ➔ | View workflow run | Using deepseek-v4.1-flash (free via Pullfrog for OSS) | 𝕏

m4air added 3 commits October 5, 2026 17:31
… always take it over

BUG-17: a recovery that took a stale fence over, failed and retained it left a fresh lock, so
every later recovery read it as still fresh and the host could never be recovered. A run that
keeps the fence once it is done now backdates the lock; one whose remote command may still be
running keeps it fresh.

Also run the in-process terminal deferral before the forced protocol check, so a degraded host
whose daemon is empty names its in-process terminals instead of an unreported protocol.
… recover just retained

The fake host now answers a stale-only takeover busy while a recovery's own takeover is
fresh, which reproduces BUG-17's 'still fresh' loop without the ownerless mark.
@OrcaWin
OrcaWin force-pushed the OrcaWin/node-rt-p3-bug17 branch from d4385fe to 9f7b37f Compare October 6, 2026 00:33

@pullfrog pullfrog Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ No new issues found.

Reviewed changes

This run re-reviewed PR #25698 after a rebase. Since the prior pullfrog review, the only net content change is the typecheck fix that review flagged.

  • Discarded the acquireFence boolean in two mocks — orcad-managed-wake.test.ts and orcad-remote-decommission.test.ts now call host.acquireFence() inside a block body, so their acquireInstallLock mocks return Promise<void> again and pnpm tc:node passes.
  • Rebased fix/test series — orcad-activation-lock.ts, ssh-relay-install-lock-commands.ts, orcad-update-plan.ts, and their accompanying tests are unchanged in content from the prior review; git diff d4385fecd8..HEAD -- <PR files> shows no other differences.

Pullfrog  | View workflow run | Using deepseek-v4.1-flash (free via Pullfrog for OSS) | 𝕏

@OrcaWin
OrcaWin merged commit 911a082 into OrcaWin/node-rt-phase3 Oct 6, 2026
60 checks passed
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