Repository navigation
feat(tui): page session history instead of loading it whole - #803
Merged
Merged
Conversation
`make test-tui-tmux` was already red on main: #798 added the `/skill-recommend` row to the help card but did not re-record the three goldens that show it (they still read "↓ 26 more" / "↑ 26 above"). The Rust pane was byte-compared against them and lost. Recorded with `tui/tests/tmux-diff.sh --record`; the only changes are the new row and the two counts it shifts.
Switching to a long session read its entire transcript in one response (`get_messages`), which is why a 10 MB session stalled and why a session past the 32 MiB wire cap could not be opened at all (#800 raised the client cap; this removes the unbounded read). The TUI now reads display history through the agent's indexed pager: `get_session_entries` with the exclusive backward cursor `before` (`i64::MAX` = the tail) and `limit` counted in user exchanges. A switch loads the newest ten exchanges; scrolling up past the top of the transcript fetches the ten before those, until the session begins. Each page is bounded, and the rows are the same display projection the desktop renders. - `SessionEntriesPage` (tui/src/rpc/types.rs) parses a page and keeps the continuation cursor. It also accepts the legacy whole-history `messages` shape, so one mapper renders both. - `load_history_tail` reads the tail page and falls back to `get_messages` when the pager answers with nothing *or* errors: an agent that predates backward paging, and a session with no persisted history (e.g. an ephemeral one, which the pager rejects), still have a live context — "no page" must not read as "no conversation". - `App::history_paging` holds the cursor, keyed by session id: a page that was in flight when the user switched away is dropped instead of prepended into another transcript, and a page that claims more history without advancing its cursor ends the walk (the guard the desktop's page loop already applies). - `ChatArea::prepend_messages` inserts above the transcript and shifts `viewport_top` by the height it measured, so the reader keeps their place. When the reader is still at the top (the normal case — that is what triggered the load), the view is moved to show the loaded page instead of anchoring to invisible rows. - `HistoryWriter::shift`/`rebase` keep the scrollback watermark aligned: the terminal scrollback is append-only, so prepended rows are never written there, and the next flush must not mistake the shifted transcript for new content and write a second copy. - History rows now render the compaction checkpoint the mapper already handled (it was unreachable through `get_messages`, whose LLM wire shape has no `kind`/`checkpoint`). Fallback: an empty/failed pager read still ends at `get_messages`, which is the previous behaviour and now only runs when paging cannot answer. Verified against the real agent (isolated home, real journal): with 14 planted exchanges, `before=i64::MAX, limit=10` returns e2e-05..reply-14 with `hasMore`/`nextOffset=8`, the next page returns the rest with no cursor, and the real TUI in tmux loads the tail on switch and the older page on PageUp.
huichen
enabled auto-merge (squash)
September 23, 2026 10:51
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Paged session history in the TUI
Why
Switching to a session read its entire transcript in one response:
#800 fixed the symptom (tonic's 4 MiB decoding default was never raised on the TUI's client — the agent already encoded up to 32 MiB) but left the unbounded read in place: a 10 MB session still crosses the wire in one message, and a session past 32 MiB still cannot be opened.
The agent has had an indexed history pager all along —
get_session_entrieswith an exclusive backward cursor (before), alimitcounted in user exchanges, andhasMore/nextOffsetfor the continuation. The desktop (local GUI and the mobile bridge) already reads display history that way; the TUI was the client still usingget_messages, which has no cursor at all.What changed
tui/src/rpc/types.rs—SessionEntriesPageparses a page and carries the cursor. It also accepts the legacy whole-historymessagesshape, so one mapper renders both.tui/src/rpc/grpc_client.rs—session_tail_page/session_older_page/session_entries_pagebuild the request (before,limit, explicit session id) and decode it. The page size (10 exchanges) matches the desktop's remote history page.tui/src/app.rsload_history_tailreads the tail page and falls back toget_messageswhen the pager yields nothing or errors. Two real cases need that: an agent that predates backward paging, and a session the agent never persisted (an ephemeral one — the pager rejects it) that still has a live in-memory context. "No page" must not read as "no conversation"; the fallback is also what keeps version skew from blanking a transcript, and the pager's error is the one reported when both fail.HistoryPagingholds the cursor keyed by session id: a page whose request was in flight when the user switched away is dropped rather than prepended into another transcript, and a page that claims more history without advancing the cursor ends the walk (the guard the desktop's page loop applies to a non-advancingnextOffset).scroll_upreportsfalse), and that is exactly when the rest of the history would be unreachable.clear_transcriptdrops the chat, the cursor and the scrollback alignment together (switch,/new, a fresh load) so a stale cursor can never be applied to the next session.tui/src/components/chat_area.rs—prepend_messagesinserts above the transcript and shiftsviewport_topby the height it measured from the fresh layout, so the reader keeps their place even if they scrolled while the page was in flight. When they are still at the top (the normal case), the view is moved to show the loaded page instead of anchoring to rows that would stay invisible, andauto_scrollis switched off so the next streamed row cannot drag them away from the page they asked for.tui/src/insert_history.rs—HistoryWriter::shift/rebasekeep the scrollback watermark aligned. The terminal scrollback is append-only, so prepended rows can never be written there; without the shift the watermark would stop matching, and the next flush would mistake the whole transcript for new content and append a second copy of it.kind == "compaction"branch was unreachable throughget_messages(whose LLM wire shape has nokind/checkpoint); the journal rows carry them.docs/guide/tui.md/tui.zh-CN.mddescribe the paging behaviour under the keyboard table.Behaviour notes
/transcriptshows the pages loaded so far;/exportstill writes the whole session (the agent reads it from its own store).Tests
tui/src/rpc/grpc_client.rs— the request shape (before/limit/session_id, no forwardoffset), the cursor surviving the typed payload decode (the shape the agent actually sends, where the cursor is omitted on a final page), and the legacy/empty shapes parsing to "paging off".tui/src/app.rs— the tail load on--session(and thatget_messagesis not asked for when a page arrives), the older page fetched on PageUp with the right cursor, the loaded page being revealed, a short transcript still paging from the top, no page in the middle of a transcript, the empty/error fallbacks, both reads failing, a non-advancing cursor, a page for a left-behind session, and no scrollback duplication after a prepend.tui/src/components/chat_area.rs/tui/src/insert_history.rs— the anchoring math and the watermark alignment.make test-tui-tmux— newhistory-tail/history-olderscenarios switch to a session the mock planted 14 exchanges in, assert the oldest row is not loaded, press PageUp and assert the older page arrives. Every pre-existing golden still byte-matches, which is the end-to-end check that no other screen changed.Two of the golden files this PR touches are not related to the feature:
help-*.txtwere stale on main since #798 (which added the/skill-recommendrow without re-recording), so the harness was red before this work. They are a separate commit (test(tui): re-record the help goldens stale since /skill-recommend) whose only diff is that row and the counts it shifts.Verification against the real agent
Isolated home + real agent (no model configured), with a legacy JSONL session imported first (
agent/src/session/legacy_import.rs), so the journal is real:Then the real
future-tuiin a tmux pane with--session paged-e2e: the newest exchange is on screen,e2e-01is not; PageUp at the top loads the older page ande2e-01appears. A second run against a fresh one-message session loads it with no error notice and PageUp is a no-op.Local checks
cargo test -p future-tui(2069 tests),cargo fmt --check,cargo clippy -p future-tui --all-targets --no-deps -D warnings,tui/tests/tmux-diff.sh. No other crate is touched.