fix: session transcript disappears mid-stream when live cache only has the active turn#1616
Merged
Merged
Conversation
… the active turn The live transcript cache (fed by SSE delta events) was given absolute priority over the snapshot. When a long session streams a new turn, the cache often contains only the current user+assistant pair while the snapshot still holds the full history. The old deriveRenderedSessionMessages returned whichever was non-empty first, so the user saw only their last message until the session went idle and a full re-seed restored everything. Extract message-merge helpers that union snapshot history with live streaming parts, preferring longer cached text for in-progress parts. deriveRenderedSessionMessages now merges both sources when the live cache is missing messages the snapshot knows about, and appends live-only messages (the active turn) when streaming. seedSessionState in session-sync.ts reuses the same merge helpers, replacing the inline O(N*M) merge that could also drop older cached messages when a busy snapshot arrived with fewer entries.
Contributor
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
Contributor
|
The following comment was made by an LLM, it may be inaccurate: |
benjaminshafii
added a commit
that referenced
this pull request
May 15, 2026
… the active turn (#1616) The live transcript cache (fed by SSE delta events) was given absolute priority over the snapshot. When a long session streams a new turn, the cache often contains only the current user+assistant pair while the snapshot still holds the full history. The old deriveRenderedSessionMessages returned whichever was non-empty first, so the user saw only their last message until the session went idle and a full re-seed restored everything. Extract message-merge helpers that union snapshot history with live streaming parts, preferring longer cached text for in-progress parts. deriveRenderedSessionMessages now merges both sources when the live cache is missing messages the snapshot knows about, and appends live-only messages (the active turn) when streaming. seedSessionState in session-sync.ts reuses the same merge helpers, replacing the inline O(N*M) merge that could also drop older cached messages when a busy snapshot arrived with fewer entries.
benjaminshafii
added a commit
that referenced
this pull request
May 15, 2026
… the active turn (#1616) The live transcript cache (fed by SSE delta events) was given absolute priority over the snapshot. When a long session streams a new turn, the cache often contains only the current user+assistant pair while the snapshot still holds the full history. The old deriveRenderedSessionMessages returned whichever was non-empty first, so the user saw only their last message until the session went idle and a full re-seed restored everything. Extract message-merge helpers that union snapshot history with live streaming parts, preferring longer cached text for in-progress parts. deriveRenderedSessionMessages now merges both sources when the live cache is missing messages the snapshot knows about, and appends live-only messages (the active turn) when streaming. seedSessionState in session-sync.ts reuses the same merge helpers, replacing the inline O(N*M) merge that could also drop older cached messages when a busy snapshot arrived with fewer entries.
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
deriveRenderedSessionMessagesgave absolute priority to the live transcript cache (fed by SSE deltas). When a new turn starts streaming, the cache often only contains the current user+assistant pair while the snapshot still holds the full history. The old logic returned whichever source was non-empty first, dropping the snapshot history.message-merge.tshelpers that union snapshot history with live streaming parts.deriveRenderedSessionMessagesnow detects when the live cache is missing messages the snapshot knows about and merges both, appending live-only messages (the active turn) when streaming.seedSessionStatereuses the same merge helpers, replacing the inline O(N*M) merge that could also drop older cached messages when a busy snapshot arrived with fewer entries.Changes
apps/app/src/react-app/domains/session/sync/message-merge.tsapps/app/src/react-app/domains/session/surface/session-render-state.tsapps/app/src/react-app/domains/session/surface/session-surface.tsxincludeLiveOnlyMessagesflag during streamingapps/app/src/react-app/domains/session/sync/session-sync.tsseedSessionStatedelegates to shared merge helpersapps/app/scripts/session-render-state.test.tsVerification
bun test apps/app/scripts/session-render-state.test.ts— 7/7 passpnpm --filter @openwork/app typecheck— clean