Skip to content

Reduce remote session snapshot bandwidth without compressing private text - #22203

Closed
kazu-42 wants to merge 4125 commits into
stablyai:mainfrom
kazu-42:kazu-42/issue-22151-remote-bandwidth
Closed

kazu-42 wants to merge 4125 commits into
stablyai:mainfrom
kazu-42:kazu-42/issue-22151-remote-bandwidth

Conversation

@kazu-42

@kazu-42 kazu-42 commented Sep 22, 2026 •

Copy link
Copy Markdown
Contributor

ELI5

Remote clients repeatedly receive the same terminal-tab metadata, which can leave file browsing waiting behind background updates on a slow link. This reduces that metadata without compressing private text or skipping updates: a synthetic 17-terminal workload uses 49.2% fewer bytes.

What Changed

An authenticated desktop subscription can advertise remote-runtime.snapshot-deflate.v1. The host then compresses only the structure of session.tabs.subscribe / subscribeAll replies before the existing encryption step; the client restores the original result before normal validation and routing. Titles, paths, prompts, messages, unknown fields and unknown field names travel separately, uncompressed but still encrypted. Old peers and explicit opt-out keep the original replies.

The codec uses fresh level-1 compression contexts, caps input/restored results at 256 KiB, bounds decompression and literal references, and retains the existing outbound queue limits. Terminal bytes, file responses, authentication, connection ownership and state ordering are unchanged. Malformed compressed replies fail visibly and close the subscription.

Why

The real desktop path encrypts JSON before WebSocket transmission. Enabling WebSocket compression alone would mostly remove base64 overhead, rather than compressing repeated JSON. Compressing the entire plaintext snapshot would create a same-message secret/attacker-input length oracle, since agent status includes prompts and messages. The separate uncompressed text array avoids that correlation; fresh dictionaries alone would not. This approach also avoids introducing state deltas, dropping intermediate updates, or changing the transport scheduler.

This is a focused improvement to the inventory stream, not a claim that the reporter's deployment is fully fixed. Its stream attribution and actual WAN behavior have not been reproduced.

Linked Issue

Refs #22151. Kept open because real-deployment confirmation and other subscription/replay traffic remain outside this PR's evidence.

Visual Proof

N/A — no UI layout or rendering changes. The proof is encrypted transport integrity plus reproducible bandwidth measurements; no user runtime or visible application windows were touched.

Testing

CI status: the upstream pull-request workflows require maintainer approval and have not executed. Local validation below is not a claim of green upstream CI.

  • Manual desktop UI testing — not performed; automated isolated transport verification is described below
  • Automated tests added/updated

macOS arm64 / Node 24.18.0: 15 focused suites, 113 tests passed, including real localhost WebSocket + E2EE roundtrips, current/legacy capability combinations, explicit opt-out, reconnect to current state, malformed compressed data, exact snapshot and terminal-byte integrity, incompressible traffic, queue overflow/drain, and equal-length secret/attacker-input noninterference. Unknown fields and __proto__ roundtrip without entering the compression dictionary. Existing socket auth, heartbeat, shared-control subscription and backpressure suites also pass.

ORCA_BACKGROUND_LAUNCH=1 pnpm tc:node, pnpm tc:cli, and pnpm run check:code-quality:changed origin/main pass; git diff --cached --check passes. The full application build and full test suite were not run. Windows/Linux/SSH-host execution and rendered Electron checks were not run; the required electron skill is unavailable.

Reproduce the benchmark:

ORCA_BACKGROUND_LAUNCH=1 pnpm exec vitest run --config config/vitest.config.ts \
  src/main/runtime/rpc/runtime-bandwidth.test.ts \
  src/shared/remote-runtime-snapshot-compression-cost.test.ts \
  --maxWorkers 1 --disableConsoleIntercept

The workload is typed session-tab metadata with distinct IDs, titles, paths and agent statuses, plus 2.1 KB/s of terminal payload. Three 34-second cycles each contain 30 seconds of 500 ms snapshot updates and a four-second 100 ms burst; small file-list/file-read replies share the connection twice per second. Actual E2EE payload lengths and WebSocket headers feed a deterministic FIFO model at 0.8 Mbps and 74 ms RTT. These are modeled RPC delays, not measured WAN latency; loss, TCP/VPN overhead, kernel buffering, handler time and encoder scheduling are excluded.

