Store a finished reply after its own message - #5259
Open
tomsmith8 wants to merge 2 commits into
Open
Conversation
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.
Problem
A user message is stored the moment it is sent; the reply is stored when its stream finishes, by appending to the end of the conversation. If another message lands in between — a second tab, another member of a shared room, or (until #5257) a stale copy of the chat that let a second send through while the first reply was still running — the stored order becomes
and every reload shows both questions stacked above both answers.
Fix
appendTurnMessagestakes the turn's id. When that turn's user row is already stored, the finished rows are inserted right after the turn's last row instead of at the end, so the transcript readsuser 1 · reply 1 · user 2 · reply 2whatever order the writes arrived in. When the turn is already last, or no turn is given (proposal intents store both rows in one write), the write is the same append as before.The three assistant writers pass their turn id:
/api/ask/quick(both the normal and the error-row write),/api/ask/sync, and the org MCP tool runner.Not covered
The live-sync merge in an open tab is still append-only, so a tab that sees a reply arrive after someone else's later message shows it last until the next reload. The stored transcript, which every open and reload reads from, is now in order.
Tests
placeTurnRowsbehaviour throughappendTurnMessages: rows land after their own user message ahead of a later one; plain append when the turn is already last or no turn id is given.