Repository navigation
Keep terminals responsive under agent output load - #7176
brennanb2025 wants to merge 1 commit into
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Repository UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (2)
📝 WalkthroughWalkthroughThis change modifies terminal output drain scheduling behavior. The high-priority drain interval was increased from 1ms to 4ms, the maximum writes per drain reduced from 16 to 2, and a new 8ms time budget (DRAIN_TIME_BUDGET_MS) was introduced. A getDrainNow() helper using performance.now() with a Date.now() fallback tracks elapsed drain time, causing the drain loop to yield once writes have started and the budget is reached. Corresponding test assertions were updated and two new tests added covering budget-triggered yielding and the Date.now fallback path. Changes
Sequence Diagram(s)Not applicable — changes are confined to internal scheduling logic and test assertions without a multi-component interaction flow worth diagramming beyond the internal control flow shown in the review stack. Estimated code review effort: 🎯 3 (Moderate) | ⏱️ ~20 minutes Related PRs: None identified from the provided context. Suggested labels: performance, scheduler, tests Suggested reviewers: Not enough information available to recommend specific reviewers. Poem 🚥 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 |
Summary
Keeps the renderer responsive while agents stream terminal output, by pacing how fast the output scheduler feeds xterm:
HIGH_PRIORITY_MAX_WRITES_PER_DRAIN16 → 2 (at most ~32 KB handed to xterm per drain tick, down from ~256 KB)HIGH_PRIORITY_DRAIN_INTERVAL_MS1 → 4 (matches Chromium's clamped nested-timer floor, cuts timer churn)DRAIN_TIME_BUDGET_MS(8 ms): a drain yields after the current write once the tick's wall-clock budget is spent. This has a real production trigger — after user input, xterm'swrite()parses synchronously inside the call (_didUserInputfast path, up to its 12 ms slice), so a slow first write no longer drags a second synchronous parse into the same tick.Why
Under multi-agent output load the scheduler could feed xterm up to 256 KB/ms. xterm parses on the renderer main thread in ~12 ms slices, so sustained output kept the thread near-100% busy and starved input/paint — the "terminal gets laggy, then the whole app" escalation in #7017's Windows/WSL report. Keystroke echo is unaffected: latency-sensitive foreground writes still bypass the queue.
Might fix #7175 — "Not responding" with >3 parallel sessions on Windows is consistent with this renderer-saturation mechanism, since all sessions share one renderer and output load scales with session count. Note it does not address memory-driven crashes (#7175's crash on 32 GB could also be OOM), nor main-process load from many projects.
Related: #7017
Testing
pane-terminal-output-scheduler.test.ts: 45/45, including two new tests (drain yields when writes spend the frame budget;Date.nowfallback whenperformanceis unavailable)terminal-shutdown-layout-capture,use-terminal-pane-global-effects,use-terminal-scroll-visibility-memory): 31/31typecheck:webcleantest:e2e:terminal-perfrun failed for environmental reasons (harness fixturerepos.addfails before any test body; reproduced identically with main's scheduler files) — relying on CI for the perf gates (typing latency, redraw freeze, output scheduler, artificial OpenCode load)Follow-ups (pre-existing, not addressed here)