Repository navigation
fix(terminal): bound parse-deferred remote flow - #10012
Conversation
7862da3 to
6ae5a1c
Compare
|
Note Reviews pausedIt looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the Use the following commands to manage reviews:
Use the checkboxes below for quick actions:
📝 WalkthroughWalkthroughUpdates terminal multiplex flow control with shared limits, adaptive per-stream and aggregate ACK windows, round-robin pending-output draining, transport-failure handling, and stream-slot enforcement. Renderer delivery credits now settle after all scheduler claims complete. Remote terminal multiplexing batches acknowledgements and handles malformed frames, unknown streams, disposal, parser failures, and transport errors. New tests cover these behaviors, alongside parsed-credit simulation and benchmark evidence updates. 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing Touches📝 Generate docstrings
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. Comment |
There was a problem hiding this comment.
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
src/renderer/src/runtime/remote-runtime-terminal-multiplexer.ts (1)
525-541: 🩺 Stability & Availability | 🟡 Minor | ⚡ Quick winGuard non-ack terminal output delivery with the same catch branch.
For
!stream.acknowledgeOutputclients,deliverOutput()directly callsstream.callbacks.onData(...)without atry/catch, while the ack path wraps the same callback infailConnection. UncaughtonDataerrors here should be routed the same way for robustness and unsubscribe handling.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro
Run ID: bd5f011a-f97d-4714-ac02-1323e9863f63
📥 Commits
Reviewing files that changed from the base of the PR and between 01bcc57 and 7862da3c8b5abb3c8474ea9e234699802c027b76.
📒 Files selected for processing (16)
config/reliability-gates.jsoncsrc/main/runtime/rpc/methods/terminal.tssrc/main/runtime/rpc/terminal-multiplex-flow-control.bench.test.tssrc/main/runtime/rpc/terminal-multiplex-round-robin.test.tssrc/main/runtime/rpc/terminal-multiplex-round-robin.tssrc/main/runtime/rpc/terminal-multiplex.test.tssrc/renderer/src/components/terminal-pane/pty-connection.test.tssrc/renderer/src/components/terminal-pane/pty-connection.tssrc/renderer/src/components/terminal-pane/terminal-pty-ack-gate.test.tssrc/renderer/src/components/terminal-pane/terminal-pty-ack-gate.tssrc/renderer/src/lib/pane-manager/terminal-delivery-credit.test.tssrc/renderer/src/lib/pane-manager/terminal-delivery-credit.tssrc/renderer/src/runtime/remote-runtime-terminal-multiplexer.tssrc/renderer/src/runtime/remote-runtime-terminal-parse-backpressure.test.tssrc/renderer/src/runtime/runtime-terminal-stream.test.tssrc/shared/terminal-multiplex-flow-control.ts
💤 Files with no reviewable changes (1)
- src/renderer/src/components/terminal-pane/terminal-pty-ack-gate.ts
ede6096 to
5042ce7
Compare
|
@coderabbitai review |
✅ Action performedReview finished.
|
5042ce7 to
a6978be
Compare
|
@coderabbitai review |
✅ Action performedReview finished.
|
a6978be to
dd58794
Compare
|
@coderabbitai review |
✅ Action performedReview finished.
|
There was a problem hiding this comment.
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
src/renderer/src/runtime/remote-runtime-terminal-multiplexer.ts (1)
575-591: 🩺 Stability & Availability | 🟠 Major | ⚡ Quick winUnhandled exception path for non-desktop (
acknowledgeOutput === false) streams.When
stream.acknowledgeOutputistrue,deliverOutput()is now wrapped in try/catch and any throw fails the connection gracefully. The sibling branch for!stream.acknowledgeOutput(mobile clients, sinceacknowledgeOutput: args.client.type === 'desktop'at line 254) callsdeliverOutput()unguarded — ifstream.callbacks.onDatathrows, the exception escapeshandleBinaryentirely, up through theonBinarycallback passed towindow.api.runtimeEnvironments.subscribe(...), with no cleanup (nofailConnection, no unsubscribe, noonError). This leaves the connection/stream state inconsistent for mobile clients specifically, and is untested (all provided tests useclient: { type: 'desktop' }).🐛 Proposed fix to align both branches
if (!stream.acknowledgeOutput) { - deliverOutput() + try { + deliverOutput() + } catch (error) { + this.failConnection( + error instanceof Error ? error : new Error('Remote terminal output delivery failed.') + ) + } return }
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro Plus
Run ID: 7008a335-529c-42af-b703-43a7e6ab4474
📒 Files selected for processing (16)
config/reliability-gates.jsoncsrc/main/runtime/rpc/methods/terminal.tssrc/main/runtime/rpc/terminal-multiplex-flow-control.bench.test.tssrc/main/runtime/rpc/terminal-multiplex-round-robin.test.tssrc/main/runtime/rpc/terminal-multiplex-round-robin.tssrc/main/runtime/rpc/terminal-multiplex.test.tssrc/renderer/src/components/terminal-pane/pty-connection.test.tssrc/renderer/src/components/terminal-pane/pty-connection.tssrc/renderer/src/components/terminal-pane/terminal-pty-ack-gate.test.tssrc/renderer/src/components/terminal-pane/terminal-pty-ack-gate.tssrc/renderer/src/lib/pane-manager/terminal-delivery-credit.test.tssrc/renderer/src/lib/pane-manager/terminal-delivery-credit.tssrc/renderer/src/runtime/remote-runtime-terminal-multiplexer.tssrc/renderer/src/runtime/remote-runtime-terminal-parse-backpressure.test.tssrc/renderer/src/runtime/runtime-terminal-stream.test.tssrc/shared/terminal-multiplex-flow-control.ts
💤 Files with no reviewable changes (1)
- src/renderer/src/components/terminal-pane/terminal-pty-ack-gate.ts
🚧 Files skipped from review as they are similar to previous changes (13)
- src/shared/terminal-multiplex-flow-control.ts
- src/main/runtime/rpc/terminal-multiplex-round-robin.test.ts
- src/main/runtime/rpc/terminal-multiplex-round-robin.ts
- src/renderer/src/components/terminal-pane/pty-connection.ts
- src/renderer/src/components/terminal-pane/terminal-pty-ack-gate.test.ts
- src/renderer/src/components/terminal-pane/pty-connection.test.ts
- src/renderer/src/lib/pane-manager/terminal-delivery-credit.test.ts
- src/renderer/src/lib/pane-manager/terminal-delivery-credit.ts
- src/main/runtime/rpc/terminal-multiplex-flow-control.bench.test.ts
- src/renderer/src/runtime/runtime-terminal-stream.test.ts
- config/reliability-gates.jsonc
- src/main/runtime/rpc/methods/terminal.ts
- src/main/runtime/rpc/terminal-multiplex.test.ts
Credits remote terminal output only after parse or intentional discard, with bounded adaptive windows, fair draining, recovery cleanup, and RTT/parser benchmarks.
Summary
This is a direct-to-
mainfollow-up to merged #9683 and commitb606117ee. It preserves the parsed-or-intentionally-discarded ACK contract and adds the bounded flow-control, cleanup, fairness, and performance work needed for production remote terminals.Receipt-time ACK is not used.
Deterministic reproduction
Paired renderer replay plus live-output tests hold delivery credit while xterm has not completed parsing, then exercise replay/live ordering, transformed frames, hidden panes, late callbacks, disposal, reconnection, and transport failure. The affected Windows 2 Setup PTY independently reproduced blank/stale replay, hidden queued input, and duplicated fragments while the underlying ConPTY remained writable.
Reliability coverage
Deterministic tests cover replay ordering, stale generations, malformed and transformed frames, queue eviction, hidden panes, pane disposal, recovery serialization failure, repeated same-slot subscribe, renderer delivery failure, ACK transport failure, late parser callbacks, reconnect, stream caps, bounded pending memory, and round-robin fairness.
Benchmark
Opt-in command:
ORCA_TERMINAL_PERF_BENCH=1 pnpm exec vitest run --config config/vitest.config.ts --disableConsoleIntercept src/main/runtime/rpc/terminal-multiplex-flow-control.bench.test.tsCompletion spread was 0 ms and aggregate in-flight memory stayed at or below 8 MiB. On the latest local run, measured
@xterm/headlessthroughput for 1/4/8 viewers was 27.5/75.2/98.3 aggregate MiB/s; parser CPU was 81.4/196.7/324.2 ms; retained heap was 2,878/7,664/39,932 KiB for 4 MiB per viewer. The benchmark also reports protocol frame allocations, scheduler iterations, and xterm writes.Screenshots
No UI change. This is a transport, renderer-delivery, and server scheduling contract.
Testing
497138435: 23 files, 1,750/1,750 tests; fix(terminal): bound parse-deferred remote flow #10012 curated subset 535/535.mainatc445f2654: verify, Linux/mac golden E2E, Wayland, Windows restart, and packaged crash survival all green.mainatc445f2654is clean.AI Review Report
Review compared the implementation with landed #9683, current reconnect/output scheduling, and the newer #10089 resync hardening now on
main. Repeatedinternal-review-until-cleanpasses covered exactly-once credit settlement, fanout, nested delivery, timer/disposal ownership, transport throws, unavailable or failed recovery snapshots, malformed/transformed frames, bounded memory, stream caps, replay trimming, retry/watchdog composition, and fairness. The protocol and renderer paths are platform-neutral; this PR adds no shortcuts or labels, uses no platform-specific path or shell assumptions, and preserves Electron/SSH/native/WSL transport boundaries. Focused tests ran on macOS and Windows, while latest-head CI covers Linux/Wayland and Windows terminal restart/crash survival. The final CodeRabbit pass is clean and all GitHub review threads are resolved.Security Audit
Frame validation remains fail-closed. Malformed framing closes the connection so server-side debt is released; invalid transformed payloads are credited only after intentional discard. Per-stream, aggregate, pending-byte, and stream-count bounds prevent a slow or malicious viewer from creating unbounded memory growth. No receipt-time ACK bypass exists.
Notes
Related remote-runtime recovery and Active Server isolation: #10011. Both PRs target
maindirectly; the split keeps throughput/backpressure risk independent from host/topology migration risk.