Skip to content

feat(tui): page older session messages - #39721

Open
kitlangton wants to merge 4 commits into
anomalyco:v2from
kitlangton:older-messages
Open

feat(tui): page older session messages#39721
kitlangton wants to merge 4 commits into
anomalyco:v2from
kitlangton:older-messages

Conversation

@kitlangton

Copy link
Copy Markdown
Contributor

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.tsx keeps the opaque server cursor private and adds data.session.message.older(sessionID, count).
  • Older requests coalesce per session, deduplicate overlap, prepend in chronological order, and rebuild the message index.
  • Exhaustion stays internal: 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.tsx requests history at the viewport top and serializes each fetch through layout restoration.
  • Anchor restoration prefers the existing visible message boundary, so concurrent bottom appends do not affect compensation; total-height growth remains the fallback for notice rows.
  • The existing full rows.ts reduction runs after each prepend so reasoning, exploration, and usage groups may cross page boundaries safely.

Scope

  • No protocol, server, generated client, or plugin Data API changes.
  • No incremental row-prepend optimization or transcript virtualization.
  • JSON export retains its existing direct ascending API pagination.

Testing

  • cd packages/tui && bun run test (570 passed, 5 skipped)
  • cd packages/tui && bun typecheck
  • Repository-wide push-hook typecheck (33 tasks passed)
  • Changed-file oxlint (0 errors; baseline warnings remain)
  • OpenCode Drive: seeded a 15-turn session, opened it in a fresh TUI, verified newest-20 startup, upward prepend with request 6 held at the same viewport position, and First message landing on request 1

Demo

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:

Request 6 remains at the top after loading older history

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
Loading

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant