Skip to content

feat: reach all terminal history and page thread search instead of capping it - #6

Merged
greaber merged 5 commits into
grant/mainfrom
grant/scrollback-search
Nov 12, 2026
Merged

greaber merged 5 commits into
grant/mainfrom
grant/scrollback-search

Conversation

@greaber

@greaber greaber commented Nov 11, 2026

Copy link
Copy Markdown
Owner

Terminal scrollback kept 5,000 lines / 8 MiB per terminal and showed clients at most 512 KiB; thread search returned the newest 2,000 hits and scanned only the newest 20,000 messages without the index. Older output and older matches were silently unreachable.

Terminal history

  • On disk per terminal: 1,000,000 lines / 256 MiB (T3CODE_TERMINAL_HISTORY_MAX_LINES, T3CODE_TERMINAL_HISTORY_MAX_BYTES). Persistence appends; rewrites go to a temp file, fsync, rename. Old history files load unchanged; loading streams the file and keeps only the newest part decoded.
  • Memory: newest 16 MiB per terminal, 512 MiB across terminals (older parts stay readable from disk), exited sessions 256 MiB total.
  • terminal.history RPC pages before/after any byte offset. Clients keep a ~4 MiB / 25,000-line sliding window: scrolling to the top loads older output (dropping the newest), scrolling down loads newer, live output waits aside and resumes on "Jump to latest". Web keeps the reading position; mobile has "Load earlier/later output" and "Jump to latest" menu items. Scrollback 60,000 rows (iOS 60 MB).

Search

  • Newest-first pages with a cursor instead of the 2,000-hit / 20,000-scan caps. Clients continue through at most 3 empty pages, then show "Search older messages". If a search reaches 2,000 matching threads it stops and says so.

Not done: native Android/iOS changes are not compiled (mobile needs a native rebuild); not yet tried in a running client; disk paging not benchmarked. Measured search on a 1M-message copy: no page over ~400 ms.

Check SHA Result
vp test run src/terminal src/orchestration-v2/ThreadSearch.test.ts src/provider/AgentContextBudget.test.ts (apps/server) f50b970 146 pass
vp test run terminalSession, terminal, threadSearch (client-runtime) f50b970 35 pass
vp test run ThreadTerminalDrawer, terminal/ghostty (apps/web) f50b970 80 pass
vp test run src/features/terminal (apps/mobile) f50b970 42 pass
vp run check:changed f50b970 pass

Claude Opus 5.5 via Claude Code (T3 Code).

greaber and others added 4 commits November 11, 2026 12:47
Terminals kept only 5,000 lines or 8 MiB on the server, sent at most 512 KiB on
attach with no way to reach anything older, held 10,000 rows in the client
views, and forgot all but 128 exited sessions. Each persist also rewrote the
whole history file, which would not scale to larger histories.

The server now keeps up to 1,000,000 lines and 256 MiB per terminal by default
(T3CODE_TERMINAL_HISTORY_MAX_LINES / _MAX_BYTES override them). History files
grow by appends and are rewritten only when the history is cleared or the
trimmed prefix outgrows the retained text, so total writes stay under about
twice the output; existing files still load, and loading no longer rewrites
them. Exited sessions are retained up to 4,096 and 4 GiB of history.

An attach sends the newest 512 KiB plus its offset; the new terminal.history
RPC returns the 512 KiB page before an offset. Clients prepend pages into the
same buffer (now 8 MiB). Web and desktop load a page when the user scrolls to
the top and keep the viewed rows in place; mobile gets a "Load earlier output"
terminal menu action, since its native views own scrolling. Web, Android, and
iOS views hold about 100,000 rows.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Message search read only the newest 2,000 hits, and of those at most the newest
10,000 index candidates or, without the index, the newest 20,000 messages.
Anything older was silently missing from results.

Search now pages newest-first by message rowid. Each page still reads at most
2,000 hits, passes over at most 10,000 index candidates (or scans 50,000
messages without the index) and returns up to `limit` ranked threads, so one
request stays as fast as before. The result carries a cursor while older
messages may hold more; the next request passes it back with the threads
already returned, which later pages leave out. Every matching thread in a
page's range is either returned or already excluded, so paging to the end
misses none. The agent search tool keeps its single top-ranked page.

