Repository navigation
fix(coderd/x/chatd): reset stream history only if after_id is deleted - #29808
Conversation
|
/coder-agents-review |
|
Chat: Review posted | View chat Review history
deep-review v0.13.0 | Round 1 | Last posted: Round 1, 13 findings (2 P2, 7 P3, 2 P4, 2 Nit), COMMENT. Review Finding inventoryFinding inventory: PR #29808Findings
Contested and acknowledgedLaw analysisNot run. Effective additions 369 (threshold 1000). Round logRound 1Full panel (round 1). Netero first pass: 1 P2, 1 P3, 2 Notes, no build or test failure, so the panel ran. Panel: ging-go, Ryosuke, Melody, Knuckle, Killua (domain specialists: Go files, Go code, streaming producer/consumer cursor, Go-to-SQL revision semantics, per-connect hot path), Pariston and Mafuuu (core), Bisky (tests changed), Gon and Leorio (once-per-PR floor), Kite (wildcard, random draw from the distilled set). Size 11 exceeds the focused target of 6-8 because five specialists matched and Bisky, Gon, and Leorio are required. ging-go, Melody, Killua: no findings. Cross-check: the revision comparison finding converged across Ryosuke, Knuckle, Pariston, Mafuuu. Contradiction: Ryosuke, Knuckle, Pariston recommend no reset for tombstones above after_id; Mafuuu (id comparison) and Bisky (pin the reset in a test) keep it. Presented as a choice in CRF-5, with CRF-8 asking to pin whichever result is chosen. Bisky's justification cites the PR caveat about lastMessageIdRef as a cursor that understates holdings; the caveat describes a cursor that overstates holdings, so that reasoning was not carried into posted text. Orchestrator reproduced CRF-7: removing the !hasDeleted early return leaves About deep-reviewCRF = Coder Review Finding (P0-P4, Nit, Note)
|
There was a problem hiding this comment.
This PR limits the first stream sync's history_reset to cases where message after_id is missing or deleted, or a tombstone has a higher revision than it. Findings: 2 P2, 7 P3, 2 P4, 2 Nit.
Reviewers disagree on one design point: dropping the full reset for tombstones above after_id (see the finding on the revision comparison) or keeping it in case a client's cursor understates what it holds. The finding on the missing test case asks you to pin whichever you choose.
The Caveats list gaps with no ticket (see the finding on "Fixes CODAGT-1175"), including one this PR introduces: a cursor that overstates the client's state is no longer repaired by the next connect, so deleted messages can stay on screen until reload. This needs a human decision: file a ticket or accept the gap.
The PR title is 81 characters; docs/about/contributing/CONTRIBUTING.md caps commit titles at 72, and the squash commit uses the title.
Out of scope (needs a ticket or explicit acceptance by a human):
coderd/database/queries/chats.sql:2441:SoftDeleteContextFileMessageshas no caller and is the only query that can delete a message without deleting every message above it; a caller would break the tail-only assumption the stream reset rule depends on.coderd/database/dump.sql:1448:set_chat_message_revision_beforeaccepts content changes anddeleted = truetofalseon any row, so nothing in the database stops the in-place updates the reset rule does not handle.coderd/x/chatd/stream_loop.go:357: on the first sync,messageEventsdrops every changed row withid <= after_id, so an in-place update of a message the client holds is not sent until reload.coderd/x/chatd/stream_loop.go:151: the first sync still reads every visible row of the chat, tombstones and content included, on every connect; only the(chat_id)index serves it, so connect cost grows with chat length.coderd/x/chatd/stream_loop_internal_test.go:126:TestStreamLoopMessageSyncAfterIDAndEditsmodels an edit as an in-place update, the shape the new doc comment says does not happen, so readers who copy it learn the wrong edit shape.
Notes:
- The 7.1 MB measurement used an
after_idpast the chat's newest message. If that id matched no row, this PR still resets for it (theidx < 0branch atstream_loop.go:223), so the measurement shows the bug but not the fix.
coderd/x/chatd/ARCHITECTURE.md:1217
P2 [CRF-1] This section still says any soft-deleted fetched row triggers history_reset, which is no longer true for the first sync with an after_id. (Netero)
The root AGENTS.md requires updating this document when chatd behavior changes. Describe the first-sync rule here, and add the invariant the rule depends on to the Required invariant list at line 1224 (see the finding on the historyResetRequired doc comment).
🤖
coderd/exp_chats.go:3170
P4 [CRF-16] The after_id docs describe a filter, but the server now also treats it as the id of the newest message the caller holds and resets when that message is missing or deleted. (Mafuuu)
On a chat with any tombstone, an after_id that names no live row in the chat, such as a value past the newest id, gets history_reset plus the full history, while codersdk.StreamChatOptions.AfterID (codersdk/chats.go:2635-2638) says it lets relay callers skip the full history. State on both that after_id must be the id of the newest message the caller holds, and that a missing or deleted id causes a full reset.
🤖
🤖 This review was automatically generated with Coder Agents.
A new stream with after_id replays the full history when the chat has any soft-deleted message, even when the deletion predates the client's newest message. These cases fail until the initial sync bounds resets by the revision of the after_id message.
…evision A new stream with any soft-deleted message in the chat sent history_reset and every message, ignoring after_id. Chats with an edited message replayed their full history on every connect. On the initial sync with after_id, reset only when message after_id is missing or deleted, or a deletion has a higher revision than it. Otherwise send messages newer than after_id and skip deleted rows. Resets after the initial sync are unchanged.
Add cases for a tombstone at the same revision as after_id, a tombstone above after_id with a newer live message, a tombstone after after_id at or below its revision, the initial sync without after_id, and a deletion after the initial sync. Document the in-place update invariant that historyResetRequired relies on.
… deleted Messages are only deleted as a suffix of the chat, so on the initial sync the client holds a deleted message only if message after_id is deleted or missing. Drop the revision comparison, which only added full resets for tombstones above after_id, and the initial-sync guard, which matched the missing-row check for every input current writers produce.
db5f9af to
8d6ebc6
Compare
Fixes CODAGT-1175
tl;dr: The chat stream no longer sends the full history on every connect when a chat contains old edit tombstones.
On its first sync, the chat stream WebSocket treated any soft-deleted message (edits create them) as a history reset and sent
history_resetplus every message, ignoringafter_id. The client replaced its paginated cache with that history, so every connect, reconnect and PWA resume of a long chat that had ever been edited rendered the whole transcript. A dogfood chat of about 3.2k messages sent 7.1 MB per connect.historyResetRequiredinstream_loop.gonow resets on the first sync with anafter_idonly if messageafter_idis missing or deleted. Messages are only deleted as a suffix of the chat (an edit deletes the edited message and every later one), so while that message is live the client holds none of the deleted rows. Otherwise the stream sends only live messages newer thanafter_id, andmessageEventsnever sends tombstones as messages. Deletions after the first sync still reset.stream_loop_internal_test.gocovers the initial-sync cases and the deletion of a streamed message after the first sync,TestSubscribeAfterMessageIDWithEditruns a realEditMessageagainst the database, andARCHITECTURE.mdgets TODOs for the new rule.