Repository navigation
fix(ssh): managed servers install through SSH gateways that cut long commands (#30491) - #30549
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info
📝 Walkthrough
Priority: ⬆️ High Severity of issue fixed: Medium Merge Risk: 🔵 Low · up to
|
f40c483 to
45f6e1e
Compare
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:
5ff71de1-8e16-4940-bfc9-83f2d3c90959
📥 Commits
Reviewing files that changed from the base of the PR and between c68567ead868e4ae850bc362dfd88568e6b669b7 and 45f6e1e4ea492bc44a78b9ecebbf0c989f64a49d.
📒 Files selected for processing: 12
src/main/managed-server/host-state/orcad-machine-claim-command.tssrc/main/managed-server/host-state/orcad-machine-home.test.tssrc/main/managed-server/host-state/orcad-state-snapshot-shell.test.tssrc/main/managed-server/host-state/orcad-state-snapshot.tssrc/main/managed-server/install/orcad-remote-context.tssrc/main/ssh/connection/ssh-connection.tssrc/main/ssh/connection/ssh-exec-options.tssrc/main/ssh/remote-exec/remote-exec-command.tssrc/main/ssh/ssh-exec-command-decoder-fallback.test.tssrc/main/ssh/ssh-posix-command-wrapper.test.tssrc/main/ssh/ssh-posix-command-wrapper.tssrc/main/ssh/system-transport/system-ssh-command.ts
Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 2 remain after this review.
| if ( | ||
| options.compress === false || | ||
| Buffer.byteLength(wrapped) <= REMOTE_COMMAND_COMPRESSION_THRESHOLD_BYTES |
There was a problem hiding this comment.
🩺 Stability & Availability | 🟡 Minor | ⚡ Quick win
🔎 Supported by static analysis
🏁 Script executed:
sed -n '35,80p' src/main/ssh/ssh-posix-command-wrapper.ts
sed -n '35,85p' src/main/ssh/system-transport/system-ssh-file-transfer.ts
sed -n '125,155p' src/main/ssh/system-transport/system-ssh-file-transfer.ts
sed -n '1,20p' src/main/ssh/connection/ssh-exec-options.tsRepository: stablyai/orca
Length of output: 5391
Make wrapper compression opt-in for direct callers.
When uploadDirectoryViaSystemSsh builds a long remote command, the omitted option can select the compressed wrapper. A host without base64 or gzip then exits with ORCA_COMMAND_DECODER_UNAVAILABLE before reading the tar stream. This direct upload path has no plain-command retry. Make compression opt-in for direct callers.
🐛 Suggested fix
--- "a/src/main/ssh/ssh-posix-command-wrapper.ts"
+++ "b/src/main/ssh/ssh-posix-command-wrapper.ts"
@@ -46,10 +46,10 @@
const decodeAndRun = `decoded=$(printf %b "$@" && printf _) || exit $?; ${runDecoded}`
const chunkArguments = encodedChunks.map(quotePosixShell).join(' ')
const wrapped = `exec /bin/sh -c ${quotePosixShell(decodeAndRun)} orca-command ${chunkArguments}`
if (
- options.compress === false ||
+ options.compress !== true ||
Buffer.byteLength(wrapped) <= REMOTE_COMMAND_COMPRESSION_THRESHOLD_BYTES
) {
return wrapped
}
Update wrapper tests that expect compression to pass { compress: true }.
📝 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.
| if ( | |
| options.compress === false || | |
| Buffer.byteLength(wrapped) <= REMOTE_COMMAND_COMPRESSION_THRESHOLD_BYTES | |
| if ( | |
| options.compress !== true || | |
| Buffer.byteLength(wrapped) <= REMOTE_COMMAND_COMPRESSION_THRESHOLD_BYTES |
…d claims and snapshot verdicts through gateway noise On top of the gateway fix (#30503): - A host without base64 or gzip gets a long command plain: the compressed wrapper checks for its decoders before reading anything, exits 125 with a marker, and execCommand resends once with compressCommand: false and remembers that host. `base64 -D` covers macOS before 13, whose base64 refuses `-d`. - Snapshot capture, restore, presence and compare answers read the last line that is a verdict, so shell noise a stderr-merging gateway appends after it is ignored. - The machine claim reads the claim line by line, and every failed step now prints CLAIM_FAILED <step> <error> with the df line, so "orcad could not claim this host's .orca-remote" says what failed and how to fix it instead of exiting 65 with the raw command or failing with no reason. A failed write no longer leaves a partial file. Refs #30491
…ed 10 KiB The snapshot command repeats its temp path ~40 times, so on CI's short /tmp it fell under 10 KiB and the truncation precondition failed. Co-Authored-By: Claude <[email protected]>
5a5a915 to
343cd01
Compare
ELI5
Some company networks put an SSH "gateway" between you and your machines. The one in #30491 cuts every command longer than about 10 KB, and mixes the command's error stream into its normal output. Orca's pre-update snapshot command is longer than that, so after updating, Orca refused to start its server on those machines. This sends long commands compressed so they fit, keeps working on hosts that can't decompress, and stops gateway noise from being read as a failure.
This carries @zzzpyyy's fix from #30503 (their commit is kept as-is, with their authorship) plus follow-ups from review.
What Changed
Before: behind such a gateway, connecting to a machine after the update failed with:
A new machine could fail with
orcad could not claim this host's .orca-remote, with no reason given.After: the server installs and starts through the gateway. If the claim still fails, the message names the step that failed, the shell's own error, and what to do (for example, "The filesystem holding ~/.orca-remote has 0 KB free: free space there, then reconnect.").
Mechanism:
wrapRemoteCommandForPosixShell. A wrapped command over 8,000 bytes is now sent as gzip+base64 when that is shorter (the snapshot command shrinks from about 11.6 KB to about 1.7 KB). The remote side decodes it, gzip checks the whole payload, and only then runs it. Stdin, exit status and trailing newlines are unchanged.waited for after it is killed. Without that, bash prints aTerminatedjob notice when it exits, the gateway moves it onto stdout afterCAPTURED, and a snapshot that worked was read as failed.base64andgzipbefore it reads anything. If either is missing it exits 125 with a marker, andexecCommandresends the same command uncompressed once and remembers that connection.base64 -Dcovers macOS before 13, whosebase64rejects-d.CAPTURED,RESTORED, and so on), not just the last line. The machine claim is read line by line too.CLAIM_FAILED <step> <error>plus thedfline, and no longer leaves a half-written file behind. Before, a failed write exited 65 and the user saw the raw shell command. A claim that read back wrong gave no reason at all.Why
The gateway limits the size of the SSH exec request, so the command has to get smaller, or travel some other way. Uploading the script first would mean a temp file plus an extra round trip on every long command, and stdin is already in use for relay frames and uploads. Compressing inside the existing wrapper changes one function that both SSH transports share, and short commands stay byte-for-byte as before. Hosts without the decoders get the old plain path through a one-time retry. That is safe because the wrapper exits before running anything or reading stdin, so nothing ran twice. Reading the last verdict line, instead of the last line, protects every snapshot step from noise without changing what the host prints, so older hosts see no wire change.
On the new-machine error: a gateway that only truncates and merges in order does not reproduce it. With that gateway, current main's claim succeeds. The only way I found to get exactly that message is extra output landing next to the claim, which a stderr-merging gateway can deliver. A test reproduces that, and the line-by-line read fixes it. The claim's other failure paths now name their cause, so if a user still hits it the message says what to fix.
Linked Issue
Fixes #30491
Supersedes #30503 (carried here with the original commit and author).
Visual Proof
N/A. No UI change; the only user-visible change is error text. The proof is the transport runs below.
Testing
Live, on a real Linux host (openclaw, Docker, isolated temp dirs, OPTION A): the real client-side managed-orcad deploy (
proveManagedOrcadCell, the hostile-host lane's prover) against a CentOS 7 / glibc 2.17 container. This is the reporter's runtime:0.1.0+77dfa08c40aais 1.4.229'slinux-x64-glibc217slot. The SSH connection went through an ssh2 gateway that cuts exec requests at 10 KiB and merges stderr into stdout. It used the 1.4.229 packaged orcad template:Could not snapshot /root/.orca before activating 0.1.0+77dfa08c40aa. Orca's persisted state carries no schema version, so without a snapshot a rollback has no way back. Refusing to activate.The gateway log shows the 10,309-byte capture request cut to 10,240.Automated (each new case fails on main):
ssh-exec-command-decoder-fallback.test.ts: a host without base64/gzip gets one plain resend and then plain commands; a host with them gets one compressed call; a snapshot capture goes through a simulated 10 KiB stderr-merging gateway.ssh-posix-command-wrapper.test.ts: the decoder-missing exit and marker, a payload that fails to decode never runs, macOSbase64 -D, and the explicit plain mode (plus fix(ssh): preserve activation commands through SSH gateways #30503's cases).orcad-machine-home.test.ts: the claim is read through merged noise (main fails with exactlyorcad could not claim this host's .orca-remote); a read-only~/.orca-remotenames the write step andPermission deniedand leaves no partial file; a full disk names the failing step and0 KB free.orcad-state-snapshot.test.ts: capture and restore verdicts survive a trailingTerminatednotice and CRLF.orcad-state-snapshot-shell.test.ts(fix(ssh): preserve activation commands through SSH gateways #30503): fenced capture and restore through a 10 KiB gateway.Local: the full "static analysis and typecheck" job steps,
pnpm tc:node, and thesrc/main/sshandsrc/main/managed-serverunit folders.AI Disclosure
Review
Security review of #30503: the compressed payload is base64 (
[A-Za-z0-9+/=]), chunked through the same printf encoder andshellEscapeas before, so it adds no new way for text to escape quoting. The decoded script is our own command, and gzip's CRC check stops a cut payload from running. It changes no workflows, scripts or install hooks. Windows/PowerShell remotes still skip the wrapper (wrapCommand: false).Agent skill upstream boundary
Notes
-Dfallback.~/.orcaunder~/.orca-remote/orcad-state-snapshots/and never prunes it. A failed capture also leaves its partial archive behind, which can fill a small home. I reproduced this on CentOS 7, and a separate PR fixes it.Checklist
N/Awith reasonpnpm lint,pnpm typecheck,pnpm test, andpnpm buildpass (or CI will cover; local preferred)