Repository navigation
Conversation
…dotgg#39395) Co-authored-by: Julius Marminge <julius0216@outlook.com>
…el (pingdotgg#39415) Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
…elegating (pingdotgg#39413) Co-authored-by: Simone <185146821+Lucenx9@users.noreply.github.com> Co-authored-by: Julius Marminge <julius0216@outlook.com>
…ect loop for good (pingdotgg#39420) Co-authored-by: Julius Marminge <julius0216@outlook.com>
b153d3e to
fa0eb18
Compare
…eporting partial history (pingdotgg#39435)
…ain (pingdotgg#37419) Co-authored-by: Claude Haiku 5.5 <noreply@anthropic.com> Co-authored-by: Julius Marminge <julius0216@outlook.com>
…steners after a defect (pingdotgg#39431)
fa0eb18 to
2174d60
Compare
|
Evidence for the PR description, part 1 of 4. None of this is committed. What the Ghostty source does at the pinI read
In every case the parser stays in the sequence until a terminator. Size never ends it. So libghostty prints none of an oversized string as text. The parser still accepts some strings up to its own caps, such as an OSC 52 or a DCS under 1 MiB. Live output against a replay of the history, 76 streams in the real Ghostty coreThe server half runs the real sanitizer over each stream. The Ghostty half feeds the stream to one core, the web client's wasm, as live output and the server's history to a second core as a replay. It compares the visible rows, the red attribute, the cursor position, the full scrollback text and what the client would send to the program: a paste of
With this PR, 51 streams match and 25 differ as expected. No stream differs unexpectedly.
12 replays send a reply. For 10 of them the Defects that exist on
|
…pingdotgg#39453) Co-authored-by: Cursor <cursoragent@cursor.com>
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
…t and @ (pingdotgg#38323) Co-authored-by: Yash Singh <saiansh2525@gmail.com>
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
…ider versions (pingdotgg#39427) Co-authored-by: Claude Fable 5.2 <noreply@anthropic.com>
…fest (pingdotgg#39434) Co-authored-by: Claude Fable 5.2 <noreply@anthropic.com>
…nd median (pingdotgg#39660) Co-authored-by: Julius Marminge <julius0216@outlook.com>
…efault (pingdotgg#39981) Co-authored-by: Julius Marminge <julius0216@outlook.com>
…only when cut off (pingdotgg#40076)
… app does (pingdotgg#28597) Co-authored-by: maria-rcks <maria@kuuro.net> Co-authored-by: maria-rcks <254055478+maria-rcks@users.noreply.github.com> Co-authored-by: Julius Marminge <julius0216@outlook.com>
Co-authored-by: maria-rcks <maria@kuuro.net> Co-authored-by: Julius Marminge <julius0216@outlook.com>
Co-authored-by: maria-rcks <maria@kuuro.net> Co-authored-by: Julius Marminge <julius0216@outlook.com>
…rogress (pingdotgg#37859) Co-authored-by: Julius Marminge <julius0216@outlook.com>
…dotgg#38895) Co-authored-by: Julius Marminge <julius0216@outlook.com>
…dotgg#30925) Co-authored-by: Julius Marminge <julius0216@outlook.com>
…ingdotgg#39670) Co-authored-by: Julius Marminge <julius0216@outlook.com>
…t page by default (pingdotgg#40003) Co-authored-by: Julius Marminge <julius0216@outlook.com>
…hanges (pingdotgg#24841) Co-authored-by: maria-rcks <maria@kuuro.net> Co-authored-by: Julius Marminge <julius0216@outlook.com>
…tgg#24888) Co-authored-by: Julius Marminge <julius0216@outlook.com>
…s current (pingdotgg#36868) Co-authored-by: Julius Marminge <julius0216@outlook.com>
…checkout (pingdotgg#37191) Co-authored-by: Julius Marminge <julius0216@outlook.com>
… errors (pingdotgg#40042) Co-authored-by: Julius Marminge <julius0216@outlook.com>
…ingdotgg#39994) Co-authored-by: Julius Marminge <julius0216@outlook.com>
Problem
The server saves a cleaned copy of each terminal's output as its history and sends it to a client that attaches. A client draws that history in a replay. While a control sequence is unfinished, the server holds every piece of PTY output until the sequence ends, so it can keep the sequence whole or strip it. Nothing limited the held text. Output arrived seconds late and server memory grew with every piece. When the sequence ended, the server appended it whole and pushed earlier lines out of history. On
mainate37e45fd5bin the web client,seq 1 200000took 11.87 s after an unfinished CSI, against 0.24 s plain. Closes #37.Change
Only
sanitizeTerminalHistoryChunkand its constants change inapps/server/src/terminal/Manager.ts. I exportedsanitizeTerminalHistoryChunkso the new test can call it. This PR adds a limit on held text for each kind of sequence. The limits count UTF-16 code units and apply only when a piece ends inside a sequence. Web and Android draw with Ghostty'slibghostty-vtterminal emulator, pinned to3ff6d08finnative/libghostty-vt/VERSION. The limits below follow what it does.DEFAULT_MAX_TERMINAL_BUFFER_BYTES. Clients keep 512 KiB and drop any sequence their trim cuts through, so none can replay a longer string whole.libghostty-vtdoes not run a CSI with more than 24 parameters. The server also rescans a held CSI from the start on every piece.ESCand four intermediates, bytes0x20to0x2Fbefore the final byte. Past that limit, the server holds the first five code units and drops later intermediates. Ghostty ignores later intermediates atParser.zig:313-321, so five code units replay the same as the whole sequence.Past a string or CSI limit, the server holds only the introducer and drops the rest. The introducer is the two characters that open a string or a CSI, like
ESC ]. The sequence stays unfinished, and history resumes only after its own end arrives. That stops late output and unbounded memory. For a string, it also keeps earlier history intact. For a CSI, history still receives executed controls like line feeds as they arrive, so earlier lines still scroll out just as they do on the live screen.The first drop of a string or a CSI writes one ST,
ESC \, the string terminator, to history. That closes any earlier unfinished sequence, such as a title cut short by the dropped sequence'sESC. In ground state, outside any sequence, ST does nothing. Later pieces of the same sequence write no further ST.The server stays inside an oversized string because Ghostty prints no oversized string as text. Ending it early would replay output the live screen never showed. Between 524,288 code units and Ghostty's own size caps, Ghostty's parser still accepts some strings that history now drops. No client can replay a string longer than 512 KiB whole.
The four evidence comments on this PR, each headed "Evidence for the PR description, part N of 4", hold the evidence behind this description. Two of the strings Ghostty's parser still accepts are an OSC 52 and a DCS under 1 MiB. The first evidence comment explains why those two strings have no effect on the screen in pinned
libghostty-vton web and Android.Costs I accept:
ESC [, 20,000 zeros, and6n, which replay would answer.main, the same replay sends nothing. Web drops replay replies atapps/web/src/terminal/ghostty/core.ts:429. Android forwards them to the program's input atT3TerminalView.kt:398and:459.main. Peak held text drops from 2,097,161 code units onmainto 524,233.Scope
This is a bug fix for #37. The fix solves one problem, the same unlimited hold across all six sequence kinds. It changes only server history parsing and adds one paragraph to
docs/internals/terminal-runtime.md, with no contract, client, provider, or locale changes.Upstream PRs 29604 and 30479 end an unfinished string at the next
ESC. This bug happens when noESCfollows.On 2026-11-20, the upstream project had 2,418 open pull requests, and 21 of them change
apps/server/src/terminal/Manager.ts. I read what each of those 21 pull requests changes in that file, and none limits the held text. Only one of the 21, upstream PR 28840, adds code tosanitizeTerminalHistoryChunkthatmaindoes not already have. In that function, it reads the shell'sOSC 133;Dcommand-finished mark and adds acommandExitCodefield to every return statement. Those return statements include the three this PR replaces, so the later of the two pull requests to land needs a small manual merge in that function and in the lines directly above it. Upstream PR 28840 targets a feature branch and notmain, so that merge comes up only when its branch lands. Eight other open pull requests, each of about 34,800 files, are too large for GitHub to list in full, and I did not check them.Left out:
main.main, and the first evidence comment lists the queries they miss.main, in the first evidence comment.ESCand dropping abandoned escape sequences. That would remove the drop ST and defects 3 and 4 in the first evidence comment.3ff6d08fpin untilnative/libghostty-vt/VERSIONmoves, detailed in the second fold.Verification
Reviewers found this bug during code review of another terminal fix. No user reported it. I reproduced it on purpose in a real shell and the web client.
Test.
stops holding a control sequence that outgrows its limitinManager.test.tsruns nine rows. All 122 tests in the file pass. Onmainwith onlyexportadded, it fails withDCS, split code point: expected 526343 to be less than or equal to 4. The test is larger than the fewest rows that fail onmain, on purpose, so all 61 hand-made mutations of the fix fail it. Every row and check exceptescape endsuniquely catches at least one.Web client.
vp run scenarios:provefails onmainand passes on1662c3c7d6for CSI and OSC, one run each. Each time below measures from the Enter key to the first frame that showsDONEin the web client. The recorded commands printDONEin black on green so the page can detect the frame. The recording scenario in the fourth evidence comment and the timing probes in the third compare elapsed times, so I did not commit them.mainseq 1 200000; printf 'DONE\n'printf '\033['; seq 1 200000; printf 'mDONE\n'seq 1 2000000; printf 'DONE\n'printf '\033]0;stuck'; seq 1 2000000; printf '\007DONE\n'Each video shows
mainon top and this PR below, with a stopwatch that the recording adds.CSI:
unfinished-csi-before-after.mp4
OSC:
unfinished-osc-before-after.mp4
Runtime transcript. On a real
/bin/shPTY with no browser, I timed from writing each command untilDONEreached the manager's listeners.printf '\033['; seq 1 200000; printf 'mDONE\n'fell from 11,528 ms onmainto 178 ms.printf '\033]0;stuck'; seq 1 3000000; printf '\007DONE\n'fell from 51,344 ms onmainto 2,685 ms, against 2,599 ms plain.Replay comparison. I compared 76 test streams as live output against history replays in the web client's Ghostty core. With this PR, 51 match and 25 differ for reasons I expected, with none unexpected. On
main, 19 differ, 1 unexpectedly. The 25 are 8 dropped CSIs Ghostty ran, 3 split surrogate pairs a real PTY never sends, and 14 other streams that differ onmaintoo. The two streams with the new reply are among those 14, and onmainthey differ because the replay swallows the text after the query. Two ofmain's 19 now match, and the 8 dropped CSIs are new.Checks.
vp run check:changedpasses format, lint, knip, graphql, typecheck of 3 packages, and tests of 2 files.Not checked. iOS uses a separate Ghostty fork rather than the
3ff6d08fpin, and I did not read it. I did not test newer Ghostty or run desktop, Android, or iOS. Web timings are one dev-stack run each.Evidence. The first evidence comment has Ghostty notes, replay output, defects on
main, and strip rules. The second has mutations, timings, memory, and real PTY logs. The third has probes and scripts. The fourth has the recording scenario.The whole window when each run ended
mainWhat Ghostty has changed since the pin
The
3ff6d08fpin is a Ghostty commit from 2026-07-07, and Ghostty has since changed two behaviours the server models. Ghostty PR 14016, merged 2026-08-25, makes bytes 0x80 to 0xFF payload inside a DCS, so a code point with a C1 byte no longer ends one. Ghostty PR 14023, merged 2026-08-26, drops U+0080 to U+009F in ground state, where the pin prints them. On Ghosttymainof 2026-11-19, a C1 byte still ends a CSI, a PM or APC string, and a DCS header. The sanitizer and two new test rows,DCS, split code pointandDCS opened by U+0090, match the pin.Code by Claude Fable 5.2 and Claude Opus 5.5 in Claude Code. Description written by Gemini 4 Neon in Antigravity and reviewed by Claude Fable 5.2. Driven from T3 Code.
🤖 Generated with Claude Code