perf(client): stop replaying terminal buffers on rollover - #242
perf(client): stop replaying terminal buffers on rollover#242leoisadev1 wants to merge 1 commit into
Conversation
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.
|
The latest updates on your projects. Learn more about Vercel for GitHub. 1 Skipped Deployment
|
Greptile SummarySummary
Merge safetyNot safe to merge until terminal rollover forces the web viewport to replace its displayed contents with the retained output. Confidence Score: 4/5A 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
What T-Rex did
Reviews (1): Last reviewed commit: "perf(client): stop replaying terminal bu..." | Re-trigger Greptile |
| if ( | ||
| cursor.generation !== output.generation || | ||
| cursor.resetVersion !== output.resetVersion || | ||
| cursor.offset < (firstChunk?.startOffset ?? output.nextOffset) | ||
| ) { | ||
| return { type: "reset", data: terminalOutputText(output), cursor: nextCursor }; |
There was a problem hiding this comment.
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.
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
lifecycleVersionon the buffer state yet; snapshot and restart still reset output throughresetOutput. 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 linton 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.