Files
coder/coderd
J. Scott Miller 939146b077 fix(coderd/x/chatd): reset stream history only if after_id is deleted (#29808)
Fixes
[CODAGT-1175](https://linear.app/codercom/issue/CODAGT-1175/prevent-chat-stream-resets-from-loading-full-history)

**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_reset`
plus every message, ignoring `after_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.

`historyResetRequired` in `stream_loop.go` now resets on the first sync
with an `after_id` only if message `after_id` is 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 than `after_id`, and `messageEvents` never sends
tombstones as messages. Deletions after the first sync still reset.
`stream_loop_internal_test.go` covers the initial-sync cases and the
deletion of a streamed message after the first sync,
`TestSubscribeAfterMessageIDWithEdit` runs a real `EditMessage` against
the database, and `ARCHITECTURE.md` gets TODOs for the new rule.

> Generated by Coder Agents on behalf of @jscottmiller.
2026-10-16 15:40:17 -05:00
..