Repository navigation
fix(managed-server): snapshot capture and restore run on BusyBox before 1.30 - #30840
Conversation
…re 1.30 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]>
📝 Walkthrough
Priority: ➖ Normal Merge Risk: 🔵 Low · up to
|
There was a problem hiding this comment.
Actionable comments posted: 1
🧹 Nitpick comments: 1
src/main/managed-server/host-state/orcad-state-snapshot-shell.test.ts: 1
129-135: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winAssert the mutation timeout arguments.
The shim validates only the
-tsyntax and then executes the command. Iforca_deadlineis empty, the capture command still runs and returnscaptured. Record shim invocations and assert that the mutation invocation contains-t 900 -s KILL, separately from the one-second probe.
ℹ️ Review info
⚙️ Run configuration
- Configuration used: Repository UI
- Review profile: CHILL
- Plan: Advanced
- Run ID:
3df12a48-2426-4407-843b-b126f1ca101d
📒 Files selected for processing: 2
src/main/managed-server/host-state/orcad-state-snapshot-shell.test.tssrc/main/managed-server/host-state/orcad-state-snapshot.ts
Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 3 remain after this review.
| `orca_deadline=; if timeout 1 true 2>/dev/null; then orca_deadline="timeout -s KILL ${ORCAD_STATE_MUTATION_DEADLINE_SECONDS}";`, | ||
| `elif timeout -t 1 true 2>/dev/null; then orca_deadline="timeout -t ${ORCAD_STATE_MUTATION_DEADLINE_SECONDS} -s KILL"; fi;`, |
There was a problem hiding this comment.
🩺 Stability & Availability | 🟡 Minor | ⚡ Quick win
🔎 Supported by static analysis
🏁 Script executed:
set -eu
printf '%s\n' '--- changed file ---'
nl -ba src/main/managed-server/host-state/orcad-state-snapshot.ts | sed -n '1,240p'
printf '%s\n' '--- related timeout probes and callers ---'
rg -n -F --glob '*.{ts,tsx}' -e 'timeout 1 true' -e 'timeout -t 1 true' -e 'sh -c :' -e 'orca_deadline' -e 'ORCAD_STATE_MUTATION_DEADLINE_SECONDS' srcRepository: stablyai/orca
Length of output: 15385
🏁 Script executed:
set -eu
printf '%s\n' '--- changed file ---'
nl -ba src/main/managed-server/host-state/orcad-state-snapshot.ts | sed -n '1,240p'
printf '%s\n' '--- related timeout probes and callers ---'
rg -n -F --glob '*.{ts,tsx}' -e 'timeout 1 true' -e 'timeout -t 1 true' -e 'sh -c :' -e 'orca_deadline' -e 'ORCAD_STATE_MUTATION_DEADLINE_SECONDS' src || test "$?" -eq 1Repository: stablyai/orca
Length of output: 15385
Probe timeout with the shell that runs the mutation.
If true is available only as a shell builtin, timeout cannot execute it. Both probes can fail, leaving orca_deadline empty even when timeout is installed. Use sh -c :, which the mutation already requires.
🐛 Suggested fix
--- "a/src/main/managed-server/host-state/orcad-state-snapshot.ts"
+++ "b/src/main/managed-server/host-state/orcad-state-snapshot.ts"
@@ -136,8 +136,8 @@
// Why timeout inside the group: KILL then reaches tar and rm, not only the shell.
// The deadline is a word list, so the script is sent once, not once per branch.
// BusyBox before 1.30 spells it `timeout -t SECS`, as the room probe found.
- `orca_deadline=; if timeout 1 true 2>/dev/null; then orca_deadline="timeout -s KILL ${ORCAD_STATE_MUTATION_DEADLINE_SECONDS}";`,
- `elif timeout -t 1 true 2>/dev/null; then orca_deadline="timeout -t ${ORCAD_STATE_MUTATION_DEADLINE_SECONDS} -s KILL"; fi;`,
+ `orca_deadline=; if timeout 1 sh -c : 2>/dev/null; then orca_deadline="timeout -s KILL ${ORCAD_STATE_MUTATION_DEADLINE_SECONDS}";`,
+ `elif timeout -t 1 sh -c : 2>/dev/null; then orca_deadline="timeout -t ${ORCAD_STATE_MUTATION_DEADLINE_SECONDS} -s KILL"; fi;`,
`orca_state_group $orca_deadline ${run};`,
`status=$?; ${owned ? `[ "$status" -eq ${ORCAD_FENCE_LOST_EXIT} ] && exit ${ORCAD_FENCE_LOST_EXIT}; ` : ''}if [ "$status" -eq 124 ] || [ "$status" -eq 137 ]; then echo ${ORCAD_STATE_MUTATION_DEADLINE}; fi`
].join(' ')📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| `orca_deadline=; if timeout 1 true 2>/dev/null; then orca_deadline="timeout -s KILL ${ORCAD_STATE_MUTATION_DEADLINE_SECONDS}";`, | |
| `elif timeout -t 1 true 2>/dev/null; then orca_deadline="timeout -t ${ORCAD_STATE_MUTATION_DEADLINE_SECONDS} -s KILL"; fi;`, | |
| `orca_deadline=; if timeout 1 sh -c : 2>/dev/null; then orca_deadline="timeout -s KILL ${ORCAD_STATE_MUTATION_DEADLINE_SECONDS}";`, | |
| `elif timeout -t 1 sh -c : 2>/dev/null; then orca_deadline="timeout -t ${ORCAD_STATE_MUTATION_DEADLINE_SECONDS} -s KILL"; fi;`, |
ELI5
Before Orca updates its server on an SSH host, it saves a snapshot of the server's state so it can roll back. On hosts with an old BusyBox (before 1.30), the snapshot command never actually ran, so every update stopped the server, failed with "Could not snapshot...", and restarted it. Now the snapshot works there too.
What Changed
Before: the state-mutation wrapper (used by snapshot capture, restore and clear) ran
timeout -s KILL 900 sh -c …. BusyBox before 1.30 only acceptstimeout [-t SECS] [-s SIG] PROG, so it treated900as the program to run and exited 127. The script never ran. The wrapper printed no verdict, andparseOrcadSnapshotCaptureread that asfailedwith no reason.After: the wrapper probes which syntax the host's
timeouttakes, the same way the snapshot room check from #30618 already does:timeout -s KILL 900;timeout -t 900 -s KILL;timeoutwas missing.Why
This matches the probe that
orcad-state-snapshot-space.tsalready uses for the same BusyBox, so the two commands now agree about the host. When #30744 rewrote this line, it kept the old syntax.Alternatives considered:
Linked Issue
Post-hardening scan finding; follow-up to #30618 and #30744.
Visual Proof
N/A: the change is a remote shell command, with no UI.
Testing
orcad-state-snapshot-shell.test.ts. It puts an old-BusyBox-styletimeoutstub first on PATH (it accepts only-t SECS [-s SIG] PROG). On main the capture parses asfailed; with the fix it parses ascaptured.src/main/managed-server/host-state(single worker): 110 passed.Review
Agent skill upstream boundary
Notes
Checklist
N/Awith reasonpnpm lint,pnpm typecheck,pnpm test, andpnpm buildpass (or CI will cover; local preferred)