Skip to content

refactor(orcad): the activation snapshot runs on the candidate's Node; state ops send their script once - #30741

Closed
nwparker wants to merge 2 commits into
mainfrom
nwparker/r4-10b-node-snapshot-capture
Closed

nwparker wants to merge 2 commits into
mainfrom
nwparker/r4-10b-node-snapshot-capture

Conversation

@nwparker

@nwparker nwparker commented Oct 19, 2026 •

Copy link
Copy Markdown
Contributor
Files Added Deleted Net
Test 6 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​176 $\color{#cf222e}{\Huge{\mathbf{−}}}$​29 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​147
Prod 9 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​238 $\color{#cf222e}{\Huge{\mathbf{−}}}$​53 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​185

ELI5

Before Orca updates its server on a remote machine, it saves a copy of your settings and sessions, so a rollback has something to go back to. That save was a very long shell command, and some SSH gateways cut long commands short. This makes the save command much shorter in two ways. It stops sending the same script twice. And the activation save now runs as a small program inside the new server build, instead of as a long shell script.

What Changed

  • User-visible: nothing changes when things work. On hosts behind gateways that cut long exec requests (Remote development machines unreachable after update: host claim and state snapshot failures #30491), every snapshot, restore and clear is now about half its old size, and the activation snapshot is under the 6 KB budget.
  • One script, sent once. serializedStateMutationCommand (the shell lock, fence and 15-minute deadline every state change runs under) repeated its whole script in both branches of if command -v timeout. The deadline is now a word list (orca_deadline=...; orca_state_group $orca_deadline sh -c '...'), so the script crosses the wire once. Measured worst-case wire bytes:
    • wrapper: 6,529 → 3,998
    • shell capture: 17,407 → 9,439
    • restore: 20,805 → 11,136
    • clear: 9,175 → under budget
  • Activation snapshot on the candidate's Node. The activation capture now runs orcad --orcad-state-snapshot capture <root> <snapshotDir> [keep...] on the slot it is about to activate, inside the unchanged shell lock and deadline (5,324 bytes).
    • The new op in src/main/orcad/orcad-state-snapshot-host-op.ts keeps the old contract exactly: the CAPTURED/EMPTY/FAILED verdict, a SNAPSHOT_FAILURE reason of up to 400 characters, refusal of symlinks, umask 077, a .partial file then a rename, and pruning of every other sibling pre-* dir except the recorded snapshot (rollback rescues are never touched).
    • The archive is still state.tar, written by the host's tar, so older clients restore it with tar -x.
  • Shorter slot selection. orcadNodeSlotRuntimeCommand/selectOrcadSlotEntryCommand assign orcad_slot= once instead of repeating the long slot path.
  • Deleted: the shell prune (pruneOrcadSnapshotsScript) and the shell capture's prune parameter. Only the rollback rescue still uses the shell capture, and it never pruned.

Why

This is round 4, R4-10b (decision D-J): move the long POSIX state ops onto Node. Running the op under the candidate slot's own bundle means no new script to stage and no version probe. The candidate's profile preflight has just proven that this exact build runs on this host, and this client built it.

  • Rollback and recovery keep the shell ops for now. The slot they run against may predate the subcommand. Next slice: record the capability in the activation transaction (an optional field), then move restore, clear and compare too, with a shell fallback for older slots.
  • The lock stays in shell. The on-disk protocol is unchanged, so no interop test is needed yet.
  • Alternatives: staging a separate content-addressed host script (as Windows does) adds an upload and a new file for every client version. Writing tar in JS would risk mismatches with the restore's tar -x.

Linked Issue

Part of the SSH/remote hardening round 4 (R4-10b). Related: #30491.

Visual Proof

N/A: there is no UI change. This only changes the remote host commands.

Testing

  • New orcad-state-snapshot-host-op.test.ts runs on the real filesystem with the real tar: the shell's tar -x restores the archive, the daemon dir is excluded, prune keeps the right dirs and every rollback rescue, an empty root reads as EMPTY, a symlink is refused with a reason, an unreadable file fails and removes its partial, an un-prunable old capture doesn't block, and an unknown op fails.
  • A real-shell test runs the full wrapped command against a fake slot. It checks the exact argv, the lock release, and a missing runtime reported as a SNAPSHOT_FAILURE reason.
  • The byte-budget ceilings shrank. The gateway-truncation test now uses a deep home, so it still covers the compressed path.
  • Units: src/main/managed-server, src/main/orcad and src/main/ssh, single worker. The only failures are the known macOS /private/var tmpdir cases in orcad-forked-child-paths.test.ts, which fail the same way on main.
  • The full static-analysis job, run locally: 0 failures.
  • SSH hostile-hosts Docker lane: run 39260789224 passed on 5ca7d7f9, before the final prune-tolerance commit.

Review

  • Codex (gpt-6.1-sol, high): clean on rounds 1 and 2.
  • Opus: no P1 or P2.
    • Fixed: an old capture that can't be pruned no longer blocks the snapshot, matching the shell's rm -rf loop.
    • Dismissed: a failed dynamic import of the op gives no reason. The candidate's preflight loaded the same bundle seconds earlier.
    • Kept: an unreadable data root now fails instead of reading as EMPTY. This is safer, because an empty answer lets a later rollback skip restoring.

Agent skill upstream boundary

  • Not applicable, or this change copies or mechanically translates no upstream skill-installer source, tests, fixtures, registry entries, path tables, comments, or documentation.

Notes

  • Windows: unchanged. It still uses the host-script ops.
  • SSH and mixed versions: the archive format and the lock protocol are unchanged.
  • Cross-platform: tar is started with @orca/process-host.

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)

…e slot's Node; the state lock sends its script once

The state-mutation wrapper repeated its whole script in both branches of the
timeout check, so every capture, restore and clear crossed the wire twice. The
deadline is now a word list and the script is sent once.

The activation's capture (prune, symlink refusal, tar, verdict) moves into
`orcad --orcad-state-snapshot capture`, run by the candidate slot's own Node
inside the unchanged shell lock and deadline. The archive stays state.tar, so
older clients still restore it with tar -x. The rollback rescue keeps the shell
capture, because the slot it runs against may predate the subcommand.
@coderabbitai

coderabbitai Bot commented Oct 19, 2026

Copy link
Copy Markdown
Contributor

Review in Change Stack →

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration
  • Configuration used: Repository UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 995b9069-4408-4927-9bfa-14baac910bb0
📥 Commits

Reviewing files that changed from the base of the PR and between 36913fd and b599402.

📒 Files selected for processing: 15
  • src/main/managed-server/host-state/orcad-slot-state-snapshot-command.ts
  • src/main/managed-server/host-state/orcad-state-snapshot-members.ts
  • src/main/managed-server/host-state/orcad-state-snapshot-space.test.ts
  • src/main/managed-server/host-state/orcad-state-snapshot-space.ts
  • src/main/managed-server/host-state/orcad-state-snapshot.test.ts
  • src/main/managed-server/host-state/orcad-state-snapshot.ts
  • src/main/managed-server/install/orcad-remote-runtime.ts
  • src/main/managed-server/posix-host-op-byte-budget.test.ts
  • src/main/orcad/main.ts
  • src/main/orcad/orcad-state-snapshot-host-op.test.ts
  • src/main/orcad/orcad-state-snapshot-host-op.ts
  • src/main/ssh/orcad-installed-activation.ts
  • src/main/ssh/orcad-snapshot-capture-command.ts
  • src/main/ssh/orcad-snapshot-room.test.ts
  • src/main/ssh/ssh-exec-command-decoder-fallback.test.ts

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 6 remain after this review.

📝 Walkthrough

The change adds a host operation for state snapshot capture and dispatches it through the Orcad command-line entry point. Activation now invokes capture through the candidate slot’s Node runtime on non-Windows hosts. The operation prunes eligible snapshots, validates members, and writes a tar archive. Existing snapshot commands use a shared archive filename constant, omit shell-based capture pruning, and update mutation deadline handling.

Priority: ⬇️ Low

Merge Risk: ⚪ Minimal · up to b5994

The change moves activation snapshot capture to the candidate slot's Node runtime and shrinks remote command sizes. No concrete defect was found, so it is ready to merge after the normal checks.

Pre-merge checks: Passed 4 · Failed 1

Failed Failed checks: 1 warning

Check name Status Explanation Resolution
Docstring Coverage Warning Docstring coverage is 61.90% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 21 functions across 15 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
Passed Passed checks: 4 passed
Check name Status Explanation
Title check Passed The title is concise, specific, and accurately summarizes the two main changes: candidate-Node activation snapshots and single-send state-operation scripts.
Description check Passed The description is complete and closely follows the repository template. It explains the user impact, implementation, rationale, alternatives, testing, compatibility considerations, and checklist stat…
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Full details: Description check

Explanation

The description is complete and closely follows the repository template. It explains the user impact, implementation, rationale, alternatives, testing, compatibility considerations, and checklist status. It also documents known test limitations and the SSH validation timing.

  • Fix all pre-merge checks with AI
✨ Finishing Touches: 💡 1
📝 Generate docstrings: 💡
  • Commit to this branch
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@nwparker

Copy link
Copy Markdown
Contributor Author

Superseded: a shell shrink (one member loop, each path sent once) brings every state op under the 6 KiB budget and is smaller than the Node op, so the lead revised D-J to keep one shell implementation. This PR's good part, the state-lock wrapper sending its script once, is folded into the R4-10b shell PR (linked there).

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