Repository navigation
fix(chat): page chat history and restore the reading position exactly - #581
Merged
Merged
Conversation
Opening a chat sent its whole active branch over the socket - on a long chat tens of megabytes and about a second of server work, every time the chat was opened. Returning to a chat after switching projects or refreshing also rarely landed where the user had left it. The chat now loads its latest page (about 80 messages) and fetches older pages on scroll-up or when a jump targets an unloaded message. Page boundaries never separate a tool call from its result, a sub-agent from its parent call, or a compaction/skill message from its source. The navigation rail and the task widget, which need the whole branch, get a light prompt index and task history instead of message bodies. A 7,084-message chat now opens with 124 KB instead of 41.8 MB. The reading position was off for four reasons, each addressed: - the list rendered through two branches, so every message remounted just as a restore finished, dropping the heights being aligned to; it now has one render path - heights kept settling after the one-time alignment, and Safari has no scroll anchoring; the restored position is now held for two seconds or until the user scrolls, clicks or types - workspace saves requested while docks were still loading after a switch were dropped; they are now deferred until the docks settle - the last scroll before a refresh sat in two debounces; it is now flushed on pagehide and when the tab is hidden
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.
Summary
Load chat history a page at a time instead of the whole branch, and make returning to a chat (after a project switch or a browser refresh) land exactly on the last reading position.
Why
Opening a chat sent every message on its active branch. On a long chat that meant tens of megabytes and about a second of server work, every time the chat was opened. Separately, the saved reading position was restored inaccurately or not at all after switching projects or refreshing.
Changes
backend/chat/message-pages.ts(new): page the active branch backwards from the head (default 80 messages). A page boundary never separates a tool call from its result, a sub-agent from its parent call, or a compaction/skill message from its source. Also serves a prompt index for the navigation rail and the task-tool history older than the loaded page.backend/ws/messages/crud.ts:messages:list-page,messages:list-prompts,messages:list-task-history(session access checked).sessions.svelte.ts: load the latest page and fetch/prepend older pages, with a generation guard against session switches. Holds the prompt index and task history.virtual-scroll.svelte.ts:prepend()shifts the window so older items enter without moving what is on screen.ChatMessages.svelte: page in on scroll-up, when a short first page doesn't fill the viewport, for nav-rail jumps, for a restored edit target, and for a saved anchor that is not loaded. Single render path (the two-branch render remounted every message on restore). Holds the restored position against late layout. Flushes the position on pagehide/hidden. Loading indicator is now an overlay instead of an in-flow row.TaskProgress.svelte: replays the task history plus the loaded messages.project-workspace.svelte.ts: saves requested while docks are settling are deferred, not dropped. AddsflushWorkspaceSave()and flushes on pagehide/hidden.Notes
TaskOutputwhose backgroundBashcall sits on an unloaded page shows unlinked until that page loads.renderScopeConfigtests fail locally onmaintoo (they read the machine's git identity); unrelated.