feat(tui): page older session messages - #39721
Open
kitlangton wants to merge 4 commits into
Open
Conversation
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.
What
Load only the newest 20 messages when opening a V2 TUI session, then page older history into the transcript as the user scrolls upward.
On the measured 200-message session, the initial API request dropped from 1.66 MB / 111.9 ms median to 72 KB / 12.7 ms median. Across four open tabs, that is about 86% fewer bytes and 5.3x less sequential server time before client decoding, row reduction, and rendering.
Before / After
Before: Every session switch fetched up to 200 projected messages before reducing the transcript. Opening several long tabs repeatedly paid for history that was not visible.
After: A session opens from its newest 20 messages. Reaching the top fetches the next page through a private cursor, prepends it chronologically, and preserves the visible message anchor. Short pages continue loading until the viewport is filled.
Commands that require complete history still behave completely: First message, previous-message navigation, timeline, fork, transcript copy, and Markdown export load the remaining pages before acting.
How
packages/tui/src/context/data.tsxkeeps the opaque server cursor private and addsdata.session.message.older(sessionID, count).older(...)returns the number of newly loaded messages and becomes a zero-result no-op once the cursor is exhausted.packages/tui/src/routes/session/index.tsxrequests history at the viewport top and serializes each fetch through layout restoration.rows.tsreduction runs after each prepend so reasoning, exploration, and usage groups may cross page boundaries safely.Scope
DataAPI changes.Testing
cd packages/tui && bun run test(570 passed, 5 skipped)cd packages/tui && bun typecheckDemo
The recording uses OpenCode Drive's simulated model. It opens the fresh 20-message tail, pages upward while request 6 remains anchored, then invokes First message and lands on request 1.
recording-c26e375c-8eb1-4876-956b-b30012647881.mp4
Anchor after the prepend:
Flow
sequenceDiagram participant View as Session view participant Data as TUI data layer participant API as Message API View->>Data: sync(sessionID) Data->>API: newest 20, order=desc API-->>Data: messages + opaque older cursor Data-->>View: chronological loaded window View->>View: user reaches transcript top View->>Data: older(sessionID, 20) Data->>API: cursor page API-->>Data: older messages + next cursor Data->>Data: dedupe, prepend, rebuild index Data-->>View: enlarged chronological window View->>View: full row reduction + anchor restore