Repository navigation
perf(terminal): send hidden sidecar bytes past the view so throttled renderers can't pace agents - #27033
perf(terminal): send hidden sidecar bytes past the view so throttled renderers can't pace agents#27033outof-place wants to merge 1 commit into
Conversation
…renderers can't pace agents A hidden pane whose PTY a raw-byte sidecar watches (background-launched and automation agents) kept the hidden-delivery gate off for the whole PTY, so its hidden xterm parsed every byte and main paced the producer to that parse. The parse runs on renderer timers, which Chromium throttles for hidden pages (one wake-up a minute after ~5 minutes), so a flooding agent slowed to tens of KB/s and blocked on its own writes. Delivery interest now only decides who receives the bytes, not whether the view is gated. For a hidden PTY with interest, main sends chunks flagged sidecarOnly. The renderer hands them to sidecars only and credits them on receipt. The view skips them like a gated drop and restores from the model on reveal, and main answers the PTY's terminal queries meanwhile. Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
Warning Review limit reachedYou've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository. Next included review available in 1 minute. View limit detailsLimit details: You’ve used all 10 included reviews currently available. Review configuration: ⚙️ Run configuration
📒 Files selected for processing (14)
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 |
|
Closing as not planned after reproducing behavior regressions. Revealing a pane configured for 50,000 history rows can replace 8,001 saved rows with roughly 5,024 main-model rows; a throwing sidecar also leaves credit unreturned, and the new early return bypasses speculative-shutdown buffering. The hidden-agent bottleneck is real, but this routing/snapshot rewrite does not preserve terminal history, flow control, and shutdown behavior. |
ELI5
When an agent runs in a hidden tab or window and Orca is watching its output in the background, Orca made the agent wait until the hidden terminal had drawn every line. A hidden window is only allowed to wake up about once a minute, so a chatty agent crawled. Now the watchers still get every byte immediately, the hidden terminal skips drawing, and it catches up when you look at it again.
What Changed
Before:
After: these agents run at full speed while hidden. When the pane is revealed it shows the complete output, repainted from the main-owned terminal model.
Mechanism. Delivery interest exists so raw-byte sidecars (automation observers, background-launch status, paste-draft readiness) keep receiving a hidden PTY's bytes. Until now it also turned the hidden-delivery gate off for the view. Now interest only decides who receives the bytes; the view stays gated:
sendPtyDataToRenderer): for a hidden PTY with interest, it flags the chunksidecarOnlyand records the same "dropped while hidden" latch a gated drop records. That emits the existinghidden-droprestore marker once per hidden period.shouldModelAnswerHiddenPtyQueries): the query responder now answers whenever the view is gated, interest or not. The rule "main answers iff the view didn't get the chunk" still holds.pty-dispatcher.ts): asidecarOnlychunk goes to sidecars only, never to the pane's handler or eager buffer, and is credited on receipt. Main's existing in-flight window (512 KB per PTY) still bounds what is outstanding, so memory stays bounded.unhiderestore repaints the view from the model. Bytes queued while visible but sent after hiding are skipped exactly as the gate's existing pending drop skips them. Bytes queued while hidden but sent after reveal are dropped by the existing post-restore sequence reconciliation.terminalHiddenDeliveryGateorterminalMainSideEffectAuthorityoff, nothing here runs.Why
The slowdown came from tying producer credit to a hidden view's parse. That parse is the one part of the pipeline Chromium throttles, and it is wasted work for a pane that restores from the model on reveal anyway. Alternatives considered:
setBackgroundThrottling(false)). It affects the whole window, including browser guests, and doesn't help occluded windows on macOS.Trade-offs
Measured on macOS (M4 Max) at load average ~400 from parallel builds, so absolute CPU times are inflated; the ratios are what matter. The renderer numbers use
@xterm/headlessand@xterm/addon-serializeas a stand-in for the hidden view's parse and the reveal restore.Merge risk: low to medium.
payload.ts,pty-hidden-delivery-gate.ts,terminal-model-query-authority.ts) and one branch in the renderer dispatcher (pty-dispatcher.ts,pty-sidecar-only-delivery.ts). The wire change is an optional payload field (sidecarOnly). Only hidden PTYs that hold delivery interest change behavior.terminalHiddenDeliveryGate(andterminalMainSideEffectAuthority) off disables the gate, and with it the sidecar-only path.User-facing costs, both ways:
So renderer CPU moves from "per byte while hidden" to "once per reveal". For a pane that prints less than about 6 MB while hidden, total renderer CPU is higher after this change, and the reveal pays the restore (tens of milliseconds) once. That is the same cost every hidden PTY without a sidecar already pays today.
Maintenance cost: one new concept (the
sidecarOnlydelivery flag, a variant of the existing hidden drop) and one renderer branch. +89/−29 production lines and +258/−24 test lines.Verdict: substantial because background and automation agents no longer slow to Chromium's throttled-timer speed (a 46× faster producer in the 60 s-clamp case). It is not free: reveals of those panes pay one restore, and quiet hidden panes can spend slightly more renderer CPU in total.
Linked Issue
Fixes #27032
Visual Proof
N/A: no visual change. A revealed pane shows the same output as before; only the agent's speed while hidden changes. The e2e below asserts the revealed content.
Testing
Headless (
ORCA_BACKGROUND_LAUNCH=1) on macOS, M4 Max under load. Anodeproducer floods the active pane's PTY with 2 MB. The page is pinned hidden as interminal-stuck-occlusion-recovery.spec.ts, delivery interest is registered, and renderer timers are clamped:After the flood, the revealed pane shows the producer's final line, repainted from the model.
New and updated tests:
tests/e2e/terminal-hidden-sidecar-pacing.spec.ts: 60 s clamp, asserts the producer finishes within 20 s (it took ~45 s before) and that the revealed pane shows the output.pty-dispatcher-sidecar-only.test.ts: sidecars get the bytes, the view's handler doesn't, credit on receipt.sidecarOnlypayload plus one restore marker per hidden period.Gates and suites:
pnpm tcORCA_CODE_QUALITY_BASE=upstream/main pnpm run check:code-quality:changedsrc/main/ipc,src/main/runtime,src/renderer/src/components/terminal-pane,src/preload: 22,300 tests pass.run-terminal-shell-alone.node-pty.test.tsfails identically on an unmodifiedmain.worktree-git-common-pollingandfilesystem-quick-open-optionspass when rerun alone.Platforms: tested on macOS. The change is platform-neutral (main delivery and renderer dispatch). SSH PTYs take the same main path; their projection credit settles on the renderer's receipt ack as before. Remote-runtime (web/mobile) terminals use the multiplexed stream and are unaffected; remote view subscribers keep query authority as today.
AI Disclosure
Written with Claude Opus 5.5 (Claude Code), including the measurements; reviewed and run locally.
Review
Agent skill upstream boundary
Notes
Ensure no issues in: Security, Cross-platoform support (Linux, Windows, Mac), Remote SSH, Mobile, general backwards compatibility, performance
Checklist
N/Awith reasonpnpm lint,pnpm typecheck,pnpm test, andpnpm buildpass (or CI will cover; local preferred)🤖 Generated with Claude Code