Repository navigation
fix: take chat state from the stream only - #30478
Conversation
This comment has been minimized.
This comment has been minimized.
|
Chat: Review posted | View chat Review history
deep-review v0.13.0 | Round 15 | Last posted: Round 15, 179 findings (3 P2, 41 P3, 68 P4, 66 Nit, 1 Note), APPROVE. Review Finding inventoryFindings
Law analysisR3: effective +1002 -1257 (14 files), head 61d7798. Verdict: Don't split. Enforcement: Advisory. R7: effective +4280 -6692 (47 files), head 0e8cd3a. Verdict: Split, Mandatory (re-raised against the revert defense). R6: effective +3518 -6292 (46 files), head ba7ddb7. Verdict: Split (three vertical slices). Enforcement: Mandatory. Contested and acknowledgedCRF-41 (P4, AgentChatPage.tsx:839) - No test for the load-older mutation wiring
CRF-41 panel closure (R4, 1/1)
CRF-36 (P3, submitChatTurn.ts:419) - reverse-order send test
CRF-79 (P4, chatStore.ts:133) - stored fields and shown-turn selectors share names
CRF-89 (Nit, useChatStore.ts:102) - useCallback in a React Compiler path
CRF-93 (P1, PR) - mandatory split
CRF-95 (P3, chatStore.ts:474) - concurrent queue actions end each other's parts
CRF-96 (P3, useChatStore.ts:247) - one-second reconnect loop
CRF-95 promote panel closure (R7, 3/3)
CRF-96 parse-error panel closure (R7, 4/4)
CRF-89 re-raise (R7)
CRF-93 re-raise (R7)
CRF-93 R9 author reply
CRF-141 (P4, useConversationEditingState.ts:135) - Edit enabled but no-op during send
CRF-154 (P4, AgentChatInput.tsx:1177) - catch comment describes the store
CRF-157 (P4, submitChatTurn.ts:290) - buildOptimisticEditedMessage builds sends
CRF-158 (Nit, ChatPageContent.tsx:175) - streamError key
CRF-166 (P3, useChatStore.ts:455) - 400 cursor retried forever
CRF-167 (P4, AgentChatPage.tsx:494) - non-API failure silent
R9 panel closures
R10 author replies
R10 panel closures
CRF-204 (P4, useConversationEditingState.ts:256) - plain-text compose draft removed after a successful edit
R12 panel closures
R15 author replies
R15 panel outcomes
Round logRound 1Netero first pass (1 P2, 1 P3, 1 Nit), then full panel (round 1): ging-ts, nami, takumi, melody, pariston, mafuuu, bisky, gon, leorio, komugi, meruem (wildcard). 10 panel + wildcard exceeds the focused target of 8 because Gon and Leorio are the round-1 floor and ging-ts, nami, takumi, melody were triggered. Pagination overwrite (CRF-4) classified in scope: fix changes patchChatMessages to meet the PR's goal; severity P2 by disagreement tiebreak. CRF-6 downgraded P2 to P3: keep-argument "the PR rewrote the doc into a false statement about a shared predicate"; downgrade reason: the false claim narrows the stated match set, so no caller gets wrong behavior from it. Takumi's remount-refetch note folded into CRF-1. Reviewed against 5ca77e2..5ec0d69. Round 2Churn guard PROCEED: CRF-1 to CRF-8 author fixed (025b7f0, 8f0173e); panel confirmed CRF-4 fixed (Nami, Pariston, Mafuuu, Melody). Restructure round (patchChatMessages rewritten, reapplyAfterFetch added, PR description goal changed): full panel ging-ts, nami, takumi, melody, pariston, mafuuu, bisky, gon, leorio, chopper (wildcard). Workspace outage interrupted after Netero; resumed with same round state. CRF-16: Chopper P3 vs Mafuuu/Takumi Note; Chopper's scenario (fetch B sent after the write, returns without it) contradicts the PR's own failed-fetch rule, higher wins. CRF-17: Gon P2 vs Takumi P4; keep-argument: exported function documents a false safety guarantee and an in-tree updater (edit projection) violates it, guarded only by the await cancel; kept P2. Gon's other comment P2s downgraded: 1178 and 2342 to P3 (keep-argument: misleading "new page" and the only in-code guard for the bypass; downgrade: no behavior effect), test comments 5082/5149 to Nit (narration only). CRF-9 dropped: keep-argument "the queue_update still makes the refetch redundant"; drop reason: the refetch is no longer discarded, so the cost described no longer exists. Reviewed against a4b68ac..2037768. Round 3Churn guard PROCEED: CRF-14 to CRF-28 addressed by removal of the replay in the redesign. Restructure round (base moved to #29662 head, 14 files, new exports, goal rewritten). Law ran (+1002 effective): Don't split, advisory. Netero: 4 P3, 1 P4. Full panel: ging-ts, ging-react, nami, takumi, melody, komugi (specialists), pariston, mafuuu (core), bisky, gon, leorio (floor/restructure), hisoka (pool), meruem (wildcard); 13 exceeds focused target because six specialists triggered. Dropped CRF-70/71: keep-argument "useChatStore.ts:856 says the store is shared, so an unkeyed route would expose it"; drop reason: router.tsx lazy-imports the default export KeyedAgentChatPage, keyed by agentId on both routes, and useChatStore creates its store with useState per mount. CRF-36: Gon P2 vs Leorio P4; keep-argument: contradictory comments on the core ordering guard; downgraded to P3 because send responses do not advance the cached history_version, so the history_version reconnect resends the dropped batch; loss is limited to the after_id path and unverified. Gon comment P2s downgraded to P3/P4/Nit (no behavior effect); CRF-45 kept at P3 because the comment is false. Reviewed against e2f393f..61d7798. Round 4Churn guard PROCEED: 29 addressed, CRF-41 contested, CRF-36 test request contested. Branch rebased onto a73dc4e. Restructure round (files added to the PR: coderd/exp_chats_test.go, AgentChatPageView.tsx, ChatMessageScroller.tsx; onFetchMoreMessages prop type changed). Law skipped (+206 since R3 analysis). Netero: 1 P3, 1 P4, 1 Note. Full panel: ging-ts, ging-react, ging-go, takumi, melody, komugi, pariston, mafuuu, bisky, hisoka (new agents), nami, gon, leorio (round-3 agents resumed for dispute check-in), knov (wildcard). Ryosuke not selected: the only Go change is a test file with no package-boundary or API surface. CRF-41 closed 1/1, CRF-36 test request closed 2/2. CI title failure: job log shows the earlier Round 5Churn guard PROCEED: CRF-72 to CRF-78 author fixed (04ec244, 64227af, e874a14); CRF-79 rename declined, treated as contested. Branch rebased onto 698f065; round-5 delta is four commits (+103 -11). Fix round (no files added, no signature change, small delta). Netero: 1 Note (CRF-83). Panel: knov (round-4 agent resumed, dispute), gon, leorio (comments touched), ging-ts, ging-react, nami (changed-file specialists), razor (wildcard). CRF-79 closed 1/1. Gon P4 and Leorio P4 on useChatStore.ts:113 merged as CRF-84. Reviewed against 698f065..ba9a198. Round 6Churn guard PROCEED: CRF-84, CRF-85 addressed by removal in the second redesign (stream-only store, pending actions, editable composer). Rebased onto e2bae13. Law ran (+3518 effective, grew +2516 since R3): Split, Mandatory. Netero: 1 P3, 2 P4, 3 Nit, 1 Note. Law decision gate: mandatory split, panel skipped, REQUEST_CHANGES with Netero findings and split proposal. This round counts as a Netero-only round for the consecutive cap. Human threads from DanielleMaywood answered by author (f929878). Reviewed against e2bae13..ba7ddb7. Round 6 (continued)The CLI rejected the Law-only post twice: REQUEST_CHANGES needs panel reviewers, and any post after a prior panel round needs panel reviewers. The skill's mandatory-split gate (skip panel) conflicts with the CLI; ran a full panel. Restructure round. Panel: ging-ts, ging-react, nami, takumi, melody, komugi (specialists), pariston, mafuuu (core), bisky, gon, leorio (floor/restructure), hisoka, luffy (pool), razor (wildcard). CRF-86 dropped: Bisky showed chatStore.test.tsx:4901 and :2837. CRF-129 dropped: keep-argument "the comment at ChatPageContent.tsx:669 promises attachments added during the request stay"; drop reason: AgentChatInput.tsx:978 sets onWorkspaceAttach undefined while isLoading, so no workspace upload can start during a send (Hisoka checked the same path). CRF-44 reopened: Pariston found 9361614's tests absent; grep confirms 0 matches. CRF-82 dropped: Melody showed the client no longer writes running. Gon comment P2s downgraded to P3 (false or misleading statements) or Nit (restatement). Event REQUEST_CHANGES for the mandatory split. CRF-86 restored after the CLI rejected a drop made after the first post attempt; posted with Bisky's correction that the load-failure path is covered. Round 7Churn guard PROCEED: 41 addressed; CRF-89 and CRF-93 contested; CRF-95 promote and CRF-96 parse-error partially contested. Rebased onto 1e7c5fd; +4280 -6692, 47 files. Law (resumed): Split, Mandatory, re-raised. Netero (resumed): CRF-89 re-raised, CRF-138, CRF-139. Panel: takumi, komugi, mafuuu, hisoka, razor (resumed for disputes); ging-ts, ging-react, ging-go, nami, melody, pariston, bisky, gon, leorio, chopper (wildcard). CRF-95 promote closed 3/3, CRF-96 parse-error closed 4/4. Calibration: Gon comment P2s downgraded as in R6 (false statements P3 or P4, restatements Nit); Chopper's non-API error P3 to P4 because the composer restores the draft on failure; Chopper's delete catch P4 merged into the same-as-main OOS item with Nami and Leorio. CRF-166 verified: main used after_id, so the 400 on a cursor above the chat's version is new client behavior. Event REQUEST_CHANGES for the mandatory split. Reviewed against 1e7c5fd..0e8cd3a. Round 8 updateBLOCKED. CRF-93 (mandatory split) silent: the author's reply to the R7 re-raise repeats the R6 sentence the re-raise rebutted. Churn guard: 26 addressed, 6 contested (CRF-141, CRF-154, CRF-157, CRF-158, CRF-166, CRF-167), 1 silent. No review panel. Head c99aa01. Round 9Round 8 blocked on CRF-93; the author then replied with a new argument (chain; review by file). Head unchanged (c99aa01). Churn guard PROCEED: 26 addressed, 7 contested. Law (resumed): Split, Mandatory, re-raised. Netero (resumed): no findings; CRF-89, CRF-138, CRF-139 verified. Fix round (delta 0e8cd3a..c99aa01). Panel: mafuuu, nami, gon, chopper (resumed for disputes); ging-ts, ging-react, komugi, bisky, melody, leorio, pariston (new); meruem (wildcard, random from distilled set). All six non-Law disputes closed. Gon P2s downgraded (false reason P4, restatement Nit); two Gon Nits dropped as re-raises without new evidence (CRF-185, CRF-186); Meruem isRowGone P4 to Nit (no current bug). Event REQUEST_CHANGES for the mandatory split. Reviewed against 0e8cd3a..c99aa01. Round 10Churn guard PROCEED: 6 addressed (CRF-175, 177, 179, 180, 181, 183), 5 contested. Author stated the split override as a human decision. Law (resumed): Split, Advisory; not re-raised. Netero (resumed): 1 P4 (CRF-194). Fix round (delta c99aa01..418d431, +29 -17, 4 files). Panel: bisky, komugi, gon, meruem (resumed for disputes); leorio (doc comments changed); zoro (wildcard, random). All disputes closed, CRF-93 included. Gon's P2 on the resend paragraph dropped (CRF-198, ping-pong with the adopted CRF-180 text); Zoro's wrapper and load-state P4s to Nit (style). Event APPROVE: no open finding above P4 and no mandatory split. Reviewed against c99aa01..418d431. Round 11Churn guard PROCEED: 9 of 9 addressed. Law skipped (effective additions grew 233 since R10, under 500). Netero (resumed): no findings; CRF-194 verified. Fix round (delta 418d431..1215742, 14 commits, 11 files; includes new composer behavior for edits and unmount). Panel: nami, mafuuu, bisky, gon, leorio, hisoka, ging-react; zoro (wildcard, random). Gon comment P2s to Nit (restatements); Zoro showComposeDraft duplication P4 to Nit; Bisky's test-wrapper Note to Nit because it asks for a change. Event APPROVE: nothing above P4. Reviewed against 418d431..1215742. Round 12Churn guard PROCEED: 10 addressed, CRF-204 contested. Law skipped (+22 since R11). Netero (resumed): no findings. Fix round (delta 1215742..e941530, 3 commits, 4 files). Panel: bisky (resumed for CRF-204), gon, leorio, mafuuu, razor (wildcard, random). CRF-204 closed 1/1. Gon's P2 on :188 to Nit, merged with Leorio's; Gon's rename P4 dropped (CRF-218). Event APPROVE. Reviewed against 1215742..e941530. Round 13Churn guard PROCEED: 5 of 5 addressed. Law skipped (+3). Netero (resumed): no findings. Fix round (delta e941530..5e507a9, 2 commits, comments and one rename). Panel: gon, leorio, mafuuu, razor (wildcard, random). Gon's three P2s: one kept as Nit (CRF-224, comment on code the PR changed), two dropped as ping-pong with earlier adopted findings (CRF-225, CRF-226). Event APPROVE. Reviewed against e941530..5e507a9. Round 14Rebased onto 4ed589d (round-13 head maps to 2170fae). Churn guard PROCEED: CRF-224 addressed. Law skipped (+65). Netero (resumed): no findings; rebase joins match main. Restructure round (rebase conflict resolutions merge main's chat projects, ACPContext, attachments panel, turn action bar, skill preferences). Panel: nami, mafuuu, bisky, melody, pariston, gon, leorio, hisoka; knov (wildcard, random). Pariston and Knov P3 on the pending-ID type hazard to P4 (the realized bug is fixed; remaining risk is future consumers, as CRF-181). Nami's attachments reload moved out of scope (same path on main). Gon P2s to Nit. Event APPROVE. Reviewed against 4ed589d..a3e8aef, focus 2170fae..a3e8aef. Round 15Rebased onto 36d77b8 (round-14 head maps to 87aedb7). Churn guard PROCEED: 4 addressed, 3 contested. Law ran (+814 since R10): Split, Advisory, CRF-93 stays closed. Netero (resumed): no findings; rebase join matches main. Restructure round (749f465 restores main's queued-message edit work on the store; 7496838 changes placement). Panel: pariston, knov, gon, leorio (resumed for disputes); nami, mafuuu, bisky, melody, komugi, hisoka, ging-react; meruem (wildcard, random). Placement in 7496838 checked against chatstate by Pariston, Knov, Nami, Mafuuu, Melody, Leorio; mutations by Bisky, Melody, Meruem. Event APPROVE. Reviewed against 36d77b8..5063feb, focus 87aedb7..5063feb. About deep-reviewCRF = Coder Review Finding (P0-P4, Nit, Note)
|
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
This comment has been minimized.
This comment has been minimized.
There was a problem hiding this comment.
This PR makes patchChatMessages cancel an in-flight background refetch of the messages query before each cache write. Findings: 2 P2, 3 P3, 1 P4, 2 Nit. The cancel also discards refetches whose purpose is to load state the stream does not send, and a fetchNextPage in flight still overwrites the write. Re-applying the write after any in-flight fetch settles, instead of cancelling, would address both P2 findings and the no-op cancel.
Out of scope (needs a ticket or explicit acceptance by a human):
codersdk/chats.go:962:ChatMessagesResponsecarries no history version, so the client cannot tell whether a REST read is older than the stream events it already applied; every client-side guard for this race is a timing heuristic.site/src/api/queries/chats.ts:955: theisBackgroundRefetchparameter type requiresqueryKey, which the body never reads.site/src/api/queries/chats.ts:958: the inline comment repeats the JSDoc's first-fetch rationale, so the two copies can drift.site/src/pages/AgentsPage/components/ProjectPage/ProjectChatsList.test.tsx: "loads the next page when the end of the list scrolls into view" timed out at 5000 ms on an unmodified head during a loaded run and passed on rerun.
Notes:
site/src/api/queries/chats.ts:2392: a queued-message delete already bumpsqueue_version, so the stream sends aqueue_update; with this PR that write cancels the refetchdeleteChatQueuedMessagestarts whenever it lands first, so during a running turn the invalidation mostly costs a discarded request.
🤖 This review was automatically generated with Coder Agents.
5ec0d69 to
2037768
Compare
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
2037768 to
62621a3
Compare
This comment has been minimized.
This comment has been minimized.
62621a3 to
028881d
Compare
7d672d8 to
96b147e
Compare
This comment has been minimized.
This comment has been minimized.
There was a problem hiding this comment.
This round redesigns the fix: after the first page loads nothing replaces the messages cache, older pages are appended, a pending edit is hidden in the store instead of truncating the cache, and send and edit responses apply only when ahead of the cache. Findings: 13 P3, 9 P4, 8 Nit (most are tests and comment wording). All round-2 findings are addressed by removing the replay. The redesign holds up against every interleaving the reviewers traced: edit response before and after the stream's reset, a second edit from another tab, older-page loads racing resets, and responses after leaving the chat.
Out of scope (needs a ticket or explicit acceptance by a human):
coderd/database/queries/chats.sql:2643:isAheadOfCachedMessagesrelies on two server rules (message IDs follow commit order; every deletion inserts a newer message) that only this client comment states;SoftDeleteContextFileMessagesdeletes without inserting and has no caller, so wiring it up would let a late response restore a deleted message.site/src/pages/AgentsPage/components/ChatConversation/chatQueueReconciliation.ts:81: the queue-promote failure path and the/compactfailure path (submitChatTurn.ts:165) still restore pre-request snapshots over stream updates delivered meanwhile.site/src/pages/AgentsPage/components/ChatConversation/useChatStore.ts:221: "Compute the last REST-fetched message ID" is wrong; the cache also holds stream and response writes.site/src/pages/AgentsPage/components/ChatConversation/useChatStore.ts:206: thewsStatusReceivedRefcomment cites a window-focus refetch thatApp.tsx:20disables.site/src/pages/AgentsPage/components/ChatConversation/useChatStore.ts:248:upsertCacheMessagesandreplaceCacheMessagesareuseCallbacks againstsite/AGENTS.md:82, and the first name hides that it invalidates prompts, automations and searches.site/src/pages/AgentsPage/components/ChatConversation/useChatStore.ts:311: theprevChatIDRef.current !== chatIDbranch never runs, becauseKeyedAgentChatPageremounts the page peragentId; comments still describe one store serving several chats.
Notes:
useChatStore.ts:317: "the page only adds messages to the store and never removes any" holds only because the stream's reset removes messages that a cache-only edit response deleted after the user left and reopened the chat.chatStore.ts:309: when the edit response beats the stream'shistory_reset, old-turnmessage_partevents still on the socket show under the edited message until the reset clears them; the window predates this PR.- PR description: "turn fill requests" is not defined; for example, "a page that starts in the middle of a turn also requests that turn's older messages".
🤖 This review was automatically generated with Coder Agents.
61d7798 to
4e5f251
Compare
|
In reply to AMREM-3 (Nit, The description now says what the fill is: since #30524, a page that starts in the middle of a turn also fetches that turn's older messages.
|
|
$@codex review\n/coder-agents-review\n\n> 🤖 This review was automatically generated with Coder Agents. |
…t renders The locked editor is a visual state, so the create form test of its contenteditable attribute is gone and an AgentChatInput story shows it. The pending row test in ConversationTimeline clicks every Edit button and checks the callback. The ChatPageContent test of the draft's workspace uploads during an edit only checked which chips render, so it is gone. Other ChatPageContent tests drop their checks of what renders.
…rce does The harness passes the row the shown queue marks, which the source calls markedID. The server names no longer fit, because this tab's pending begin or end marks the row too.
… SendShowsPromptAtSubmit submitChatTurn tests check that a send shows its prompt at submit, so the story only drives the page into that state for the screenshot.
…is, and drop two comments The comments restated the guard and the function body below them. The comment on the request-in-flight condition named the rollback as the restorer of the kept content; the rollback is the reason a target is not loaded then.
…ctly in its tests Only the deleted edit test passed another input component, and the composer is queried by its role like the rest of the suite.
…pt a fixed timestamp SendingFromHistoryDoesNotSnapToBottom built the message with the current time, so the story data changed on every run.
… no longer fail useConversationEditingState calls neither focus nor isMobileViewport, so the mobile focus test and the focus assertions checked nothing. The matchMedia helper had no other use.
…ies the page cannot show The page passes the row that the shown queue marks as the row under edit, so a row's marker and the under-edit ID always agree. A pending begin or end changes the marker at the click.
…ns a reason A pending row's action buttons were disabled natively, so they left the tab order and their tooltip could not show. They now use the reason tooltip that the Edit button already has.
Edit on a sent message or a queued row did nothing during a request, and the buttons gave no reason. The page now passes no edit handler while a request is pending, so the buttons are not shown, and the handlers and the hook lose their in-flight check.
…pace upload during an edit ChatPageContent shows the compose draft's workspace uploads while an edit request runs, and no story showed that state. The story uploads a file to the draft, saves an edit against a request that never settles, and leaves the screenshot to Pixel. It reuses the rebuilt workspace, whose agent is connected, so the composer accepts workspace uploads.
submitChatTurn.ts is its only caller, and it builds the content of a send and a queued save as well as an edit, so neither the file under api/queries nor the name said what it is.
… the invalidation by its queries It invalidates the prompt history and the chat search. The messages query that the name referred to no longer exists.
…ng actions on stored state A pending action ended at the next stream event of a type, which the client cannot match to its own request: two deletes before the first result ended together at the first queue_update, and the second row showed again. Each action now shows only its effect on the row or message acted on, and ends when the stored state holds its result.
upsertDurableMessages and setQueuedMessages took a snapshot version that nothing reads: pending actions end on the stored state, and the stream resumes from the version that advanceSnapshotVersion records.
The chat store shows a pending send or edit until the stream reports new user content, oldest first, so the server must make the changes in the order the user made them. A shared mutation scope runs the requests one at a time, and a request that waits is pending, which keeps the composer from accepting another submit meanwhile.
…ed actions at a connection's first read When the stream falls behind several of the user's actions, one read can report all of them, and counting new user content can end the wrong action and leave another for good. A connection's first read holds the result of every request that settled before it opened, so those actions end there. The store now leaves request order to the mutations, queues a send behind an earlier pending message, and keeps the shown queue's identity while only the stream state changes.
… pending begin of an edit on another row The server ends a row's edit when another row's edit begins, so after two begins the first one's result shows only if the client reads the queue in between. When one read covers both, the first begin never ended.
…omment compactChat and clearChat change the chat too but do not share the scope.
…ved actions at the first status and edits by ID A connection's first read can span several WebSocket messages and ends with its status event, so ending the resolved actions after the first message let a deleted row show again. Counting an edit's message as new content could end an earlier send instead and leave the edit hiding the transcript; an edit now ends by its message ID and replaces the earlier sends, whose results it deletes.
…at an edit deletes and where the status event comes Three comments said more than the code does: an edit also deletes the edited message, the queue is cleared as its own step, and a first read can send events after its status event.
…ueued row as new by its ID, not by the highest ID The server delivers a steer row before an older queue row. When one read reported both, the older row was below the highest stored row ID and did not count, so one pending send never ended and showed next to its stored message.
…pending actions without a reconnect rule A reconnect ended the pending actions whose requests had resolved, because counting could leave one pending for good. Two changes make every such action end on the stream's state: rows count as new by ID, and a message edit replaces an earlier pending edit, whose message it deletes.
… the received row IDs and the replaced actions' tests for what they hold The set holds every queued row ID the store received, including rows that are no longer stored, and two tests named an end at a read for an action that its replacement ends at the click.
…nto main dropped Replaying the branch's commits with their side preferred dropped main's attachments hook changes, so this restores the tree of the merge with main.
…at's status between visits A chat rendered without a status from the moment it opened until the stream's first status event. The timeline renders a chat without a status as an ended turn: the working block shows the duration up to its last stored step, and the turn's last text shows as the answer. When the stream reported running, the block's clock jumped and the text folded into the block. This happened on every return to a running chat, because the end of a visit cleared the status. The end of a visit now keeps the status and the turn error, and a new store takes its first status from the chat record.
…eep a chat's status between visits" This reverts commit 2e9e9ac.
…e stream reports one The timeline and the composer read the status from the chat store only, and the store has none from the moment a chat opens, or reopens, until the stream's first status event. The timeline renders a chat without a status as an ended turn: the working block shows the duration up to its last stored step, and the turn's last text shows as the answer. When the stream reported running, the block's clock jumped and the text folded into the block. Both now fall back to the chat record's status, as the page already does for its other readers. The chat list's watcher keeps that status current while the chat is closed.
On
main, the chat page keeps two copies of a chat's messages and queue: the messages query cache and the store. A refetch or an action response can replace state that a newer stream event already set.This PR makes the store the only copy. It implements D1 and D2 of the RFC Chat stream contract: one copy of each chat in the web client, which describes the design and the alternatives. The diff under
site/removes about 2,600 lines net, about 900 of them source.Stacked on #29662, which adds
snapshot_versionto the stream.Changes
chatQueueReconciliation.tsare deleted. The client no longer sets a chat status itself, and it does not read messages or queue rows from action responses.snapshot_versionand reconnects at the highest version among the events that the client applied. Ahistory_resetdeletes the stored messages from itsfrom_message_idon.editing_sincematches or the row is gone;queued_message_id, so a delivered row never shows in the queue and the transcript at once.coderd/exp_chats_test.gocover events that the client no longer backs up with a refetch: the ones after/clearand after a queued message is deleted.Behavior that differs from
mainmain, it showed from the POST response.main, the composer was disabled during a request, and a send kept its text there until it succeeded.main, the list hid or disabled rows itself while a request ran.main, it showed nothing.queue_updateof the change that removed it. Onmain, the client deleted the row from its own queue.main, the client skipped the message, lost its events, and kept the error.[A, B, C], deleting A and then B before the first result arrives keeps B hidden when thequeue_updatefor A arrives.Deviations from the RFC
The RFC is approved, and its page is not changed yet. D2 differs in three places:
readonly, and the site owner role has no chat permissions.Known limits
The client assumes one user who acts in one client. In the cases below, the queue or the transcript is wrong until the next stream message corrects it.
Decision log
busy_behavioronly changes fromqueuetosteer, so the delete and promote conditions only move one way.queued_message_id, so a send counts once. Rows count by ID and not by a highest ID, because the server delivers a steer row before an older queue row. Rejected: reading the ID from the action's response (the client would depend on the response, and the stream can report the change first), and a client-chosen ID stored with the message (it needs a new stored field on the server).history_resetremoves the edited message, and the next user message above it is the edit's. An edit also replaces earlier pending sends and message edits, because it deletes what they add.isPendingfalse.chatStore.tshas 74 more lines than with the RFC's next-event rule: the server-placement prediction is gone, and the end conditions and the counting replace it.statusevent, and the timeline renders a chat without a status as an ended turn.maincopied the record's status into the store; here the components fall back to it, so the store's status still comes only from the stream.statusanderrorevents, so "Thinking" shows when the stream reports the turn.useQueuedMessageEditno longer reads the marker request's state, because a pending begin or end marks the row in the shown queue.should-fix: the editable composer (RFC D2 rule 4) could be its own PR. It is not split, because the composer must clear at the click here (the transcript shows the sent message at the click), so a split would ship an interim composer that clears and locks. Nits:WithMessageHistoryandSendingFromHistoryDoesNotSnapToBottomkeep assertions in their play functions; both stories are excluded from Pixel onmain, and the second holds the only check that a pending user row anchors the scroller. Two naming nits are unchanged, both names thatmainhas:streamErrorinliveStatusModel.tsandhasFileReferences. One nit from the latest round is unchanged: the truncation of the transcript from an ID is written twice, inbuildViewand inresetHistoryFrom.Deleted tests
The branch deletes 112
itblocks, 18describeblocks, 11 stories, and one test file. A test that kept its assertions under a new name or a renameddescribecounts as renamed, not deleted. File names are shortened:createStoreischatStore.createStore.test.ts, andchatStore.testischatStore.test.tsx.chatQueueReconciliation.test.ts,runEditQueuedMessage(3 tests)queue_update.pending actions show the server's changecases "begin a queued edit while another row is under edit" and "save a queued edit", and "a failed queued edit shows the queue as before and drops no row". AgentChatPage.test: "an Edit refused with %i reports it and can be retried". submitChatTurn: "saves a queued row with its chips and the marker cleared and makes no chat send".chatQueueReconciliation.test.ts, the rest of the file (26 tests):restoreOptimisticRequestSnapshot,runPromoteQueuedMessage,runDeleteQueuedMessage,reconcilePromotedQueuedMessages,buildInactiveChatQueueReconciliation,settlePromotedQueuedMessages,submitEditqueue_update.pending actions show the server's changecases "promote in an errored chat", "promote in a paused chat", "send to an errored chat with a queue", "send after turn to an errored chat with a queue" and "delete the row that holds a paused chat". submitChatTurn: "reports send failures and invalidates the chat", "restores the transcript when an edit fails", "$name when a history edit fails". AgentChatPage.test: "reports a failed promote and keeps the row queued", "reports a failed Remove from queue". chatStore.test: "shows a chat's pending send in no other chat".applyAuthoritativeQueuedMessages(13 tests)pending actions show the server's changecases for promote, thepending action endscase "a promote at the queue update that moves the row to steer", "keeps a pending $kind through a queue update from before it", "shows nothing for a promoted row the queue no longer holds", "applies a queue update that only changes editing_since, content or lane".setChatStatus(2 tests), and "returns true after optimistic send: clearStreamState + setChatStatus('running') + upsertDurableMessage"setChatStatusis deleted. The status comes only from stream events.applyServerChatStatustests, "returns true when WS delivers user message + status:running (fresh send)". chatStore.test: "drops message_part updates after the stream reports %s".upsertDurableMessage(3 tests),setStreamState(1 test),duplicate message deduplication(1 test)upsertDurableMessagestests, including "keeps one ID for a message that appears twice".message upsert fan-out and history replacement(13 tests), and thepatchChatMessages,invalidateChatMessagesandcancelChatMessagestestsupsertDurableMessagestests. chatStore.test: "replaces messages after history_reset".editChatMessagecache tests; chatMessageEdits.test,reconcileEditedMessageInCache(1 test)pending action endscase "an edit at its new message". chatStore.test: "keeps the messages below a history_reset's from_message_id".store/cache desync protection(3 tests)snapshot_version, notafter_id.from_message_id.hasMoreMessages.SendNowPending,DeleteRejectionRestoresRowPendingRowDisablesActions.BeginRequestPending,EndRequestPendingWaitingBehindHeadUnderEditshows a pending begin, andSeveralMessagesshows a pending end.the row shown as under edit(1 table test), and the pending-begin case of "the row the composer edits"pending actions show the server's changecase "send to an errored chat with a queue".SendResponseAfterChatSwitch,SendRendersDurableUserRowBeforeAssistantOutputSendShowsPromptAtSubmit.QueuedSendPromotesPreviousHeadSendToErroredChatWithQueue. createStore: thepending actions show the server's changecase "send to an errored chat with a queue".LoadingAttachments; ChatSummaryPanel.stories:LoadingMessages,LiveMessageArriving,EarlierAttachmentsWhileFinalPageHydratesChatAttachmentsno longer takes an undefinedattachments, and theisHydratingMessagesprop is deleted. These loading states cannot occur: the view mounts after the newest page loads, and one synchronous call sets an older page andhasMoreMessages.No test covers these cases:
Kept tests whose assertions changed:
mainexpected it untouched, because a send clears the composer and a failure puts the text back. It no longer checks focus.watchChatwith the page's snapshot version. "closes old WebSocket and resets state when chatID changes" expects the second chat to open at its own page's snapshot version.Renamed tests that assert the same thing:
chatMessageEdits.test.tsmoved topendingContent.test.tsinChatConversation, and itsbuildOptimisticEditedMessagebecamebuildPendingContent. In chats.test,chatMessagesForInfiniteScrollbecamechat message pages, and four invalidation tests lost "messages" from their names. In createStore,setStreamError / clearStreamErrorbecamesetClientError / clearClientError, "clearStreamError is a no-op when already null" became "clearClientError is a no-op when already null", thereplaceMessagesandupsertDurableMessagetests that kept their names moved toupsertDurableMessages, and "does not notify when setting the same status" moved fromsetChatStatustoapplyServerChatStatus. Two createStore tests also check more: "applies a snapshot that only changes editing_since or content" became "applies a queue update that only changes editing_since, content or lane", and theresetTransientStatetest now also checks the status and the turn error. In chatStore.test, "cancels scheduled stream reset when message_part arrives after message" became "keeps a message_part that follows an assistant message in the same frame". In submitChatTurn, "compacts instead of sending and restores state if compact fails" became "reports a failed compaction without sending". In useConversationEditingState.test, "loads edit text into the composer and restores the prior draft on cancel without refocusing" lost "without refocusing".