Skip to content

perf(server): smooth sustained terminal output - #33324

Closed
StiensWout wants to merge 3 commits into
pingdotgg:mainfrom
StiensWout:t3/terminal-stream-window
Closed

StiensWout wants to merge 3 commits into
pingdotgg:mainfrom
StiensWout:t3/terminal-stream-window

Conversation

@StiensWout

Copy link
Copy Markdown
Contributor

Sustained terminal output could deliver an RPC chunk for each PTY callback, making frame delivery uneven. A fixed 2 ms leading-edge window now batches adjacent output events while preserving their bytes and sequence. Idle output is immediate; lifecycle events and a full 64 KiB batch flush early. The ACK window, bounded queue and resync behavior are unchanged.

Five alternating equal-work production-build pairs on one clean VM support smoother frames with no demonstrated change in renderer CPU. During comparable active-load intervals, the median paired reduction in mean frame interval was 25.9%, long-frame share fell 54.6%, and render submissions per second rose 36.2% (higher in all five pairs). These are animation-frame/canvas observations, not compositor presentations.

Five matched terminal workload pairs: smoother frames, no reliable CPU change

Each arm completed the same 29,360,128-byte ANSI payload, offered at 4 MiB/s, on a 212×44 terminal. Main payload hashes matched, full streams matched their own producers, sequences stayed ordered, all 26 sustained echoes painted, queues drained to zero, and no resync occurred. Actual completion was about 2 MiB/s. Marker and echo overhead were accounted separately. Frame windows use the shorter active interval in each pair; CPU covers the whole equal-work sample. Repeated-run variation is shown in the graph. Full comparison and method.

The observed benefit is smoother output with no demonstrated CPU change; these samples do not establish CPU equivalence. Renderer CPU changed +0.7% (middle half −4.9% to +8.6%); page TaskDuration changed −7.3% with variation spanning zero. There is no CPU-saving claim. The original approximately 20% message-family CPU/wall acceptance criterion was not met: one separate attribution pair measured family thread CPU 1,509→1,524 ms and wall 2,598→2,787 ms, including nested terminal writes. Fewer socket tasks alone are not a speedup. Traced responsiveness is not pooled with the lean headline runs. Echo p50 improved, but echo p95 was inconsistent.

Four measured pairs have complete idle echoes. The original fifth baseline idle marker was not captured, so its idle percentile remains missing. A separate bounded 212×44 functional check recorded all 26 real key reads, emits, decoded payloads and canvas draws on both versions; it does not replace the missing measured sample or establish decode-to-paint timing.

Measured sources were base b07fdeb and candidate 740c395995cd. Rebases onto main 4c8eb1d preserved the measured patches by range-diff. The final rebase also preserved the clock fix exactly; final head is 6677da5. Final review changed the deadline clock to Effect monotonic time: both APIs use the same high-resolution monotonic source under stable wall time, and the fix removes wall-clock reanchoring without changing the 2 ms interval or timer machinery. A backward-clock test failed before that fix and passes now. The graph is captured evidence for the measured candidate, not a new benchmark of the final SHA.

Validation: focused OutputProtocol/Manager tests (94) and RpcAuthorization tests (20), primary integrated test-t3-app pass with ANSI/Unicode output and terminal hide/show, and check:changed. Standard pipeline because the change adds deadline/lifecycle state. No Manager production change or protocol/schema change. The shared server stream applies to web, Electron, native mobile and remote connections; hardware-GPU, Electron-shell, native-mobile, many-stream concurrency and remote/relay/tunnel performance were not measured. Heap endpoints were captured; peak resident memory and long-duration leak behavior were not measured. Compact frame/echo records, producer receipts and metric endpoints are retained; full wire captures are absent, so collection-time receiver hashes cannot be rehashed offline. Linux Chromium 141 used SwiftShader.

Council review

Two code rounds, followed by one same-head scope clarification. Final scores are 9/10 from all three reviewers on 0cbc070ac6. Final head 6677da5 rebases those same three patches without changes onto main 4c8eb1d; only an unrelated orchestration fix advanced upstream. The clock fix resolved the initial code finding. Grok retained an 8 while counting the failed original CPU target against shipping, then explicitly corrected that inconsistency under the revised frame-smoothing scope; the code and measurements did not change.

Delegate Code round 1 Code round 2 Scope clarification
GPT 6.1 Sol No score; cancelled on superseded head 9/10 —
Claude Opus 5.5 8/10 9/10 —
Grok 4.7 8/10 8/10 9/10

Fresh final-head cubic review: no issues. Its earlier Manager-test clock warning was rejected: the suite explicitly sets excludeTestServices, and the exact flagged test passes. No design-lens follow-ups. Final proof audit accepts with disclosed limits and no additional gap-fill required. Red/green evidence reobserved all five new stream cases against the old protocol and the clock correction against the wall-clock variant; restored head passes.

Created with Claude Opus 5.5 (builder and trimmer), GPT 6.1 Sol (lead, fixes, review and proof audit), and Grok 4.7 (evidence and review) in T3 Code using the Codex, Claude Agent and Grok harnesses.

StiensWout and others added 3 commits November 9, 2026 12:21
Sustained terminal output reached clients as one RPC chunk per PTY callback,
so clients spent their frame budget processing messages. terminalOutputStream
now emits the first output and output after idle immediately, and holds output
that follows an emission until a fixed 2 ms deadline that arrivals never move.
A pending lifecycle event, snapshot or full 64 KiB batch flushes early. Events
stay unmerged and in order; the ACK window, 8 MiB queue and resync are
unchanged, and every wait restarts the pull so overflow is rechecked.

Candidate for paired production measurement, not yet a shipping claim.

Co-authored-by: GPT 6.1 Sol <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Co-authored-by: GPT 6.1 Sol <[email protected]>
Co-authored-by: Claude Opus 5.5 <[email protected]>
Co-authored-by: Grok 4.7 <[email protected]>
Use Effect monotonic time for the fixed 2 ms deadline. Extend the existing public stream test with a backward wall-clock correction; it fails before this change and passes with the original deadline afterwards.

Co-authored-by: GPT 6.1 Sol <[email protected]>
Co-authored-by: Claude Opus 5.5 <[email protected]>
Co-authored-by: Grok 4.7 <[email protected]>
@github-actions github-actions Bot added vouch:trusted Author is trusted by repo permissions or the VOUCHED list. size:S 10-29 changed lines (additions + deletions). labels Nov 9, 2026
@macroscopeapp

macroscopeapp Bot commented Nov 9, 2026

Copy link
Copy Markdown
Contributor

Approvability

Verdict: Approved at 6677da5

Macroscope's review found this PR approvable — Terminal output is batched within a 2 ms window to smooth sustained delivery, while lifecycle events and full batches flush immediately. Existing queue limits and resynchronization remain intact, limiting the change to output-delivery timing.

You can add or adjust custom eligibility rules. Learn more.

@coderabbitai

coderabbitai Bot commented Nov 9, 2026

Copy link
Copy Markdown
Contributor

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

terminalOutputStream now batches non-urgent output for up to 2 ms. Lifecycle events and full pending-byte batches trigger early delivery. Tests cover deadline behavior, ordered flushing, overflow resynchronization, listener cleanup, and full-batch delivery.

Changes: Terminal output batching

Layer / File(s) Summary
Timed batching and flush conditions
apps/server/src/terminal/OutputProtocol.ts, apps/server/src/terminal/OutputProtocol.test.ts
terminalOutputStream tracks a monotonic deadline and waits to collect non-urgent output. Lifecycle events and full batches flush early. Tests cover timing, ordering, overflow, interruption, ACK-stall behavior, and batch-size limits.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Change: Other

Sequence Diagram(s)

sequenceDiagram
  participant Publisher
  participant terminalOutputStream
  participant Clock
  participant Subscriber
  Publisher->>terminalOutputStream: Publish output event
  terminalOutputStream->>Clock: Check remaining batch deadline
  terminalOutputStream-->>Subscriber: Emit when deadline expires or output is urgent
Loading

Suggested labels: size:M

Suggested reviewers: bil0000, juliusmarminge, t3dotgg

Merge Risk: Minimal · up to 6677d

No concrete merge-blocking issue was identified in the terminal output batching change.

Pre-merge checks: Passed 4

Check name Status Explanation
Title check Passed The title "perf(server): smooth sustained terminal output" matches the main change: a fixed 2 ms leading-edge window that batches adjacent terminal output events in the server output stream (OutputPro…
Description check Passed The description follows the template's main sections: Problem, Change, Scope and approval, and Verification. It explains the problem (sustained output delivering one RPC chunk per PTY callback) and th…
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Full details: Title check

Explanation

The title "perf(server): smooth sustained terminal output" matches the main change: a fixed 2 ms leading-edge window that batches adjacent terminal output events in the server output stream (OutputProtocol.ts), aimed at smoother frame delivery. It is a conventional commit title in plain language and names the affected component. It does not cover the monotonic clock change or the test additions, which is expected for a title.

Full details: Description check

Explanation

The description follows the template's main sections: Problem, Change, Scope and approval, and Verification. It explains the problem (sustained output delivering one RPC chunk per PTY callback) and the change (a fixed 2 ms batching window with early flush for idle, lifecycle, and 64 KiB cases). Verification is detailed, with test counts, measured results, and stated limits. Gaps: the Problem section has no explicit expected behavior or reproduction steps beyond a brief statement. The Scope and approval section does not link a triaged issue or maintainer approval, and it does not say why the change qualifies without one. The description also has no explicit statement that it was created with an agent, though the footer names the models and harnesses used. Because the description is mostly complete, the check passes, but the author should add the linked issue or approval reference to the Scope and approval section.

Finishing Touches

Generate unit tests (beta)

  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts
Recent review info

Run configuration

Commits

Reviewing files that changed from the base of the PR and between 4c8eb1d and 6677da5.

Files selected for processing: 2

  • apps/server/src/terminal/OutputProtocol.test.ts
  • apps/server/src/terminal/OutputProtocol.ts

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 8 remain after this review.

@maria-rcks

maria-rcks commented Nov 10, 2026 •

Copy link
Copy Markdown
Collaborator

Note

Written by gpt-6.1-sol on behalf of Maria

Verified in a real dev environment

verified unchanged head 6677da56e21a0bee3483bacc8953266aae093c29 against github/main at e89abadaee on a disposable linux vm. ran one background dev server at a time. drove the actual web app using the repo's playwright and /usr/bin/google-chrome, created projects/threads through the app, and completed real codex gpt-6.1-sol turns on both versions.

ran the same 6,000-line ansi/unicode producer through the terminal input on both heads and reconstructed the received terminal.attach websocket output. both delivered all 1,512,000 normalized payload bytes exactly, with ordered sequences and matching producer/receiver sha-256 335b5b90781df1a54bb3c4f8dd4fcba9e2fc26132a3514fbcf21e807b64b69a3.

main delivered 4,220 output events in 3,664 rpc chunks, with 3,326 single-event chunks. the pr delivered 5,367 output events in 2,311 chunks, with 392 single-event chunks. pty callback counts vary between runs; this verifies batching and integrity, not a frame-rate or cpu improvement.

also exercised hide/show while output continued, idle input after draining, final output immediately before exit, and reopening the terminal. the final tail arrived before exited and closed, with exit code 0. reopening returned REOPEN_OK.

vp test run apps/server/src/terminal/OutputProtocol.test.ts apps/server/src/terminal/Manager.test.ts passed all 94 existing tests through blacksmith. existing head ci had 31 successful checks and no failing or pending checks when inspected. no source changes were needed.

before, main:

main terminal after the matching 6000-line workload

after, exact pr head:

pr terminal after the matching workload and identical producer hash

pr streaming, hide/show, idle input and terminal exit

short runtime and check transcript. inspected the captures and checked uploaded video playback and seeking.

Not verified

native mobile and electron shells, macos/windows, remote/relay/tunnel connections, hardware-gpu behavior, frame/cpu performance claims, long-running memory behavior, and live slow-client overflow. queue/overflow behavior was covered by the existing focused tests. the vm transmitted emoji bytes exactly, but its terminal font displayed a fallback glyph on both versions.

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

Labels

size:S 10-29 changed lines (additions + deletions). vouch:trusted Author is trusted by repo permissions or the VOUCHED list.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants