fix(site/src/pages/AgentsPage): order chat transcript by message id - #27620
Conversation
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: d0f2c2c3da
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
8500551 to
56f7161
Compare
d0f2c2c to
4a334b5
Compare
56f7161 to
d2ce637
Compare
4a334b5 to
2a89408
Compare
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 2a89408243
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
|
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 9611ca53f3
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
9611ca5 to
8a028d8
Compare
|
@codex review |
|
Codex Review: Didn't find any major issues. Can't wait for the next one! Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
If Codex has suggestions, it will comment; otherwise it will react with 👍. Codex can also answer questions or update the PR. Try commenting "@codex address that feedback". |
d2ce637 to
3ee593d
Compare
8a028d8 to
1760a47
Compare
|
Restacked onto the rebased parents, which moved to current
|
|
@codex review |
|
Codex Review: Didn't find any major issues. Already looking forward to the next diff. Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
If Codex has suggestions, it will comment; otherwise it will react with 👍. Codex can also answer questions or update the PR. Try commenting "@codex address that feedback". |
3ee593d to
d974c9e
Compare
1760a47 to
be431d5
Compare
|
@codex review |
|
Codex Review: Didn't find any major issues. Chef's kiss. Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
If Codex has suggestions, it will comment; otherwise it will react with 👍. Codex can also answer questions or update the PR. Try commenting "@codex address that feedback". |
be431d5 to
e54aa9a
Compare
|
@codex review |
|
Codex Review: Didn't find any major issues. Keep it up! Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
If Codex has suggestions, it will comment; otherwise it will react with 👍. Codex can also answer questions or update the PR. Try commenting "@codex address that feedback". |
e54aa9a to
543c648
Compare
buildOrderedMessageIDs sorted by created_at, which is the transaction start time and is shared across an insert batch. Because the sort is stable, a merge that appends newly fetched lower ids to the existing message map preserved the map order, rendering a later batch ahead of an earlier one.
…rybook The comparator fix only had store-level coverage. This renders a merge that appends lower ids after higher ones, all sharing one created_at, and asserts the rendered rows follow id order.
543c648 to
c3ab8f0
Compare

Context
Follow-up to #27495 (append-order guarantee for
chat_messages.id) and #27619 (prompt query ordering), both merged. This PR applies the same id ordering to the transcript the user actually sees.Why?
buildOrderedMessageIDsinchatStore.tssorted bycreated_at, which isnow()and therefore shared by every row in an insert batch. It buildsorderedMessageIDs, which is what the transcript renders, so it re-imposed the ordering the backend PRs remove.The failure needs the merge path, not a plain fetch. Initial REST hydration already sorts by numeric id before reaching the store, and
Array.prototype.sortis stable, so a single correctly ordered response rendered correctly. ButupsertDurableMessagescopies the existing messageMap, appends new ids, and re-sorts.Mapiteration is insertion ordered, so when a refetch or reconnect merges earlier ids into a map that already holds later ones, the stable timestamp sort faithfully preserves the wrong order.This also makes the store consistent with
useChatStore.tsandapi/queries/chatMessageEdits.ts, which already sort byid.Changes
buildOrderedMessageIDsnow callstoSortedwith anidcomparator inlined at its single call site, and thebyMessageCreatedAthelper is gone.ChatMessage.idis anumberintypesGenerated.ts, backed by a Goint64, so numeric subtraction is correct.Testing
Two vitest cases, both verified red by restoring the timestamp comparator:
sorts messages by id when created_at disagrees with append orderreturned[2,1].orders merged messages by id rather than by arrivalreturned[3,4,1,2], the exact inversion the merge path produces.MergedMessagesRenderInIDOrderinChatPageContent.stories.tsxcovers the same merge path through the rendered timeline.All 334
ChatConversationunit tests and the 4ChatPageContentstorybook interaction tests pass, andtsc -p .plus biome are clean.