Clients follow pages that found nothing on their own, and the web sidebar and
mobile thread list searches show "Search older messages" while more remain.
The command palettes keep showing only their best few message matches.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…ds it excludes

Clients followed empty pages of message matches to the end of history on their
own, which on a long history without matches could read for seconds per query.
They now stop after three empty pages in a row and show "Search older messages",
so the user decides whether to keep going.

Without the index a page scans 20,000 messages again, as a single read did
before paging. excludedThreadIds is capped at 2,000 threads; a search that
reaches that many stops and says so in the web sidebar and mobile thread lists
instead of dropping later matches silently.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…indow

Clients could page older output only until their 8 MiB buffer filled, so most of
a large server history stayed unreachable and scrolling to the top silently did
nothing. Reopening a terminal also processed its whole history synchronously,
and history rewrites truncated the file in place.

History offsets now count UTF-8 bytes, so they map onto the history file. Each
terminal keeps its newest 16 MiB in memory (512 MiB across all terminals,
256 MiB for exited ones); older output stays only in the file, and
`terminal.history` reads pages before or after any offset from memory or the
file. Loading reads the file in blocks and keeps just the tail, and the
alternate-screen scan on reopen looks at the last 4 MiB. Rewrites copy what is
still needed into a temporary file and rename it over the old one, so a crash
leaves one whole file; a failed append marks the file for such a rewrite.

Output events carry the server's history end. A client holds a window of about
4 MiB and 25,000 lines: reading further back drops its newest output and pauses
on earlier output, buffering live output aside; reading forward drops the
oldest, and reaching the end follows the live output again. On web the view
keeps the rows being read in place, asks for a page once per arrival at an
edge, and shows "Jump to latest" while paused. Mobile gets "Load later output"
and "Jump to latest output" menu actions. Views keep 60,000 rows.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@github-actions github-actions Bot added vouch:trusted PR author is trusted by repo permissions or the VOUCHED list. size:XXL labels Nov 11, 2026
Review of the sliding window found several ways to lose older output or stall:

- A live event over 16 KiB is split into chunks and only its last knows the
  server offset, so trimming an earlier one lost the window's start and
  "load older" stopped working. Trimming now drops through to that last chunk.
- A paused view whose end the server had since trimmed ignored the next page,
  so "load later" did nothing. The page is accepted after a visible "Earlier
  output was removed" line; an older page past the server's start ends paging.
- In narrow terminals 4 MiB of output can exceed the view's 60,000 rows, so a
  prepended page fell outside the view. The window now holds no more than fits
  the rows of the terminal's grid (a row per line plus one per column width of
  bytes), and the separate line budget is gone.
- A page read chose its file range before taking the file lock, so a rewrite in
  between could make it read before the file's start. The range is re-clamped
  against the history and file start under the lock.
- Memory pages now start at a character boundary.
- Failed history writes, as on a full disk, back off from 1 s up to 60 s
  instead of trying a full rewrite every 250 ms; each failure is still logged,
  and closing a terminal still writes at once.
- Rewrite directories a crash left behind are removed at startup, and history
  deletion takes the file lock so a rewrite cannot rename a file back.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@greaber

greaber commented Nov 11, 2026

Copy link
Copy Markdown
Owner Author

Second-review fixes in 73c62ba: large live events keep the window's start offset; a view paused past trimmed history shows a visible marker and rejoins live output; page reads re-clamp against the file start under the lock; leftover rewrite temp dirs removed at startup; backoff (1 s doubling to 60 s) after failed writes; deleteHistory takes the file lock; the client window is sized to the view's row capacity (narrow views hold less, documented); page starts aligned to UTF-8 boundaries.

Check SHA Result
vp test run src/terminal src/orchestration-v2/ThreadSearch.test.ts (apps/server) 73c62ba 147 pass
vp test run src/state/ (client-runtime) 73c62ba 874 pass
vp test run ThreadTerminalDrawer, terminal/ghostty (apps/web) 73c62ba 80 pass
vp test run src/features/terminal (apps/mobile) 73c62ba 42 pass
vp run check:changed 73c62ba pass

@greaber
greaber merged commit ef6208c into grant/main Nov 12, 2026
11 of 12 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size:XXL 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