fix(web): preserve loaded history during streaming - #1126
Open
GoldenZqqq wants to merge 2 commits into
Open
Conversation
修复 Codex 会话导入合并后列表为空的问题。 Fix Codex session import merge so a session is not detected as a duplicate of itself and deleted during merge. Co-authored-by: LIUZHIRU <ryuu@fine-net.co.jp>
When the user is reading above the bottom, merge streaming agent messages without front-trimming the visible window so an expanded older-history page is not discarded mid-stream. Compact back to the normal window only when setAtBottom(true) runs. Fixes tiann#1071
There was a problem hiding this comment.
Findings
- [Major] Scrolled-up streaming window is now unbounded — why it matters: while the user is reading older history, every agent SSE merge appends into
messageswithout any trim. This store feedsSessionChat/HappyThreaddirectly, so a long-running stream can keep growing the rendered thread until the user returns to the bottom. The previous code kept the live window bounded; this PR should preserve the loaded older page without removing the cap entirely. Evidenceweb/src/lib/message-window-store.ts:1041.
Suggested fix:const messages = mergeMessages(state.messages, agentMessages) const { kept, dropped } = trimPreservingQueued( messages, OLDER_LOAD_WINDOW_SIZE + VISIBLE_WINDOW_SIZE, 'append' ) const pending = filterPendingAgainstVisible(state.pending, kept) state = buildState(state, { messages: kept, pending, ...cursorUpdatesAfterAppendTrim(kept, dropped) })
Summary
- Review mode: initial
- One major issue found: above-bottom streaming now has no bounded window. Residual risk: the new test covers one streamed message, but not a long stream past the expanded-window budget.
Testing
- Not run (automation)
HAPI Bot
| // Streaming agent events are frequent; trimming from the front on every | ||
| // event used to evict the older page that had just been loaded, making the | ||
| // user repeatedly click "Load older". Compact once they return to bottom. | ||
| const messages = mergeMessages(state.messages, agentMessages) |
There was a problem hiding this comment.
[MAJOR] Scrolled-up streaming now appends into messages without any cap. Because this store feeds the chat thread directly, a long-running agent stream while the user is reading older history can keep growing the rendered thread until they return to the bottom. Preserve the loaded older page, but keep a bounded scrolled-up window.
Suggested fix:
const messages = mergeMessages(state.messages, agentMessages)
const { kept, dropped } = trimPreservingQueued(
messages,
OLDER_LOAD_WINDOW_SIZE + VISIBLE_WINDOW_SIZE,
'append'
)
const pending = filterPendingAgainstVisible(state.pending, kept)
state = buildState(state, {
messages: kept,
pending,
...cursorUpdatesAfterAppendTrim(kept, dropped)
})
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
When the user is not at the bottom, streaming agent messages went through
ingestIncomingMessagesand were immediately front-trimmed to the normal visible window (~400). An expanded older-history window (~800 after Load older) could therefore lose the older page as soon as the agent streamed more output, so Load older looked broken or had to be repeated.Changes:
setAtBottom(true)compacts back to the normal window when the user returns to the bottom.Test plan
cd web && bunx vitest run src/lib/message-window-store.test.ts(23 passed), including new casekeeps loaded history while agent output streams above the bottomFixes #1071