Skip to content

perf(client): stop replaying terminal buffers on rollover - #242

Open
leoisadev1 wants to merge 1 commit into
mainfrom
perf/client-terminal-incremental
Open

perf(client): stop replaying terminal buffers on rollover#242
leoisadev1 wants to merge 1 commit into
mainfrom
perf/client-terminal-incremental

Conversation

@leoisadev1

Copy link
Copy Markdown
Member

Problem

Terminal attach state stored one growing string and re-trimmed it on every output event. Clients then replayed the whole buffer into Ghostty or the native surface, which spikes on long sessions.

Changes

Keep attach output as incremental UTF-8 chunks with a 512KiB retained bound and a cursor. Renderers append unread data or reset only when the retained tail moved. Each new attach stream gets a new generation so a stale cursor cannot append into the next session.

Mobile still materializes a string at the native surface boundary, because the installed native view still takes initialBuffer.

Adapted from pingdotgg#9707. Akeru has no lifecycleVersion on the buffer state yet; snapshot and restart still reset output through resetOutput. Ghostty WASM snapshot tests from that PR were left out: this Vitest setup cannot load *.wasm?inline.

Scope

This PR is client attach-output incrementalization.

Covered here:

Still assigned to this handoff, in later PRs:

Verification

  • vp test run packages/client-runtime/src/state/terminalSession.test.ts apps/web/src/terminal/ghostty/core.test.ts apps/mobile/src/features/terminal/terminalMenu.test.ts apps/web/src/components/ThreadTerminalDrawer.test.ts: 39 passed.
  • vp lint on the six changed files: clean.

Native mobile terminal was not run on this Linux host.

Implemented and verified by Grok 4.6 High in Grok Build via Orca.

Keep terminal attach output as incremental chunks with a 512KiB bound
and a cursor so renderers append instead of rewriting the whole buffer
on every event. Mobile still materializes a string at the native
surface boundary.
@vercel

vercel Bot commented Sep 10, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

1 Skipped Deployment
Project Deployment Actions Updated
akeru-bot-landing Skipped Skipped Sep 10, 2026 6:17pm UTC

Request Review

@github-actions github-actions Bot added vouch:trusted PR author is trusted by repo permissions or the VOUCHED list. size:L labels Sep 10, 2026
@greptile-apps

greptile-apps Bot commented Sep 10, 2026

Copy link
Copy Markdown

Greptile Summary

Summary

  • The new incremental terminal-output path can leave rolled-off terminal text visible after the bounded history buffer discards its prefix.

Merge safety

Not safe to merge until terminal rollover forces the web viewport to replace its displayed contents with the retained output.

Confidence Score: 4/5

A reproduced terminal rendering defect must be fixed before merging.

The rollover behavior was exercised through terminal state reduction and the web viewport writer, and it retained discarded output in the rendered surface.

Files Needing Attention: packages/client-runtime/src/state/terminalOutput.ts

T-Rex T-Rex Logs

What T-Rex did

  • Generated a finding-comment-proof for a posted P1 finding.
  • Collected and linked the terminal rollover artifacts, including the test source and execution logs, to support review.
  • Validated the terminal-rollover-render end-to-end test using the specified command, noting the rollover result and that the attach-generation path passed.
  • Persisted evidence artifacts for the validation, including the test file and confirmatory logs.

View all artifacts

T-Rex Ran code and verified through T-Rex

Fix all with Greploop Fix All in Claude Code

Reviews (1): Last reviewed commit: "perf(client): stop replaying terminal bu..." | Re-trigger Greptile

Comment on lines +297 to +302
if (
cursor.generation !== output.generation ||
cursor.resetVersion !== output.resetVersion ||
cursor.offset < (firstChunk?.startOffset ?? output.nextOffset)
) {
return { type: "reset", data: terminalOutputText(output), cursor: nextCursor };

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Reset after output rollover

When retained terminal history drops its prefix, a viewport cursor can still be at or beyond the new first chunk offset. The changed code returns an append update even though the displayed terminal still contains discarded text. With a four-byte buffer, output retained as fXYZ was appended to a viewport displaying cdef, leaving cdefXYZ rather than replacing it with fXYZ. Users can see stale terminal output after the buffer rolls over.

Artifacts

Terminal rollover rendering test

  • Focused test source that drives terminal state updates through the web terminal writer and asserts the rendered output.

Terminal rollover execution output

  • Test output showing retained `fXYZ`, rendered `cdefXYZ`, and the failed equality assertion.

Terminal rendering-path capture

  • Captured rendering-path evidence accompanying the focused rollover check.

View artifacts

T-Rex Ran code and verified through T-Rex

Fix in Claude Code

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

Labels

size:L vouch:trusted PR author is trusted by repo permissions or the VOUCHED list.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant