Repository navigation
fix: send only changed chat history over the stream - #29662
Conversation
ad7a0f3 to
f9b402f
Compare
a82cfd8 to
381fb14
Compare
381fb14 to
cb8ddd6
Compare
This comment was marked as outdated.
This comment was marked as outdated.
|
Chat: Review posted | View chat Review history
deep-review v0.13.0 | Round 15 | Last posted: Round 15, 61 findings (13 P3, 29 P4, 19 Nit), COMMENT. Review Finding inventoryFinding inventory: PR #29662Findings
Contested and acknowledgedCRF-5 (P3, useChatStore.ts:664) - Reconnect cursor never lowered when a stale REST page rolls the store back
CRF-10 (P3, AgentChatPage.tsx:296) - No test covers the page passing history_version to useChatStore
CRF-30 (P4, useChatStore.ts:580) - Full reset upserts earlier-frame messages then replaces them
CRF-33 (Nit, exp_chats_test.go:10270) - Comment repeats the assertion message
CRF-35 (Nit, stream_loop_internal_test.go:503) - reset(messages int) parameter name
CRF-10 R3 update
R3 panel closures
CRF-44 (P4, codersdk/chats.go:3163) - StreamChatOptions.HistoryVersion pointer adds nil state equal to zero
CRF-59 (P3, stream_loop.go:474) - Versioned reset relies on deleted rows keeping their edit's revision
Law analysisR1: effective +1163 (head 6787013). Verdict: Don't split. Enforcement: Advisory. Round logRound 1Full panel (round 1). Netero + Law first (Law: don't split, advisory). Panel: ging-go, ging-ts, ging-react, nami, melody, ryosuke, killua (specialists), pariston, mafuuu (core), bisky, hisoka, leorio (pool), razor (wildcard). Gon deferred to next panel round to hold the 12-reviewer target; Knuckle and Takumi not triggered (no query/schema or goroutine changes). CRF-5 is convergent (Hisoka, Melody, Mafuuu; Nami listed the root race as OOS); kept at P3 because on main the same stale state also persisted until a reconnect or refetch, so the PR's delta is the lost repair on reconnect. Reviewed against 5552152..6787013. Round 2Restructure round (exported SDK types changed: ChatStreamStatus.HistoryVersion removed, StreamChatOptions.AfterRevision renamed to HistoryVersion, ChatStreamPreviewReset added; wire param renamed). Churn guard PROCEED: 12 addressed, CRF-10 contested, CRF-5 deferred to #30478. Law skipped (+37 effective). Netero: no new findings, CRF-1/CRF-2 verified. Full panel: ging-go, ging-ts, ging-react, nami, melody, ryosuke, killua, pariston, mafuuu, gon (once-per-PR floor), leorio, hisoka, kite (wildcard), plus bisky (dispute check-in, R1 agent reused). CRF-10 re-raised by Bisky (0/1 accept). CRF-12 re-raised by Leorio (event field docs still missing; author declined that part). Gon P2 (redundant comment) downgraded to Nit: keep-argument is noise in test, but no behavior or reader trap. Gon P3 (hasHistoryVersion naming) downgraded to P4: keep-argument is a plausible refactor breaking old clients, but the field comment states the meaning and no current behavior is wrong. Reviewed against c9680e4..0e0a8ec. Round 3Fix round (no exported signature changes; SDK edits are comments; one behavior commit 8c68ff3 in useChatStore). Churn guard PROCEED: 6 addressed, 4 contested, CRF-5 deferred. Law skipped (+76 effective since R2). Netero: no findings. Panel: bisky, nami, gon (dispute check-ins, prior agents messaged), leorio, mafuuu, ging-go (fix verification), ging-ts, ging-react, ryosuke, hisoka (files/behavior changed since R2), chopper (wildcard). Workspace agent disconnected mid-round; after restart the 10 reviewers without output files were resumed via message_agent with the same prompt (Gon had already written). All four contested findings closed 1/1. New: 1 P3, 1 P4, 1 Nit. Reviewed against a4b68ac..f19806a. Round 4Fix round (no new files or exported signature changes; one behavior commit bfdc902 writes the preview_reset version into cached page 0, resolving CRF-4 and a Codex thread). Churn guard PROCEED: CRF-39, CRF-40, CRF-41 addressed; CRF-5 deferred. Law skipped (+137 effective since R3). Netero: no findings, both new tests mutation-verified. Panel: bisky, leorio, chopper (fix verification), nami, ging-ts, ging-react, ging-go (changed files), hisoka (new cache state), zoro (wildcard). All three fixes verified. New: 2 P4, 1 Nit (convergent). Zoro P4 on the HistoryVersion pointer kept at P4: keep-argument is the generated number|null and caller zero-checks on an experimental API that is cheap to change now; counter-argument is the sibling AfterID *int64, which does not remove the meaningless state. Reviewed against 6bae268..bfdc902. Round 5Fix round (refactor and doc comments only since R4). Churn guard PROCEED: CRF-43, CRF-45 addressed; CRF-44 contested; CRF-5 deferred. Netero: no findings. Panel: zoro (dispute check-in, R4 agent messaged), nami, hisoka, leorio, ging-ts, ging-react, knov (wildcard). CRF-44 closed 1/1. Codex thread PRRT_kwDOGkVX1s6q1d9h (empty chat at version 0) refuted by Nami, Hisoka, Knov; orchestrator confirmed insertChat rejects empty InitialMessages (transitions.go:126). Knov raised CRF-3 at P4 claiming revisions between chat version and the client value are permanently lost; orchestrator disproved that mechanism (applyDBSnapshot sets l.state.historyVersion = chat.HistoryVersion unconditionally at stream_loop.go:361, so later syncs use the real version). Kept at P4 as CRF-47 with the residual consequence (rows at or below the chat's version the client never held are silently never sent; public parameter, one-comparison fix). Keep-argument for P3: silent incomplete history on a public API; settled P4 because only a caller sending a version it never read hits it. Reviewed against 782fb30..a73dc4e. Round 6Fix round (one validation check, its test, doc text). Churn guard PROCEED: CRF-47, CRF-48 addressed; CRF-5 deferred. Netero: no findings. Panel: knov, leorio (fix verification), bisky, chopper, hisoka, ging-go, zoro (wildcard). Both fixes verified; > vs >= boundary pinned (Bisky, Chopper mutation). New: 1 P4 (error detail), 1 Note (DB rollback retry loop, no change requested). Reviewed against 782fb30..77ab16b. Round 7Fix round (CRF-51 detail text, two comments). Churn guard PROCEED: CRF-51 addressed; CRF-5 deferred. Netero: no findings. Panel: leorio, hisoka (raised CRF-51), gon (comments), chopper, kite (wildcard). Gon first reported its prompt missing (read during select); re-sent the same prompt and it completed. CRF-51 verified. Gon P2 on the patchNewestPage comment downgraded to Nit: keep-argument is the misleading reference-vs-equality contract for a future caller; downgrade because the cost of misreading is one redundant setQueryData, and Leorio R5 judged the comment accurate. Gon AfterID doc item is pre-existing text (OOS). Reviewed against 782fb30..698f065. Round 8Restructure round: PR rewritten from history_version cursor to per-event snapshot_version; web client changes moved to #30478; five queries deleted; migration guide rewritten. Churn guard PROCEED: CRF-54 addressed (code removed), CRF-5 deferred. Law skipped (effective +1056, below R1). Netero: 2 P4 (CRF-57, CRF-58); Netero prompt race (spawned in same batch as select) resent. Full panel 14: ging-go, knuckle, ryosuke, melody, killua, takumi, kurapika, pen-botter (specialists: Go, queries, architecture, wire format, hot path, concurrency, dbauthz, docs), pariston, mafuuu (core), bisky, gon, leorio (pool; gon/leorio mandatory on restructure), kite (wildcard). Exceeds 12 because eight specialists triggered. Convergence: unenforced write invariants behind the versioned path (Ryosuke, Kite, Pariston framing 4, Takumi note) kept as two P3s with distinct fixes. Gon P2s on test-helper comments downgraded to Nit (same reason as R7). Bisky single-row table finding merged into CRF-58. Reviewed against b9e76bd..e2bae13. Round 9 updateBLOCKED. CRF-59 (P3) silent: no reply and no change to set_chat_message_revision_before. 20 findings addressed in cdf4789 and f1007e9 (claimed fixed per churn guard; not yet verified by the panel). No review panel. Reviewed against 9cda919..556131b. Round 10Fix round. Churn guard PROCEED: CRF-57, CRF-58, CRF-60 to CRF-77 addressed (cdf4789, f1007e9); CRF-59 contested; CRF-5 deferred. Netero: no findings, CRF-57 and CRF-58 verified. Panel: ryosuke (dispute check-in, R8 agent messaged), kite, knuckle, mafuuu, leorio, pen-botter, gon, bisky, ging-go, knov (wildcard). All checked fixes verified (CRF-57, 58, 60 to 68, 77; Gon confirmed 70 to 76 applied). CRF-59 re-raised by Ryosuke (0/1 accept) with new evidence: migration 000435 backfilled chat_messages with no deleted filter. Convergent comment finding (4 reviewers) on versionedMessageEvents: Gon P3, others P4; kept P4 because it is comment accuracy, code behavior is tested. Gon P2s on comment repetition downgraded: CRF-85 to P4 (two lists to keep in sync), CRF-86 and CRF-87 to Nit (same reason as R7/R8). Pen Botter OOS: codersdk/chats.go:3392 StreamChat turns read failure into synthetic error event (body). Reviewed against 9cda919..e5e63f8. Round 11Fix round (comments, one test local rename, two docs sentences; e5e63f8..1e7c5fd). Churn guard PROCEED: CRF-83 to CRF-89 addressed, CRF-59 contested again, CRF-5 deferred. Netero: no findings, CRF-83 to CRF-89 verified. Panel: ryosuke (dispute check-in, R8 agent messaged), gon, leorio (raised CRF-83 to CRF-89; comment and doc changes), mafuuu, bisky (CRF-83 co-raisers), pen-botter (docs changed), knov (wildcard). All seven fixes verified. CRF-59: author's R11 defense (000435 predates 000519, no write since updates a deleted row, trigger would block a write no code makes) answers the R8 raise-exception fix, not the R10 keep-revision fix, which blocks nothing; Ryosuke re-raised (0/1 accept). Second contest round with no movement, so the body asks for a human decision. Gon P2 and Leorio P4 on the CRF-83 replacement comment dropped as CRF-91: the author applied the wording the R10 comment proposed, the comment is accurate, and the remaining points are wording preference. Reviewed against 9cda919..1e7c5fd. Round 12Fix round (docs only: bc14706 rewords the migration guide event table). Churn guard PROCEED: CRF-59 contested a third time (author: only current UPDATEs are SoftDeleteChatMessagesAfterID and the search queries, none restamps a deleted row; the comment states the assumption), CRF-5 deferred. Netero: no findings. Panel: ryosuke (dispute check-in, R8 agent messaged), pen-botter, leorio (docs changed), mafuuu (wildcard). Ryosuke accepts the defense as correct for current code but keeps the finding (0/1 accept): documented vs enforced invariant, no new facts on either side; needs a human decision. New: CRF-92 P4 convergent (Pen Botter, Leorio). Leorio's line used (row only; line 213 explains why resends are harmless and can stay). Reviewed against 9cda919..bc14706. Round 13Fix round (docs only: 3399896 migration guide message row, 7be3f1c SnapshotVersion doc semicolon plus regenerated apidoc, schemas.md, typesGenerated.ts). Churn guard PROCEED: CRF-92 addressed, CRF-59 contested with explicit author decision (PRRC_kwDOGkVX1s8AAAABBfQW1g), CRF-5 deferred. Netero: no findings. Panel: ryosuke (dispute check-in, R8 agent messaged), pen-botter, leorio (CRF-92 raisers, docs), mafuuu (wildcard). CRF-92 and Codex thread PRRT_kwDOGkVX1s6w59V9 verified. CRF-59 closed 1/1: Ryosuke accepts the author's explicit owner decision to keep the documented invariant (no current writer violates it, stated at stream_loop.go:477 and ARCHITECTURE.md, enforceable later with one function migration). No new findings. Reviewed against 9cda919..7be3f1c. Round 14Rebase round (onto eba39ae; head 4ed589d). Not a restructure: PR diff unchanged except main-rename context lines and 98d206d (TestGetChatAttachments moved from deleted SoftDeleteChatMessageByID to SoftDeleteChatMessagesAfterID). Main added no chat_messages or chat_queued_messages writer (new read query GetChatMessagesWithFilePartsByChatID; migrations 000634 to 000637 do not touch chat tables). Churn guard PROCEED: CRF-5 deferred, no other open findings. Netero: no findings, 98d206d mutation-verified. Panel: bisky (test changed), knuckle (queries from main), mafuuu (core), knov (wildcard). All no findings; Bisky and Netero mutation-verified the fixture's delete. Reviewed against eba39ae..4ed589d. Round 15Rebase round (onto f0ddf43; head 36d77b8). PR diff unchanged except main context lines and 36d77b8 (hooks_test.go from main moved off deleted InsertChatQueuedMessage and DeleteChatQueuedMessage). Main added migration 000638 (editing_since, paused, trigger now fires on editing_since) and two queue writers (UpdateChatQueuedMessageEditing, UpdateChatQueuedMessageContent), all called from chatstate Tx methods after LockChatAndBumpSnapshotVersion; orchestrator, Netero and Mafuuu verified both fire the queue_version trigger (UPDATE OF fires on SET targets, and Content always sets content), so CRF-79 still has no writer that triggers it. Churn guard PROCEED: CRF-5 deferred only. Netero: 1 P4 (require in handler goroutine) dropped as CRF-93: the replaced line had the same defect and the file has 17 such calls from main; asking this PR to fix one is inconsistent and out of its scope. Panel: bisky (test changed), ging-go (Go idioms, Netero finding area; no findings), mafuuu (core), razor (wildcard). CI failure is the docs-analysis job, not build or tests (job log not readable: gh token 401). Reviewed against f0ddf43..36d77b8. 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 was marked as outdated.
This comment was marked as outdated.
6787013 to
0e0a8ec
Compare
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
0e0a8ec to
f19806a
Compare
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
f19806a to
bfdc902
Compare
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
…teChatMessagesAfterID TestGetChatAttachments, added on main in 3f055e7, deleted a message with SoftDeleteChatMessageByID, which this branch removes. The helper deletes the message right after inserting it, so deleting from its ID on removes only that message.
…ith the kept queries
Replaying the action-response commit and its revert onto main put back the hand-written request that main's c80aafe replaced with requestNoContent.
#31645 moved the migration guide up one directory, so the link this PR added to the stream reference pointed outside docs/.
Review found the snapshot_version and history_reset comments hard to follow. They said the stream resends commits, but the stream sends the current state of the messages and queue that changed. They described from_message_id and after_id by what a client holds, not by what the server does with them. Two statements were wrong. The messages page does not always include a change made between its reads, because the messages and the queue are read separately. A chat with a deleted message is not what makes a stream without snapshot_version send the whole history: after_id being unset or naming a deleted message is. The AfterID comment no longer mentions relay connections, which use /stream/parts and never set after_id.
Replaying the action-response commit and its revert onto main put back PromoteQueuedResult and the two-value PromoteQueued call that main's 63e08e2 removed.
Main's 63e08e2 removed the ReorderChatQueuedMessageToHead query and this branch removes ReorderChatQueuedMessageToFront, so neither is left. Their dbauthz and dbmetrics methods are removed by hand, because the generators keep methods whose query is gone.
Main's 63e08e2 added a required busy_behavior parameter to InsertChatQueuedMessageWithCreator. This branch's tests insert queued rows with that query, because the branch removes InsertChatQueuedMessage, and they left the parameter empty. They now pass queue, the column default the removed query relied on.
The migration guide said a message event reports a changed message, but no query changes a message that isn't deleted. Its test step promised message_part events, which the stream sends only while the agent writes its response. Tell clients to ignore event types and fields they don't recognize, so that the server can add them later. The other edits apply the docs style guide to sentences this branch added: one action per step, the event name instead of "retry notice", "that has" instead of "with", and contractions in the Swagger text.
ARCHITECTURE.md called from_message_id "the lowest message ID the edit removed" and said a client reconnects with the highest version it "applied". The SDK comments say "the ID of the edited message", "deleted" and "received". The API reference said "the reply in progress" where the migration guide says "the response that the agent is writing". Each concept now has one term in all four places.
The SDK comments and the API reference say an edit deletes messages. The guide said "removed" for the same thing.
An event type or field that a client doesn't recognize can change the chat's state, so a client that ignores it can show wrong state.
A page requested with before_id has no snapshot_version, so a client cannot tell from the page whether an edit deleted some of its messages.
The replay conflicted with main's change to steerQueuedMessageWithModel (#31632). The helper keeps main's version and inserts the row with InsertChatQueuedMessageWithCreator, because this branch deletes InsertChatQueuedMessage. The generated files gain the chat-automations experiment that main added.
ab2f9c8 to
5f53220
Compare
A client can resume the chat stream (
GET /api/v2/chats/{chat}/stream) only withafter_id, a message ID. A message ID does not identify what a client received:after_id. A reconnect skips that message.history_reset, so the client keeps the messages that the edit deleted, and it never receives the messages written between the edit and its own message.after_idis the ID of a message that an edit deleted. The stream sendshistory_resetand then every message in the chat that isn't deleted.No messages page or stream event includes the chat's
snapshot_version, so a client also cannot tell whether a page is older than a stream event.This PR adds
snapshot_versionto the newest messages page and to themessage,queue_updateandhistory_resetevents, and asnapshot_versionparameter to the stream. A stream opened with the parameter sends what changed at that snapshot version or later. For an edit it sends onehistory_resetwithfrom_message_id, the ID of the edited message, and then only the messages written by the edit or after it. This implements H1 to H4 of the RFC Chat stream contract: one copy of each chat in the web client, which describes the design and the alternatives. #30478 changes the web client to use it.A stream opened without
snapshot_versionsends the same events as onmain. One change applies to every stream: when the server can't subscribe to the chat or read it, it returns HTTP 500 before the WebSocket upgrade.mainupgrades and sends anerrorevent, which the web client shows as a chat error.Two changes are not part of the RFC:
snapshot_version, so an open stream sends it late or never.SoftDeleteChatMessageByIDis also removed: an edit now deletes the edited message in the sameSoftDeleteChatMessagesAfterIDcall as the messages after it.after_idand described message envelopes that the server does not send. It now describessnapshot_version.Decision log
Implementation choices that the RFC does not state. The code comment at each one gives the reason.
snapshot_version, the messages and the queue in separate statements, without a transaction. The page can therefore include changes with a higher snapshot version, and the stream sends those changes again. The API reference states this.history_resetfor each distinct revision among them, with the lowest ID of that revision asfrom_message_id. It reads no full history (versionedMessageEvents).main, then sorts them by snapshot version with a stable sort (applyDBSnapshot).subscribeWithInitialErroris deleted.SubscribeAuthorizedreturnsok == falsefor a setup failure, and the handler returns HTTP 500 before the upgrade.