Skip to content

fix(ssh): managed servers install through SSH gateways that cut long commands (#30491) - #30549

Merged
nwparker merged 3 commits into
mainfrom
nwparker/fix-30491-ssh-gateway
Oct 19, 2026
Merged

nwparker merged 3 commits into
mainfrom
nwparker/fix-30491-ssh-gateway

Conversation

@nwparker

@nwparker nwparker commented Oct 19, 2026 •

Copy link
Copy Markdown
Contributor
Files Added Deleted Net
Test 7 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​402 $\color{#cf222e}{\Huge{\mathbf{−}}}$​19 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​383
Prod 9 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​251 $\color{#cf222e}{\Huge{\mathbf{−}}}$​31 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​220

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:

Could not snapshot /home/work/.orca before activating 0.1.0+77dfa08c40aa. … Refusing to activate.

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:

  1. Compressed long commands (fix(ssh): preserve activation commands through SSH gateways #30503, @zzzpyyy). Every POSIX SSH command already goes through 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.
  2. Quiet heartbeat cleanup (fix(ssh): preserve activation commands through SSH gateways #30503). The snapshot lock's background heartbeat is now waited for after it is killed. Without that, bash prints a Terminated job notice when it exits, the gateway moves it onto stdout after CAPTURED, and a snapshot that worked was read as failed.
  3. Fallback for hosts without the decoders (follow-up). The compressed form checks for base64 and gzip before it reads anything. If either is missing it exits 125 with a marker, and execCommand resends the same command uncompressed once and remembers that connection. base64 -D covers macOS before 13, whose base64 rejects -d.
  4. Verdicts read through noise (follow-up). Snapshot capture, restore, presence and compare answers now take the last line that is a verdict (CAPTURED, RESTORED, and so on), not just the last line. The machine claim is read line by line too.
  5. Claim failures say why (follow-up). Each step of the claim command that fails prints CLAIM_FAILED <step> <error> plus the df line, 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

  • I manually tested these changes locally
  • Automated tests added/updated, or explained why not below

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+77dfa08c40aa is 1.4.229's linux-x64-glibc217 slot. 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:

  • current main: fails with 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.
  • this branch: the claim, snapshot, launch, readiness, liveness and decommission all pass. All 53 exec requests fit under the limit (largest 5,191 bytes).
  • Without the gateway, the CentOS 7 hostile-host cell also passes on this code.

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, macOS base64 -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 exactly orcad could not claim this host's .orca-remote); a read-only ~/.orca-remote names the write step and Permission denied and leaves no partial file; a full disk names the failing step and 0 KB free.
  • orcad-state-snapshot.test.ts: capture and restore verdicts survive a trailing Terminated notice 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 the src/main/ssh and src/main/managed-server unit folders.

AI Disclosure

Review

Security review of #30503: the compressed payload is base64 ([A-Za-z0-9+/=]), chunked through the same printf encoder and shellEscape as 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

  • Not applicable, or this change copies or mechanically translates no upstream skill-installer source, tests, fixtures, registry entries, path tables, comments, or documentation.

Notes

  • Remote wire compatibility: what the host prints is unchanged. Every change is in client-generated shell and client-side parsing, so it works the same with older and newer hosts.
  • Cross-platform: POSIX remotes only; Windows remotes are untouched. macOS remotes are covered by the -D fallback.
  • Out of scope, follow-up: every update keeps a full copy of ~/.orca under ~/.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

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

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: 5d283b88-74ea-4f9f-b51e-1d38560ed13a
📥 Commits

Reviewing files that changed from the base of the PR and between 45f6e1e4ea492bc44a78b9ecebbf0c989f64a49d and 343cd01.

📒 Files selected for processing: 1
  • 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; 3 remain after this review.

📝 Walkthrough

The SSH command wrapper can compress long commands and retry without compression when a host lacks the required decoder. Host-claim commands now report step-specific failures and available filesystem space, and callers use the resulting failure messages. Snapshot parsing selects the last recognized verdict in command output, and mutation cleanup waits for the heartbeat process to exit.

Priority: ⬆️ High

Severity of issue fixed: Medium

Merge Risk: 🔵 Low · up to 343cd

Most SSH commands retain the decoder fallback, but directory uploads can still fail on decoderless hosts when their commands are long enough. This is a bounded merge risk that should be fixed or explicitly accepted.

Pre-merge checks: Passed 4 · Failed 1

Failed Failed checks: 1 warning

Check name Status Explanation Resolution
Docstring Coverage Warning Docstring coverage is 44.83% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 29 functions across 17 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 identifies the SSH gateway issue and the managed-server installation fix.
Description check Passed The description follows the required template and clearly explains the problem, user impact, implementation, linked issue, testing, compatibility, scope, and checklist status. The AI Disclosure sectio…
Linked Issues check Passed Issue #30491 requires existing machines to reconnect after updates and new machines to be added. The PR compresses long POSIX SSH commands, retries without compression when decoders are unavailable, a…
Out of Scope Changes check Passed The production changes support issue #30491 by addressing long SSH requests, gateway output noise, snapshot activation, and machine claiming. The tests validate these behaviors. Snapshot pruning and p…
Full details: Description check

Explanation

The description follows the required template and clearly explains the problem, user impact, implementation, linked issue, testing, compatibility, scope, and checklist status. The AI Disclosure section is empty, but this is non-critical for an internal contributor and does not prevent review.

Full details: Linked Issues check

Explanation

Issue #30491 requires existing machines to reconnect after updates and new machines to be added. The PR compresses long POSIX SSH commands, retries without compression when decoders are unavailable, and preserves plain execution for stdin commands. Snapshot verdict parsing and heartbeat cleanup address activation through noisy gateways. Machine-claim parsing tolerates merged output and reports the failed step, shell error, and available-space guidance. The added tests cover compression, fallback, snapshot handling, and machine claims.

Full details: Out of Scope Changes check

Explanation

The production changes support issue #30491 by addressing long SSH requests, gateway output noise, snapshot activation, and machine claiming. The tests validate these behaviors. Snapshot pruning and partial-archive cleanup are explicitly excluded and are not implemented in this PR.

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

@nwparker
nwparker force-pushed the nwparker/fix-30491-ssh-gateway branch 2 times, most recently from f40c483 to 45f6e1e Compare October 19, 2026 04:56

@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: 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.ts
  • src/main/managed-server/host-state/orcad-machine-home.test.ts
  • src/main/managed-server/host-state/orcad-state-snapshot-shell.test.ts
  • src/main/managed-server/host-state/orcad-state-snapshot.ts
  • src/main/managed-server/install/orcad-remote-context.ts
  • src/main/ssh/connection/ssh-connection.ts
  • src/main/ssh/connection/ssh-exec-options.ts
  • src/main/ssh/remote-exec/remote-exec-command.ts
  • src/main/ssh/ssh-exec-command-decoder-fallback.test.ts
  • src/main/ssh/ssh-posix-command-wrapper.test.ts
  • src/main/ssh/ssh-posix-command-wrapper.ts
  • src/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.

Comment on lines +49 to +51
if (
options.compress === false ||
Buffer.byteLength(wrapped) <= REMOTE_COMMAND_COMPRESSION_THRESHOLD_BYTES

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.

🩺 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.ts

Repository: 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.

Suggested change
if (
options.compress === false ||
Buffer.byteLength(wrapped) <= REMOTE_COMMAND_COMPRESSION_THRESHOLD_BYTES
if (
options.compress !== true ||
Buffer.byteLength(wrapped) <= REMOTE_COMMAND_COMPRESSION_THRESHOLD_BYTES

zzzpyyy and others added 3 commits October 18, 2026 23:17
…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]>
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.

Remote development machines unreachable after update: host claim and state snapshot failures

2 participants