Skip to content

fix(ssh): preserve activation commands through SSH gateways - #30503

Closed
zzzpyyy wants to merge 1 commit into
stablyai:mainfrom
zzzpyyy:fix/ssh-gateway-long-commands
Closed

zzzpyyy wants to merge 1 commit into
stablyai:mainfrom
zzzpyyy:fix/ssh-gateway-long-commands

Conversation

@zzzpyyy

@zzzpyyy zzzpyyy commented Oct 19, 2026

Copy link
Copy Markdown
Contributor

ELI5

After an update, connecting to a remote machine could fail because an SSH gateway cut a long setup command in half. Send a smaller command so Orca can complete the state snapshot needed before activation.

What Changed

  • For POSIX exec requests larger than 8,000 bytes, use gzip/base64 when it produces a shorter request. Keep the existing 1,024-byte argument chunks, preserve trailing newlines and exit status, and leave stdin available for relay traffic and uploads.
  • Quietly wait for the snapshot heartbeat after stopping it. On the affected gateway, stderr is merged into stdout; Bash's Terminated notification otherwise follows CAPTURED and makes a successful snapshot look like a failure.
  • Add a real capture/restore regression through a simulated 10 KiB gateway, plus long-command coverage for shell parsers, Unicode, stdin, decoding failures and incompressible input.

Why

The activation snapshot and restore scripts exceed the affected gateway's exec limit. Truncation breaks shell quoting before the script can run. Compression fixes the shared wrapper used by both SSH transports without adding a temporary upload or consuming stdin, which already carries protocol/file data.

The heartbeat cleanup was found by checking the resulting commands through the real gateway: compression allowed the snapshot to run, but merged job notifications still broke its result parser. Waiting for that child removes the notification at its source.

Linked Issue

Fixes #30491

Visual Proof

N/A

No UI changes. Before/after transport evidence:

Original wrapper, simulated 10 KiB gateway:
  shell: unexpected EOF while looking for matching quote
  snapshot: expected "captured", received "failed"

Fixed wrapper and heartbeat cleanup, real SSH gateway to Linux:
  snapshot command: approximately 11.7 KB -> 1.7 KB; CAPTURED
  restore command:  approximately 15.6 KB -> 1.8 KB; RESTORED
  restored fixture contents and released mutation lock verified
  Unicode output and relay stdin preserved

Testing

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

147 tests passed, 7 skipped across seven related suites on macOS (unavailable shells and the Linux-only /proc case were skipped). The two gateway regression cases fail with the original wrapper. Real SSH validation used disposable fixtures on a Linux host behind the affected gateway and removed them afterward.

ORCA_BACKGROUND_LAUNCH=1 node node_modules/vitest/vitest.mjs run --config config/vitest.config.ts \
  src/main/ssh/ssh-posix-command-wrapper.test.ts \
  src/main/ssh/connection/ssh-connection-channel-open.test.ts \
  src/main/ssh/system-transport/system-ssh-operations.test.ts \
  src/main/ssh/ssh-exec-rc-stdout-noise.test.ts \
  src/main/managed-server/host-state/orcad-state-snapshot-shell.test.ts \
  src/main/managed-server/host-state/orcad-state-snapshot.test.ts \
  src/main/managed-server/host-state/orcad-state-mutation-exec.test.ts

Oxlint, Oxfmt and git diff --check passed for the changed files. Full dependency installation hit ENOSPC, so the focused suites used a temporary installation with the pinned Vitest version and required dependencies. Full typecheck/build remain for CI; the local typecheck could not load electron-vite/node from the incomplete development environment.

AI Disclosure

Implemented and tested with OpenAI Codex (GPT-6).

Review

Self-reviewed shell quoting, decoder failure behavior, stdin ownership, heartbeat cleanup and preservation of snapshot/fence checks.

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

Compressed POSIX requests require base64 and gzip on the remote host; short requests retain the decoder-free printf form. Compression is best effort: incompressible commands keep their original representation, so this does not impose or guarantee a universal exec-size ceiling. Windows commands retain their existing wrapper bypass. No remote Orca protocol/version change is required.

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)

Copilot AI balanced review requested due to automatic review settings October 19, 2026 03:06

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

An organization owner can choose the repository organization as the billing source for reviews requested by members with a paid Copilot license. Learn about Copilot code review billing.

@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: 81a27a0f-634b-4edd-befb-9518b7647d43
📥 Commits

Reviewing files that changed from the base of the PR and between 51530bb and 431c86f.

📒 Files selected for processing: 4
  • src/main/managed-server/host-state/orcad-state-snapshot-shell.test.ts
  • src/main/managed-server/host-state/orcad-state-snapshot.ts
  • src/main/ssh/ssh-connection-utils.ts
  • src/main/ssh/ssh-posix-command-wrapper.test.ts

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

📝 Walkthrough

The remote command wrapper now compresses commands when they exceed 8,000 bytes and uses the compressed wrapper only when it is shorter. Tests cover shell execution and a simulated gateway request limit. Snapshot lock cleanup now waits for the heartbeat process before removing the lock. A snapshot shell test checks capture, restore, profile contents, and lock removal.

Priority: ➖ Normal

Severity of issue fixed: Medium

Merge Risk: ⚪ Minimal · up to 431c8

No actionable merge-blocking issue is established. Normal checks can proceed, though the gateway test’s coverage of both snapshot commands remains unconfirmed.

Pre-merge checks: Passed 3 · Failed 1 · Inconclusive 1

Failed Failed checks: 1 warning · 1 inconclusive

Check name Status Explanation Resolution
Docstring Coverage Warning Docstring coverage is 50.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 4 functions across 4 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
Linked Issues check Inconclusive The changes directly address the existing-machine snapshot failure in #30491. The shared POSIX wrapper now compresses long commands, and the snapshot cleanup reaps the heartbeat process. The added tes… Provide focused evidence that adding a new machine succeeds after this change, or clarify that the host-claim failure is separate and supply the relevant linked issue or scope. Also provide end-to-end evidence for the existing-machine activ…
Passed Passed checks: 3 passed
Check name Status Explanation
Title check Passed The title clearly and concisely describes the main SSH gateway fix for preserving activation commands.
Description check Passed The description covers the required sections, explains the user impact and implementation, links issue #30491, documents testing and limitations, and marks visual proof as not applicable. It also iden…
Out of Scope Changes check Passed The changed wrapper code, heartbeat cleanup, and regression tests support the stated SSH gateway and snapshot reliability objective. The tests cover command size, compression selection, stdin, decodin…
Full details: Description check

Explanation

The description covers the required sections, explains the user impact and implementation, links issue #30491, documents testing and limitations, and marks visual proof as not applicable. It also identifies that full typecheck and build remain for CI.

Full details: Out of Scope Changes check

Explanation

The changed wrapper code, heartbeat cleanup, and regression tests support the stated SSH gateway and snapshot reliability objective. The tests cover command size, compression selection, stdin, decoding, shell parsing, capture, restore, and lock cleanup. No unrelated product behavior is changed.

Full details: Linked Issues check

Explanation

The changes directly address the existing-machine snapshot failure in #30491. The shared POSIX wrapper now compresses long commands, and the snapshot cleanup reaps the heartbeat process. The added tests cover capture and restore through a truncated, stderr-merging gateway. However, #30491 also reports failure when adding a new machine through the host-claim path. The issue does not establish a shared cause, and the diff provides no evidence for that path or for the complete expected outcome.

Resolution

Provide focused evidence that adding a new machine succeeds after this change, or clarify that the host-claim failure is separate and supply the relevant linked issue or scope. Also provide end-to-end evidence for the existing-machine activation result if the issue requirement is intended to cover that full outcome.

  • Fix all pre-merge checks with AI
  • 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

Copy link
Copy Markdown
Contributor

Thank you @zzzpyyy — your diagnosis was right, and I reproduced it end to end: a real managed-orcad deploy to a CentOS 7 host through an SSH gateway that cuts exec requests at 10 KiB and merges stderr fails on main with the exact error from #30491, and passes with your change.

I've carried your commit unchanged (your authorship kept) into #30549, with a few follow-ups from review:

  • a plain-command fallback for hosts without base64/gzip (the compressed wrapper now checks for them first and the client resends once uncompressed), plus base64 -D for macOS before 13;
  • snapshot verdicts and the machine claim are read past gateway noise rather than strictly from the last line;
  • the "could not claim this host's .orca-remote" error now says which step failed and why.

Closing this in favour of #30549 so it can run our CI directly. Thanks again for the careful fix.

@nwparker nwparker closed this Oct 19, 2026
nwparker added a commit that referenced this pull request Oct 19, 2026
…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
nwparker added a commit that referenced this pull request Oct 19, 2026
…commands (#30491) (#30549)

* fix(ssh): preserve activation commands through SSH gateways

* fix(ssh): fall back when a host cannot decode a long command, and read 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

* test(ssh): size the simulated gateway cut from the command, not a fixed 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]>

---------

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

3 participants