Skip to content

perf(terminal): send hidden sidecar bytes past the view so throttled renderers can't pace agents - #27033

Closed
outof-place wants to merge 1 commit into
stablyai:mainfrom
outof-place:perf/pty-background-ack
Closed

outof-place wants to merge 1 commit into
stablyai:mainfrom
outof-place:perf/pty-background-ack

Conversation

@outof-place

@outof-place outof-place commented Oct 9, 2026 •

Copy link
Copy Markdown
Contributor

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:

  • Background-launched agents, and agents an automation observes, slowed to the hidden renderer's timer speed while their pane was hidden.
  • That was 47 KB/s under Chromium's intensive hidden-page throttling, against 2.8 MB/s when visible. A build or test log took minutes and blocked the agent on its own writes.

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:

  • Main (sendPtyDataToRenderer): for a hidden PTY with interest, it flags the chunk sidecarOnly and records the same "dropped while hidden" latch a gated drop records. That emits the existing hidden-drop restore marker once per hidden period.
  • Main (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.
  • Renderer (pty-dispatcher.ts): a sidecarOnly chunk 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.
  • Reveal: the existing unhide restore 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.
  • Kill switches are unchanged: with terminalHiddenDeliveryGate or terminalMainSideEffectAuthority off, 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:

  • Credit hidden chunks on receipt but keep parsing them in the hidden xterm. The xterm's bounded background queue would overflow and discard backlog under any sustained flood. Terminal queries in the discarded bytes would go unanswered, because main only answers for gated chunks.
  • Main credits hidden chunks itself and stops sending when the renderer falls behind. Sidecars would lose bytes, and they need every one: automation completion is read from OSC sequences in the stream.
  • Disable background throttling (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/headless and @xterm/addon-serialize as a stand-in for the hidden view's parse and the reveal restore.

Merge risk: low to medium.

  • Scope: main delivery (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.
  • Kill switch: terminalHiddenDeliveryGate (and terminalMainSideEffectAuthority) off disables the gate, and with it the sidecar-only path.
  • Tests: the e2e and unit tests listed under Testing.

User-facing costs, both ways:

before after
Agent output while its pane is hidden and timers are throttled (2 MB) 44.5 s (47 KB/s) 0.96 s
Renderer CPU while hidden parses every byte: 23.7 ms per 2 MB none
Reveal none extra one restore from main's model: 72.9 ms CPU (serialize + replay) for a 10,000-row scrollback (a 0.58 M-char snapshot), whatever the amount of output
Memory while hidden up to 512 KB in flight + 256 KB queued in main, with the PTY paused sidecar-only bytes are credited on receipt, so neither backlog builds up
Memory at reveal none extra the snapshot string, about 1.2 MB in main and again in the renderer, freed after the replay
Main CPU unchanged: main's model parses every byte either way unchanged
IPC the same bytes the same bytes

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 sidecarOnly delivery 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. A node producer floods the active pane's PTY with 2 MB. The page is pinned hidden as in terminal-stuck-occlusion-recovery.spec.ts, delivery interest is registered, and renderer timers are clamped:

before after
visible 0.75 s 0.89 s
hidden + interest, timers ≥ 1 s 3.5 s (606 KB/s) 0.70 s
hidden + interest, timers ≥ 60 s 44.5 s (47 KB/s) 0.96 s

After the flood, the revealed pane shows the producer's final line, repainted from the model.

New and updated tests:

  • New e2e 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.
  • New pty-dispatcher-sidecar-only.test.ts: sidecars get the bytes, the view's handler doesn't, credit on receipt.
  • New gate predicate test.
  • Updated IPC gate tests: a sidecarOnly payload plus one restore marker per hidden period.
  • Updated query-authority and responder tests: main answers DA1/OSC 11 for hidden PTYs with interest. Previously it yielded to the hidden xterm.

Gates and suites:

  • pnpm tc
  • ORCA_CODE_QUALITY_BASE=upstream/main pnpm run check:code-quality:changed
  • src/main/ipc, src/main/runtime, src/renderer/src/components/terminal-pane, src/preload: 22,300 tests pass.
  • Three timing-sensitive files fail under load:
    • run-terminal-shell-alone.node-pty.test.ts fails identically on an unmodified main.
    • worktree-git-common-polling and filesystem-quick-open-options pass 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.

  • I manually tested these changes locally (not done: verified through the headless e2e and suites above, no interactive session)
  • Automated tests added/updated, or explained why not below

AI Disclosure

Written with Claude Opus 5.5 (Claude Code), including the measurements; reviewed and run locally.

Review

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

Ensure no issues in: Security, Cross-platoform support (Linux, Windows, Mac), Remote SSH, Mobile, general backwards compatibility, performance

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)

🤖 Generated with Claude Code

…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]>
@coderabbitai

coderabbitai Bot commented Oct 9, 2026

Copy link
Copy Markdown
Contributor

Warning

Review limit reached

You'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.

Check out review usage here.

View limit details

Limit details: You’ve used all 10 included reviews currently available.

Learn how review limits work.

Review configuration:

⚙️ Run configuration
  • Configuration used: Repository UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: afb213be-2653-4aef-8ac0-df92274ad389

📥 Commits

Reviewing files that changed from the base of the PR and between 9d94a20 and ec99e24.


📒 Files selected for processing (14)
  • src/main/ipc/pty-hidden-delivery-gate.test.ts
  • src/main/ipc/pty-hidden-delivery-gate.ts
  • src/main/ipc/pty-ipc-hidden-delivery-gate.test.ts
  • src/main/ipc/pty/delivery/payload.ts
  • src/main/ipc/pty/session.ts
  • src/main/runtime/terminal-model-query-authority.test.ts
  • src/main/runtime/terminal-model-query-authority.ts
  • src/main/runtime/terminal-query-responder.test.ts
  • src/preload/api/pty-api.ts
  • src/preload/api/pty-bridge-stream-and-serialization.ts
  • src/renderer/src/components/terminal-pane/pty-dispatcher-sidecar-only.test.ts
  • src/renderer/src/components/terminal-pane/pty-dispatcher.ts
  • src/renderer/src/components/terminal-pane/pty-sidecar-only-delivery.ts
  • tests/e2e/terminal-hidden-sidecar-pacing.spec.ts


  • 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

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.

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.

Background and automation agents slow to renderer timer speed while their pane is hidden

2 participants