Skip to content

refactor(orcad): every snapshot state op fits the gateway exec budget in shell; the state lock sends its script once - #30744

Merged
nwparker merged 2 commits into
mainfrom
nwparker/r4-10b-shell-state-ops
Oct 19, 2026
Merged

nwparker merged 2 commits into
mainfrom
nwparker/r4-10b-shell-state-ops

Conversation

@nwparker

@nwparker nwparker commented Oct 19, 2026 •

Copy link
Copy Markdown
Contributor

ELI5

Before Orca updates its server on a remote machine, it saves a copy of your settings and sessions so that a rollback has something to go back to. The commands that save, put back, clear and compare that copy were long shell scripts, and some SSH gateways cut long commands short (#30491). This change makes every one of them short enough to pass whole. It loops over the saved items once instead of writing out each item's full path, and it stops sending the same script twice.

What Changed

  • User-visible: nothing changes when things work. On hosts behind gateways that cut exec requests, the snapshot, restore, clear and compare commands no longer get truncated. Every one is now under the 6 KB budget, uncompressed, even with a very long home path and a held update fence.

  • One loop over the members. Previously each command repeated a test and an rm/mv/diff for every snapshot member, and each repeat carried the full quoted path, which the nested sh -c quoting multiplies. Now each command assigns root, stage, dir and archive once and runs a single for m in orca-profile-index.json orca-data.json profiles profile-move-intents loop.

    • The member names are compile-time constants and are checked to be plain words before they go into the list bare.
    • Failure semantics are kept:
      • restore still extracts into a stage before touching live state;
      • restore still stops at the first member it cannot remove or move in, and reports FAILED;
      • an interrupted restore can still rerun from the intact archive;
      • the verdict lines are unchanged.
  • One script, sent once (folded in from the closed refactor(orcad): the activation snapshot runs on the candidate's Node; state ops send their script once #30741). serializedStateMutationCommand, the lock, fence and 15-minute deadline that every state change runs under, repeated its whole script in both branches of if command -v timeout. The deadline is now a word list, so the script crosses the wire once.

  • Shorter slot selection. The slot runtime and entry selections assign orcad_slot= once instead of repeating the long slot path, which also trims the launch command.

  • Measured worst-case wire bytes (budget 6,144):

    Op Before After
    capture (with prune, as activation runs it) 17,407 5,675
    restore 20,805 5,258
    clear 9,175 4,413
    compare ~5,855 1,800
    state-lock wrapper 6,529 3,998
    launch / WSL launch 8,181 / 6,498 8,122 / 6,439

    The capture, restore, clear and wrapper ceilings are deleted from the byte-budget ratchet.

Why

Round 4 item R4-10b had planned to move these ops onto a Node program inside the server build (decision D-J). Measured, the shrunk shell is smaller than the Node version of every op: capture 5,675 vs 5,815, restore 5,258 vs 5,744. The shell also has to stay anyway, for older server builds and for rollback. A Node version would have meant a second implementation of each op, slot-capability tracking and a new journal field. So the lead revised D-J to keep one shell implementation and #30741 was closed. The archive format (state.tar), the on-disk lock protocol and every verdict are unchanged, so older desktops on the same host interoperate as before.

Linked Issue

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

Visual Proof

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

Testing

  • Real-shell tests (orcad-state-snapshot-shell.test.ts, orcad-state-snapshot-space.test.ts) run capture, restore, clear, prune and the lock on /bin/sh. They include a capture and restore through a gateway that cuts exec requests at 10 KiB and merges stderr. The decoder-fallback test now checks that a capture passes whole through a 6 KiB cut.
  • The string tests now check the member list each op walks: never daemon or logs, and extraction before removal.
  • Units: src/main/managed-server and src/main/ssh, single worker.
  • The full static-analysis job, run locally.
  • SSH hostile-hosts Docker lane: run 39265477437 green on 37d76d0c (the head adds only a test).
  • A real-shell test makes mv fail for one member: restore reports FAILED, keeps the stage, and a rerun restores. A mutation check (dropping the ok=; break guard) makes it fail.

Review

  • Codex (gpt-6.1-sol, high): clean on rounds 1 and 2.
  • Opus: no P1 or P2. It ran all four commands on bash 3.2, dash, zsh-as-sh and ksh, including failed partial removes and moves, and found every verdict and partial-failure state matching the old chain. Its P3 (no real-shell test of the partial-failure paths) is fixed with the test above.

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, the lock protocol and the verdicts are unchanged.
  • No wire, journal or orcad subcommand change.

@nwparker
nwparker marked this pull request as ready for review October 19, 2026 14:11
@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: 1524dd28-7503-4cb7-a77d-c580a71f5741
📥 Commits

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

📒 Files selected for processing: 6
  • src/main/managed-server/host-state/orcad-state-snapshot-shell.test.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/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; 7 remain after this review.

📝 Walkthrough

POSIX snapshot commands now build member lists from validated names and use quoted root and archive paths. Restore extracts into a staging directory before removing and moving members. Clear and compare use member loops. Slot runtime commands build paths from the orcad_slot shell variable. Tests cover snapshot behavior, command structure, and request-size limits.

Priority: ➖ Normal

Merge Risk: ⚪ Minimal · up to fbd38

No actionable issue remains from this review; the PR is mergeable after normal checks.

Pre-merge checks: Passed 5
Check name Status Explanation
Title check Passed The title clearly identifies the main changes: reducing Orca snapshot operation size and sending the state-lock script once. It is specific and related to the changeset.
Description check Passed The description is detailed and covers the change, rationale, linked issues, testing, visual proof, review, platform impact, and compatibility. The repository checklist section is omitted, but the req…
Linked Issues check Passed No active directly linked issue targets remain. Issue #30741 is closed and supplies historical context only, so its Node-based activation requirement does not apply. The PR summary and change summary …
Out of Scope Changes check Passed The reported production changes stay within remote snapshot and launch-command hardening: snapshot loops, the state-lock wrapper, slot selection, and byte limits. The added shell, string, gateway, and…
Docstring Coverage Passed Docstring coverage is 85.71% which is sufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 14 functions across 6 files.
Full details: Description check

Explanation

The description is detailed and covers the change, rationale, linked issues, testing, visual proof, review, platform impact, and compatibility. The repository checklist section is omitted, but the required information is otherwise substantially complete.

Full details: Linked Issues check

Explanation

No active directly linked issue targets remain. Issue #30741 is closed and supplies historical context only, so its Node-based activation requirement does not apply. The PR summary and change summary show the remote snapshot command reductions, state-lock wrapper reduction, slot-selection reduction, and related tests described for the current PR.

Full details: Out of Scope Changes check

Explanation

The reported production changes stay within remote snapshot and launch-command hardening: snapshot loops, the state-lock wrapper, slot selection, and byte limits. The added shell, string, gateway, and byte-budget tests directly validate those changes. No unrelated feature or platform behavior is reported.

✨ Finishing Touches
📝 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
nwparker merged commit 43abe32 into main Oct 19, 2026
124 of 127 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