Repository navigation
fix(tui): keep full session history and export complete transcripts (#815) - #817
Conversation
The TUI asked the session endpoint for a 100-message page, sliced its store to the newest 100 (deleting parts of everything older) and repeated that eviction on every live `message.updated`. Copy and export then built the transcript from that same capped cache, so long sessions silently lost their oldest messages. Hydration now omits `limit`, which the endpoint answers with the complete timeline (it pages internally), keeps every message and part, and no longer evicts on live appends. A message removed while hydration was in flight still does not get its parts resurrected by the stale snapshot. `sync.session.history()` reads the complete persisted timeline for a session and merges the live store into it (newer streamed part text, prompts not projected yet), and copy/export build the transcript from that instead of the render window. Regression coverage mounts the real session route against a fixture that pages like the server: 150-message hydration and reopen keep the oldest marker and its parts, live appends past 100 keep the oldest message, and copy/export include all 150 markers with their parts. Refs #815 Co-authored-by: arena-agent <[email protected]>
|
Thanks for your contribution! This PR doesn't have a linked issue. All PRs must reference an existing issue. Please:
See CONTRIBUTING.md for details. |
Code Review SummaryStatus: No Issues Found | Recommendation: Merge Files Reviewed (3 files)
Previous Review Summaries (5 snapshots, latest commit 428d8db)Current summary above is authoritative. Previous snapshots are kept for context only. Previous review (commit 428d8db)Status: No Issues Found | Recommendation: Merge Files Reviewed (4 files)
Previous review (commit 9317e75)Status: No Issues Found | Recommendation: Merge Files Reviewed (8 files)
Previous review (commit 0208cda)Status: No Issues Found | Recommendation: Merge Files Reviewed (5 files)
Previous review (commit 2fbb955)Status: No Issues Found | Recommendation: Merge Incremental review of Files Reviewed (6 files)
Previous review (commit c298288)Status: No Issues Found | Recommendation: Merge Files Reviewed (6 files)
Reviewed by free · Input: 45.6K · Output: 818 · Cached: 143.4K |
Addresses the three defects raised in review of #815: - `sync.session.history()` now registers the same request tracker that hydration uses, for the lifetime of its GET. A `message.removed` or `message.part.removed` that lands while the request is open is no longer resurrected by the older persisted snapshot: a tracked message missing from the live store is dropped, and a tracked part missing from the live store is dropped with it. The hydration tracker registry now holds a set of trackers per session so hydration and transcript reads can be open at once. - The history request passes `throwOnError: true`. A 500 or a transport failure previously arrived as `data: undefined`, and `data ?? []` turned it into an empty persisted timeline that then exported the cache as a success. The failure now propagates to the copy/export catch blocks: no clipboard write, no file, and the failure toast. - Export binds the session it was launched from (`sessionData.id`) instead of re-reading `route.sessionID` after the options dialog resolves. Metadata and history therefore always come from the same session when the user navigates while the dialog is open. Regression coverage (RED on c298288, GREEN here) in `test/cli/tui/scrollback-history.test.tsx`: removals during the in-flight transcript request, a 500 and a socket failure for both copy and export (no clipboard write, no file, failure toast), and a route change during the export dialog (file keeps the launched session's metadata and history). The fixture exposes `navigate` and accepts async responders for these races. Refs #815 Co-authored-by: arena-agent <[email protected]>
Addresses #815 without raising the old 100-message window: the initial render/store is bounded to the newest page, and every older message stays reachable through the endpoint's `before` cursor. - Hydration asks for `limit` (one page) and keeps the response's `x-next-cursor` per session. A failed hydration leaves no cursor instead of crashing sync (anomalyco#26560). - `sync.session.more()` prepends the previous page when the reader approaches the top; `hasOlder()` gates that prefetch and `session.first` drains the remaining pages before scrolling to the oldest message. The viewport is re-anchored on the message it was showing, so a prepend never scrolls the transcript, and the rAF chain stops at the first stale frame after unmount. - Live appends no longer evict the oldest message or its parts, and reopening a long session shows the same bounded window with the same access to older history. - Copy and export build the transcript from `sync.session.historyPage()`: they walk `before` newest-page-first and concatenate the formatted chunks, so the complete timeline is exported without loading it into the store or holding every message in memory at once. Both stay full and independent of the mount window. - Merged pages follow the live store: a message or part removed while a request was open stays removed, and a part touched by `message.part.updated` wins over the persisted row even when its type changed (previously the older persisted row won, and the stale text reached the transcript). Same rule hydration applies to live parts. Regression coverage in `test/cli/tui/scrollback-history.test.tsx` (RED at 8c7ed51: 0 pass / 14 fail; GREEN here: 14 pass): bounded mount and `before` paging, multi-page scroll down to the oldest message, viewport anchoring across a held older page, live append without eviction, copy and export from pages, the type transition in both a paged and a mounted part, removals during a request, 500 and network failures, overlapping reads, teardown-safe release, and the route-change export. `perf/mount-rss.ts` measures startup, RSS and export peak of a mounted session (150 / 5000 messages) against the same fixture contract. Refs #815
Follow-up to 0208cda for the three defects raised in review. The mount stays bounded; the fixes are about what "no rows added" means and what Home waits for. - `loadOlder` shares a page read that is already running instead of answering 0 for it. "First message" awaits that shared page, so Home used to stop at the oldest *loaded* message whenever the reader parked at the top and the page request was still in flight. - `sync.session.more()` now reports `{ added, cursor }`. A page can add nothing — its rows are already loaded (duplicate window) or were removed live — while its cursor still points at older history. Home treats such a page as progress when the cursor moves and only stops when a page adds nothing *and* the cursor does not advance, instead of reading "added 0" as the end of the timeline. - `historyPage()` includes store-only rows when the newest page comes back empty: a session whose only message is the prompt the reader just sent has no persisted row yet, and copy/export dropped that prompt entirely. - Home invalidates pending anchor restores, so the page that was in flight cannot pull the view back down after the jump to the first message. Tests (`test/cli/tui/scrollback-history.test.tsx`, 18 tests, every one inside the default 5 s per-test budget): - first message drains a page that is already in flight (held auto-prefetch); - first message keeps draining when a page only repeats rows (stable id cursors, duplicate window, older history still pending); - paging keeps its place when a persisted row disappears — the fixture now serves the server's stable id cursor in addition to the offset one; - copy and export keep a prompt the server has not persisted yet; - the multi-page scroll test drives the real scroll window per page instead of replaying wheel steps whose height depended on the layout (~14 s and wall-clock budgeted before, ~1.1 s now, on default budgets). RED at 0208cda with this same test file and fixture: 15 pass / 3 fail (the three defects above). GREEN here: 18 pass / 0 fail on the default timeout. `packages/tui` full suite: 923 pass / 5 skip / 0 fail. Refs #815
Two failure paths still ended in a success-looking state, and the initial
hydration carried a baseline defect: a read that failed was recorded as this
session's complete (empty) history.
- `loadOlder` no longer turns a failed page into `{ added: 0 }`. The failure is
reported ("Failed to load older messages", once per failure streak), the
rejection reaches the caller, and the cursor is untouched — the store only
advances it on a successful page, so the same page is retried. `session.first`
stops at the failure instead of jumping to the oldest *loaded* message as if
it were the first one; running it again (or scrolling) retries and reaches the
real oldest message. `watchScroll`'s prefetch handles the rejection.
- Initial hydration requests the page with `throwOnError` and, on failure,
returns before recording the session as fully synced. `sync()` still resolves
for anomalyco#26560; the next `sync()` retries and hydrates the real history instead of
the session looking permanently empty. This is the #815-review carryover of
the baseline hydration behaviour to the paged read, not a new regression.
- The stable-cursor mutation test now deletes a row *older* than the page
boundary and asserts that no page serves a message twice. The fixture records
what each paged read served, so the offset cursor — which repeats a row after
the deletion — fails it while the id cursor passes.
- Wheel coverage is restored as its own test on the default budget: the wheel
moves the transcript and crossing into the prefetch zone loads the page. A
wheel-only walk of a 100-message window does not fit the 5 s default (measured),
so the multi-page walk stays on the scroll window and the README says so.
Tests: 22 in `scrollback-history.test.tsx`, every one inside the default 5 s
per-test budget (slowest 1.35 s). RED at 9317e75 with this same file and
fixture: 19 pass / 3 fail (both older-page failures and the hydration retry).
`packages/tui` full suite: 927 pass / 5 skip / 0 fail.
Refs #815
…session The newest-page read in `sync.session.sync()` fails quietly: `sync()` has to resolve on a messages error (anomalyco#26560), so the route carried on and painted an empty timeline with no reason, and the only way out was to notice and revisit the session. The quiet contract stays as it is. `sync()` now keeps the error of the read that failed (`syncError`), cleared by the read that succeeds, and the session route reports it as "Failed to load messages: <reason>" when its sync lands on that session. Nothing is marked complete, so the existing revisit path is what retries: leaving and coming back re-syncs the session and loads the page. Regression on the mounted route for an HTTP 500 and a network failure: the error is painted, the timeline stays empty and is not recorded as complete, and the next visit loads the newest page, clears the failure, and still reaches the real oldest message. Part of #815. Co-authored-by: arena-agent <[email protected]>
Issue for this PR
Closes #815
Type of change
What does this PR do?
Long sessions lost their oldest messages in the TUI, and transcript copy/export inherited that loss.
Confirmed on base
dev-vibecoded@8c7ed51844449351b4706f888372439690791878:packages/tui/src/context/sync.tsxrequestedsession.messages({ limit: 100 }), keptinfos.slice(-100), deleted the parts of every older message, and marked the session fully synced.message.updatedpath shifted out the oldest message and its parts above 100.session.copy/session.exportinpackages/tui/src/routes/session/index.tsxformattedmessages()+sync.data.part, i.e. that same capped cache.This is an interface-store truncation, not persisted-data loss: nothing is deleted from storage, and no DB cleanup or migration is involved.
What changed:
sync.session.sync()now callssession.messages({ sessionID })with nolimit. The endpoint already answers the whole timeline whenlimitis omitted (it pages internally at 50 with its own cursors —Session.messagesinpackages/opencode/src/session/session.ts), so this uses the existing full-fetch contract instead of raising an arbitrary cap. Hydration keeps every message and part; theslice(-100)window and the part deletions are gone.length > 100shift/delete block in themessage.updatedhandler is removed, so appended messages stop dropping the oldest row and its parts.visibleset).sync.session.history(sessionID)fetches the full timeline (nolimit) and merges the live store into it: newer streamed text for text/reasoning parts, live content for a message still in flight, and prompts the server had not projected yet.session.copyandsession.exportformat that result instead of the rendered window, so a transcript never inherits a viewport/cache limit.No spacing/layout changes (#816 stays untouched), no CI/workflow edits, no history rewrite.
How did you verify your code works?
Base SHA verified against the live remote:
git ls-remote origin dev-vibecoded→8c7ed51844449351b4706f888372439690791878(the branch point of this PR).Regression coverage — new
packages/tui/test/cli/tui/scrollback-history.test.tsxmounts the realSessionroute (no component stubs) with 150 uniquely marked messages/parts. The shared fixture (test/fixture/session-route.tsx) now pages/session/:id/messagelike the server: alimitreturns the newest page in ascending order plusx-next-cursor, and an omittedlimitreturns the complete timeline. It also accepts aclipboardservice andpathsso export/copy can be observed end to end.Four cases: 150-message hydration + reopen (store and painted frame reach
HISTORY-MARK-001, parts retained, nolimiton the wire), live appends from 60 → 120 (oldest message/part survives and is still scrollable),/copy(clipboard text contains markers 001 and 150, exactly 150 markers),/export(writes the file intopaths.cwd, reads back markers 001 and 150, exactly 150 markers).Commands and results:
Two tests that pinned the removed behavior were updated rather than bypassed:
sync-live-hydration.test.tsxasserted a 100-message merge window (now asserts the whole merged timeline, oldest message and part retained), andreview-background-provenance.test.tsxnow answers the mount's hydration request with its live window so its "outside the live window" scenarios keep exercising the review's full-history read (fetch counts and assertions unchanged).Screenshots / recordings
Verified at pixel level through captured frames (
app.captureCharFrame()): after hydration and after live appends,session.firstpaintsHISTORY-MARK-001at the top of the transcript, while the untouched base hides it. Real export contents from the TUI export command were read back from disk (not from the store).Checklist