Conversation
An optimistic user message row is created with a client-clock time.created while the persisted message keeps the server clock. The message.updated handler keys rows by time.created + id, so the server event misses the optimistic row and inserts a second row with the same id — the session view renders the same user message twice until a full page refetch reconciles by id. When the composite key misses, look for an existing row with the same message id and replace it in place (re-sorted under the new key) instead of inserting a duplicate. This matches the id-keyed dedupe the page fetch path already applies via reconcileFetched.
Contributor
|
The following comment was made by an LLM, it may be inaccurate: |
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.
Issue for this PR
Closes #41428
Type of change
What does this PR do?
Regression from #41001: the message store resolves rows by
messageKey(time.created + id). The prompt input inserts an optimistic user row stamped with the client'sDate.now()and sends the same id to the server, which persists it with its own timestamp. Themessage.updatedhandler misses the optimistic row (different key) and splices in a second row with the same id — the session view renders the same user message twice until a full refetch reconciles by id.When the composite key misses, the handler now looks up the row by message id and replaces it in place (re-sorted under the new key) instead of inserting a duplicate. This restores the id-identity invariant the fetch path already enforces (
reconcileFetchedkeys rows by id).mergeOptimisticPage's exact-key confirmation miss (listed in the issue) can no longer fork visible rows once insertion is deduped, so it is left out to keep this change atomic.How did you verify your code works?
New unit test in
packages/app/src/context/server-session.test.ts: add an optimistic user message attime.created: 1000, then applymessage.updatedfor the same id at1007.dev: the store holds two rows with the same id.Full
server-session.test.tssuite passes (75 tests) andbun run typecheckis clean.Screenshots / recordings
Store-level change, no visual diff; the repro is unit-level.
Checklist