Terminals Wire bytes before / after Reduction Modeled RPC p95 before / after Modeled max before / after
15 5,477,142 / 2,834,694 48.2% 2,467 / 116 ms 3,221 / 116 ms
17 6,134,830 / 3,117,958 49.2% 3,247 / 125 ms 4,120 / 125 ms
20 7,122,342 / 3,548,218 50.2% 4,696 / 418 ms 5,469 / 585 ms

The 17-terminal baseline averages 60.1 KB/s. Regression targets are at least 40% fewer bytes, at least 80% lower modeled p95, max below one second, and peak modeled backlog below 128 KiB. These replace the initial 70% reduction proposal to preserve confidentiality. Every snapshot and terminal frame is retained and verified.

Review follow-up: input-side JSON structural limits now return the original uncompressed response, just like output-side capacity limits; invalid JSON still throws. The deep-input regression failed before the fix and passed afterward. Node 26.9.0's larger compressed output measured 119/131/525 ms p95, 119/133/754 ms maxima, and 8,990/10,514/72,534-byte peak queues for 15/17/20 terminals. The previous 500 ms / 64 KiB thresholds were Node-24-specific; the portable acceptance criteria above preserve a subsecond maximum and large relative improvement without requiring identical zlib output. The codec and benchmark passed 14 tests on Node 26; the three benchmark cases also passed on Node 22.22.0 and Node 24.18.0.

The separate 500-message encoder measurement used 231 ms of CPU (0.46 ms/message), 8.9 MB peak sampled heap growth, 87 KB retained heap growth after GC, and 19.9 MB RSS growth; wall p95/max were 1.29/11.27 ms on this shared development host. These are diagnostic measurements, not portable limits; native allocator retention contributes to RSS. Compression is synchronous with no retained peer dictionaries or added work queue.

Full contract, test commands, bounds and measurements: remote runtime bandwidth reference.

October 22 integration: merged main at 70ab09ca2fb3, preserving the current asynchronous authenticated handshake, credential-revision checks, mobile execution-host routing, and bounded replies. Capability negotiation and explicit opt-out now run through the current handshake. Updated the loopback fixtures to use the current connection and authenticated-principal contracts. The 14 relevant suites pass 88 tests, covering codec bounds and confidentiality, real encrypted WebSocket roundtrips, legacy/opt-out behavior, backpressure, shared-control keepalives, device-key authorization, and reply-size guards. Node, web, CLI and process-host test typechecks pass; changed-code quality has zero findings across 16 code files, and commit lint/React Doctor/formatting hooks pass. The synthetic bandwidth regression still satisfies its 40% minimum reduction and latency/backlog bounds; this does not establish real WAN performance or close #22151. No rendered UI, native Windows/Linux, physical devices, or live SSH acceptance was run.

AI Disclosure

Implemented and tested with OpenAI Codex.

Review

Readiness audit follow-up: reproduced the two failing existing socket-auth assertions and updated their exact expected capability lists for the new default. Added an authenticated WebSocket dispatch-boundary test covering negotiated runtime compression, legacy runtime replies, and unchanged mobile replies. The client, dispatch-boundary and encrypted integration suites pass 31 tests across 3 files. Node typecheck and changed-code quality were rerun for this change.

Self-reviewed the authenticated capability boundary, exact reconstruction, private-text separation, malformed input bounds, and mixed-version fallback. Coordinator reviewed the design and confidentiality mitigation.

Agent skill upstream boundary

  • Not applicable; no upstream skill source, fixtures or registry content copied.

Notes

No OS-specific behavior, new native dependencies, local execution fallback, or Git-worktree assumption. Ordinary traffic size and public structural-state changes remain observable; this is not padded traffic-analysis protection. Free-text-heavy/oversized snapshots, terminal replay, unrelated streams and incompressible traffic can still saturate a link; this PR adds no universal latency guarantee or priority scheduler.

Rollback by disabling subscription capability advertisement (snapshotCompression: false) or returning legacy replies from the host wrapper. No persisted state or migration is involved; reconnect needs no prior dictionary. Keep the decoder during a staged rollback while capable hosts may still send negotiated replies.

Checklist

  • This PR is focused on remote inventory bandwidth
  • Explained user-facing before/after, mechanism and alternatives
  • Visual proof marked N/A with reason
  • Self-reviewed correctness, security and performance
  • Cross-platform, SSH, folder workspace and mixed-version impact considered
  • Relevant tests, Node/CLI typechecks and changed-code quality pass; full lint/build/suite left to CI

Loading
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

9 participants