Skip to content

fix: session transcript disappears mid-stream when live cache only has the active turn#1616

Merged
src-opn merged 1 commit into
devfrom
task/fix-transcript-disappears
Apr 30, 2026
Merged

fix: session transcript disappears mid-stream when live cache only has the active turn#1616
src-opn merged 1 commit into
devfrom
task/fix-transcript-disappears

Conversation

@benjaminshafii
Copy link
Copy Markdown
Member

Summary

  • Bug: during streaming, the session transcript would disappear — only the last user message and the in-progress assistant reply were visible. The full history reappeared once the session went idle.
  • Root cause: deriveRenderedSessionMessages gave 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.
  • Fix: extract message-merge.ts helpers that union snapshot history with live streaming parts. deriveRenderedSessionMessages now detects when the live cache is missing messages the snapshot knows about and merges both, appending live-only messages (the active turn) when streaming. seedSessionState 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.

Changes

File What
apps/app/src/react-app/domains/session/sync/message-merge.ts New: shared merge helpers for snapshot + live message lists
apps/app/src/react-app/domains/session/surface/session-render-state.ts Uses merge when live cache is incomplete vs snapshot
apps/app/src/react-app/domains/session/surface/session-surface.tsx Passes includeLiveOnlyMessages flag during streaming
apps/app/src/react-app/domains/session/sync/session-sync.ts seedSessionState delegates to shared merge helpers
apps/app/scripts/session-render-state.test.ts Regression tests for the disappearing-transcript scenario

Verification

  • bun test apps/app/scripts/session-render-state.test.ts — 7/7 pass
  • pnpm --filter @openwork/app typecheck — clean
  • Docker dev stack started manually (sequential service boot); UI loaded, session created, prompt submitted and rendered in transcript via direct CDP inspection

… 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.
@vercel
Copy link
Copy Markdown
Contributor

vercel Bot commented Apr 30, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
openwork-app Ready Ready Preview, Comment Apr 30, 2026 1:46am
openwork-den Ready Ready Preview, Comment Apr 30, 2026 1:46am
openwork-den-worker-proxy Ready Ready Preview, Comment Apr 30, 2026 1:46am
openwork-landing Ready Ready Preview, Comment, Open in v0 Apr 30, 2026 1:46am
openwork-share Ready Ready Preview, Comment Apr 30, 2026 1:46am

@github-actions
Copy link
Copy Markdown
Contributor

The following comment was made by an LLM, it may be inaccurate:

@src-opn src-opn merged commit a1f3cfa into dev Apr 30, 2026
16 checks passed
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.
@benjaminshafii benjaminshafii deleted the task/fix-transcript-disappears branch May 15, 2026 17:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants