Skip to content

fix(ssh): make room for the pre-activation snapshot on remote hosts, and say why a capture failed - #30618

Merged
nwparker merged 4 commits into
mainfrom
nwparker/fix-30491-snapshot-room
Oct 19, 2026
Merged

nwparker merged 4 commits into
mainfrom
nwparker/fix-30491-snapshot-room

Conversation

@nwparker

@nwparker nwparker commented Oct 19, 2026 •

Copy link
Copy Markdown
Contributor
Files Added Deleted Net
Test 6 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​366 $\color{#cf222e}{\Huge{\mathbf{−}}}$​7 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​359
Prod 8 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​303 $\color{#cf222e}{\Huge{\mathbf{−}}}$​60 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​243

ELI5

Every time Orca updated its server on a remote machine, it saved a full backup copy of your Orca state first, and never deleted the old ones. A backup that failed halfway also left its half-written file behind. On a small disk or a disk quota, those copies piled up until no update could make its backup, and the update failed with a message that did not say why. Now Orca keeps only the backups that can still be used, cleans up after a failed backup, checks for room before stopping anything, and tells you what the backup tool reported.

What Changed

Before: each update's pre-activation snapshot (~/.orca-remote/orcad-state-snapshots/pre-*) stayed forever, a failed capture left state.tar.partial, and the error was a generic "Could not snapshot". On a nearly full home the update stopped the running server, failed the snapshot, then had to restart the old server.

After:

  • Prune: the capture removes every pre-* snapshot except the new one and the one the activation record names (the only one a rollback can restore). Rollback-rescue copies are never touched. Windows hosts are unchanged.
  • Failed capture: removes its partial archive and empty directory, and prints tar's (or mkdir's) error, which now appears in the message, e.g. ...before activating 1.3.0: tar: Cannot write: No space left on device.
  • Room check before anything stops: a read-only probe measures the state (du), what the prune would reclaim, and free space (df -Pk). If the snapshot will not fit, the update is not activated, the current server is left in place, and the message says how much is free, how much a prune would reclaim, and how much to free. The probe runs before the last terminal recount, gives each du a 12 s host-side deadline (GNU or old-BusyBox timeout syntax, whichever works), and any unreadable, timed-out, or lost answer counts as "unknown", so the capture itself still decides (the previous behaviour).

The newest-mtime probe moved unchanged into orcad-state-newest-mtime.ts so the snapshot module stays under its line limit.

Why

Only the snapshot the activation record names can ever be restored, so older ones are pure cost. Checking room before stopping the server turns a stop/fail/restart cycle into a clear refusal that leaves the user's running server alone. The probe fails open because it is advisory: a wrong "no room" would block updates, while a wrong "room" just falls back to the capture's own failure handling, which now cleans up and explains itself.

ref-oss check: this work went through more than three review rounds, so we compared it with how other remote-development servers handle upgrades. They keep only the install and state they can still roll back to, clean up older copies on update, and treat cleanup and space checks as best-effort, not as a gate that can block an update on its own. That matches this design (prune to what the record can restore, fail open on unknown space), so the approach did not change.

Linked Issue

Refs #30491 (the gateway half was fixed and closed by #30549; this is the follow-up for the snapshot failing on a full or quota-limited home).

Visual Proof

N/A: no UI change. The only user-visible change is the text of the update-failure and not-activated messages, quoted above.

Testing

  • Unit tests: src/main/ssh and src/main/managed-server folders, single worker (262 files, 3293 tests pass). New tests cover pruning with versions containing +/. and near-miss names, rollback-rescue survival, partial-archive cleanup and the tar reason, room refusal leaving the incumbent running with nothing stopped, the prune making room, the record's snapshot kept through both probe and prune (fails if it is dropped from the keep list), the probe running before the recount (fails if moved after), a timed-out scan reading as unknown, and a lost probe channel letting the update proceed.

  • Full "static analysis and typecheck" job run locally, including all ratchets: pass.

  • Live on real hosts (under a throwaway /tmp dir, nothing else touched): ran the exact generated capture and room commands, through the real command wrapper, on omarchy (Arch Linux, GNU tools), openclaw (Ubuntu; dash, plus the probe under BusyBox ash) and macOS (BSD tools, bash 3.2 /bin/sh). Verified: prune kept the new and record-named snapshots and the rollback rescue and removed the old and near-miss ones; an unreadable member gave SNAPSHOT_FAILURE tar: ... Permission denied then FAILED with no partial archive left; an uncreatable snapshot dir gave mkdir's error; the probe printed correct du/df figures; with a stalled du on omarchy the probe answered SNAPSHOT_SPACE UNMEASURED after 12 s.

  • Not verified live: a full managed-server update refusing on a really full disk (that needs a quota or a small filesystem, which needs root); covered by the unit tests above.

  • Codex review: clean after fixing two findings (probe ordering versus the recount, and an unbounded probe). Opus review (two rounds): findings fixed (message overstated free space and claimed the server was running; missing keep-list test; BusyBox before 1.30 needs timeout -t, so the probe now picks the syntax; tests for a timed-out snapshot scan and a lost fence). Windows still does not prune (its snapshot is a directory copy made by a host script); noted as a follow-up.

  • I manually tested these changes locally

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

Review

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

Ensure no issues in: Security, Cross-platoform support (Linux, Windows, Mac), Remote SSH, Mobile, general backwards compatibility, performance

No wire change: everything runs as shell on the remote host from the client that is updating it. Windows hosts skip both the prune and the room check.

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)

@coderabbitai

coderabbitai Bot commented Oct 19, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

📝 Walkthrough

The change adds POSIX snapshot-space measurement and pruning helpers. Snapshot capture can prune eligible snapshots and reports bounded failure details while cleaning up partial output. Activation checks available snapshot capacity before stopping the incumbent. The change also moves newest-state-mtime helpers into a separate module and adds tests for measurement, pruning, capture cleanup, and activation behavior.

Priority: ➖ Normal

Merge Risk: 🔵 Low · up to 7d6a0

An unreadable snapshot member can make the early space check inaccurate, so an update may stop the current server before capture fails. Treat failed scans as unknown before merging, or accept this bounded risk.

Pre-merge checks: Passed 4 · Failed 1

Failed Failed checks: 1 warning

Check name Status Explanation Resolution
Docstring Coverage Warning Docstring coverage is 55.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 20 functions across 14 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 clearly and concisely describes the main changes: making room for remote pre-activation snapshots and reporting capture failures.
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.
Description check Passed The pull request description is complete and follows the repository template. It explains the change, rationale, linked issue, testing, platform coverage, AI disclosure context, review notes, and chec…
Full details: Description check

Explanation

The pull request description is complete and follows the repository template. It explains the change, rationale, linked issue, testing, platform coverage, AI disclosure context, review notes, and checklist status. It also states that visual proof is not applicable because there is no UI change.

  • 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.

@coderabbitai coderabbitai 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.

Actionable comments posted: 1


ℹ️ Review info
⚙️ Run configuration
  • Configuration used: Repository UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: b7da119a-2260-4c48-befb-74e78a23ec14
📥 Commits

Reviewing files that changed from the base of the PR and between f6cc8f6 and 7d6a073278aa45f4f820b3c4ec4d58c986dafafe.

📒 Files selected for processing: 14
  • src/main/managed-server/activation/orcad-activation-crash-recovery.test.ts
  • src/main/managed-server/host-state/orcad-state-newest-mtime.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/host-state/remote-filesystem-space.ts
  • src/main/managed-server/install/orcad-remote-shell-commands.integration.test.ts
  • src/main/managed-server/lifecycle/orcad-rollback-transition.ts
  • src/main/ssh/orcad-installed-activation.ts
  • src/main/ssh/orcad-remote-deploy.test.ts
  • src/main/ssh/orcad-snapshot-room.test.ts
  • src/main/ssh/orcad-snapshot-room.ts

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

Comment on lines +62 to +63
`need=$($deadline du -sk ${members.join(' ')} 2>/dev/null); need_status=$?;`,
'reclaim=; reclaim_status=0; if [ $# -gt 0 ]; then reclaim=$($deadline du -sk "$@" 2>/dev/null); reclaim_status=$?; fi;',

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.

🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win

🔎 Supported by static analysis

🏁 Script executed:

sed -n '39,98p' src/main/managed-server/host-state/orcad-state-snapshot-space.ts
sed -n '28,68p' src/main/ssh/orcad-snapshot-room.ts
sed -n '170,185p' src/main/ssh/orcad-installed-activation.ts

Repository: stablyai/orca

Length of output: 4946


🏁 Script executed:

set -o pipefail
printf '%s\n' '--- relevant definitions and callers ---'
rg -n -F --glob '*.ts' -e 'ORCAD_SNAPSHOT_MEMBERS' -e 'orcadSnapshotRoomRefusal' -e 'orcadSnapshotSpaceCommand' -e 'measureRoom' -e 'capture' -e 'stop' src/main/managed-server src/main/ssh | head -n 240
printf '%s\n' '--- snapshot-space complete module ---'
cat src/main/managed-server/host-state/orcad-state-snapshot-space.ts
printf '%s\n' '--- snapshot room caller block ---'
sed -n '1,240p' src/main/ssh/orcad-snapshot-room.ts
printf '%s\n' '--- focused tests ---'
rg -n -F --glob '*.{ts,tsx}' -e 'UNMEASURED' -e 'need_status' -e 'reclaim_status' -e 'parseOrcadSnapshotSpace' -e 'orcadSnapshotRoomRefusal' -e 'orcadSnapshotSpaceCommand' test tests src | head -n 240 || test "$?" -eq 1
printf '%s\n' '--- direct du behavior with an absent member ---'
tmp=$(mktemp -d)
mkdir "$tmp/present"
printf 'x\n' > "$tmp/present/file"
set +e
out=$(du -sk "$tmp/present" "$tmp/removed" 2>/dev/null)
status=$?
set -e
printf 'status=%s output=%s\n' "$status" "$(printf '%s' "$out" | tr '\n' ';')"
rm -rf "$tmp"

Repository: stablyai/orca

Length of output: 44617


🏁 Script executed:

printf '%s\n' '--- snapshot members ---'
nl -ba src/main/managed-server/host-state/orcad-state-snapshot-members.ts | sed -n '1,70p'
printf '%s\n' '--- capture command and parser ---'
nl -ba src/main/managed-server/host-state/orcad-state-snapshot.ts | sed -n '150,245p'
printf '%s\n' '--- activation flow around room probe, stop, and capture ---'
nl -ba src/main/ssh/orcad-installed-activation.ts | sed -n '140,250p'
printf '%s\n' '--- focused room-space tests ---'
nl -ba src/main/managed-server/host-state/orcad-state-snapshot-space.test.ts | sed -n '85,155p'
printf '%s\n' '--- all direct callers of capture result handling ---'
rg -n -F --glob '*.ts' -e 'captureOrcadStateSnapshot' -e 'parseOrcadSnapshotCapture' -e 'state ===' src/main/ssh src/main/managed-server/activation src/main/managed-server/host-state | head -n 220

Repository: stablyai/orca

Length of output: 26432


Treat every non-zero du status as unknown.

du can print numeric rows for successful operands and still exit 1 when another operand is missing or inaccessible. The current -ge 124 check accepts that partial output, and parseOrcadSnapshotSpace treats it as a complete measurement. This violates the null-on-unreadable contract and can produce an incorrect room result.

Suggested fix
-    `if [ "$need_status" -ge 124 ] || [ "$reclaim_status" -ge 124 ]; then echo "${SPACE_MARKER} UNMEASURED"; else`,
+    `if [ "$need_status" -ne 0 ] || [ "$reclaim_status" -ne 0 ]; then echo "${SPACE_MARKER} UNMEASURED"; else`,

nwparker and others added 4 commits October 19, 2026 00:53
…pture failed

Every update left its own full state copy behind, and a failed capture its partial archive, so a
small or quota-limited home filled until no update could snapshot. The capture now prunes every
pre-* snapshot except the one the activation record names, removes its own partial archive on
failure, and prints tar's error. Before stopping the running server, the activation checks that
the snapshot fits, so a host without room keeps its server.

Refs #30491

Co-Authored-By: Claude <[email protected]>
…reclaims

It also stops claiming the recorded server is running, and a test pins that the record's
snapshot survives both the room check and the prune.

Co-Authored-By: Claude <[email protected]>
…hin a deadline

A slow scan after the recount could let a terminal opened meanwhile be stopped. The scan now runs
first, gives up after 12 s per du (UNMEASURED reads as unknown), and a lost probe channel leaves
the room unknown rather than failing the update. The newest-mtime probe moves to its own module
to keep the snapshot module under its line limit.

Co-Authored-By: Claude <[email protected]>
…re paths

BusyBox before 1.30 takes `timeout -t SECS`; plain `timeout 12` disabled the probe there.
Tests cover a timeout on the old-snapshot scan and a lost fence from the probe.

Co-Authored-By: Claude <[email protected]>
@nwparker
nwparker force-pushed the nwparker/fix-30491-snapshot-room branch from 7d6a073 to e1c016f Compare October 19, 2026 07:54
@nwparker
nwparker merged commit a451f47 into main Oct 19, 2026
59 checks passed
nwparker added a commit that referenced this pull request Oct 19, 2026
nwparker added a commit that referenced this pull request Oct 19, 2026
…snapshot-room PRs crossed (#30680)

* fix(managed-server): import newestStateMtimeCommand from its new module

#30635 and #30618 merged in parallel: #30618 moved newestStateMtimeCommand
to orcad-state-newest-mtime.ts while #30635's byte-budget test imported it from
orcad-state-snapshot.ts, breaking typecheck on main.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

* test(managed-server): measure the snapshot-space probe and record #30618's capture growth

Co-Authored-By: Claude Opus 5.5 <[email protected]>

---------

Co-authored-by: Claude Opus 5.5 <[email protected]>
DoozyX added a commit to DoozyX/orca that referenced this pull request Oct 19, 2026
Upstream 9294b0a (262 commits) into fork e3a5943; 30 conflicted files.
Includes upstream's post-pin stablyai#30680 test fix for the stablyai#30635/stablyai#30618 crossing,
and splits two files the merge pushed over max-lines.

Claude-Session: https://claude.ai/code/session_012SWXYezr9cxoRQJFc73DTB
nwparker added a commit that referenced this pull request Oct 19, 2026
…re 1.30 (#30840)

The state mutation wrapper ran `timeout -s KILL 900 sh -c ...`, which old
BusyBox (`timeout [-t SECS] [-s SIG] PROG`) reads as running a program
named 900. The script never ran, the capture answered nothing and parsed
as failed, so every update stopped the server and rolled back. Probe the
syntax as the room check (#30618) already does.

Co-authored-by: Claude <[email protected]>
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