Repository navigation
fix(ssh): make room for the pre-activation snapshot on remote hosts, and say why a capture failed - #30618
Conversation
📝 Walkthrough
Priority: ➖ Normal Merge Risk: 🔵 Low · up to
|
There was a problem hiding this comment.
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.tssrc/main/managed-server/host-state/orcad-state-newest-mtime.tssrc/main/managed-server/host-state/orcad-state-snapshot-members.tssrc/main/managed-server/host-state/orcad-state-snapshot-space.test.tssrc/main/managed-server/host-state/orcad-state-snapshot-space.tssrc/main/managed-server/host-state/orcad-state-snapshot.test.tssrc/main/managed-server/host-state/orcad-state-snapshot.tssrc/main/managed-server/host-state/remote-filesystem-space.tssrc/main/managed-server/install/orcad-remote-shell-commands.integration.test.tssrc/main/managed-server/lifecycle/orcad-rollback-transition.tssrc/main/ssh/orcad-installed-activation.tssrc/main/ssh/orcad-remote-deploy.test.tssrc/main/ssh/orcad-snapshot-room.test.tssrc/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.
| `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;', |
There was a problem hiding this comment.
🎯 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.tsRepository: 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 220Repository: 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`,…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]>
7d6a073 to
e1c016f
Compare
's capture growth Co-Authored-By: Claude Opus 5.5 <[email protected]>
…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]>
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
…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]>
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 leftstate.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:
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....before activating 1.3.0: tar: Cannot write: No space left on device.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 eachdua 12 s host-side deadline (GNU or old-BusyBoxtimeoutsyntax, 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.tsso 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/sshandsrc/main/managed-serverfolders, 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
/tmpdir, 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 gaveSNAPSHOT_FAILURE tar: ... Permission deniedthenFAILEDwith no partial archive left; an uncreatable snapshot dir gave mkdir's error; the probe printed correctdu/dffigures; with a stalledduon omarchy the probe answeredSNAPSHOT_SPACE UNMEASUREDafter 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
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
N/Awith reasonpnpm lint,pnpm typecheck,pnpm test, andpnpm buildpass (or CI will cover; local preferred)