Repository navigation
fix(chat): preserve created_at so stream replay can't reorder messages on reconnect - #3956
Merged
Merged
Conversation
… seeded message
deliverPolicy:"all" on /stream reconnect replays an already-persisted run as
timestamp-less streamed UIMessages. Upserting one over its DB-seeded row (which
carries the authoritative top-level created_at) stripped the timestamp, so
readTimestamp returned +Infinity and the message sorted to the END of the list
— it rendered under the NEXT turn's user message and left its own slot empty
("No response was generated"). A refresh fixed it only because, with no active
run, the reconnect uses deliverPolicy:"new" and replays nothing.
Add preserveCreatedAt: when an upsert/merge replacement lacks created_at but the
prior row has one, keep it. A genuine persisted update (incoming has created_at)
still overwrites. Applied in both upsertById (stream commit path) and
mergeAndSort (defensive). Export upsertById + tests.
pedrofrxncx
enabled auto-merge (squash)
June 16, 2026 19:36
decocms Bot
pushed a commit
that referenced
this pull request
Jun 16, 2026
PR: #3956 fix(chat): preserve created_at so stream replay can't reorder messages on reconnect Bump type: patch - decocms (apps/mesh/package.json): 3.28.2 -> 3.28.3
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.
Follow-up fix to #3951 (the diagnostics, now merged). The
decopilot-stream-diaglogs from #3951 confirmed the publish path is healthy (35/35 chunks delivered, 0 errors) — the bug is client-side ordering.Symptom
Reload mid-run → turn-1's assistant response renders under turn-2's user message; turn-1's own slot shows "No response was generated". A second reload fixes it.
Cause
On reload mid-run the client reconnects, the thread is
in_progress, so/streamusesdeliverPolicy: "all"and replays the whole per-thread subject (an already-persisted run + the next one) as timestamp-less streamedUIMessages.upsertByIdthen lets a replayed (timestamp-less) message overwrite its DB-seeded row, which carried the authoritative top-levelcreated_at. The timestamp is stripped →readTimestampreturns+Infinity→ the message sorts to the end → renders under the next turn's user message, original slot empty. A refresh fixes it only because, with no active run, the reconnect usesdeliverPolicy: "new"and replays nothing.Fix
thread-connection.ts—preserveCreatedAt: when an upsert/merge replacement lackscreated_atbut the prior row has one, keep it. A genuine persisted update (incoming hascreated_at) still overwrites. Applied inupsertById(stream commit path) andmergeAndSort(defensive). ExportedupsertById; added 3 unit tests.Testing
bun test thread-connection.test.ts— 45 pass (+3).bun run checkclean on changed files;bun run fmtapplied.🤖 Generated with Claude Code
Summary by cubic
Preserves created_at on upsert/merge so replayed stream chunks don’t reorder messages after a reconnect. Fix prevents assistant replies from appearing under the next user turn and avoids the “No response was generated” placeholder.
Written for commit 0b0ee52. Summary will update on new commits.