refactor(coderd/x/chatd): centralize chat mutations behind a single mutator - #28756
Open
ibetitsmike wants to merge 5 commits into
Open
refactor(coderd/x/chatd): centralize chat mutations behind a single mutator#28756ibetitsmike wants to merge 5 commits into
ibetitsmike wants to merge 5 commits into
Conversation
Collaborator
Author
|
@codex review |
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. |
|
Codex Review: Didn't find any major issues. More of your lovely PRs please. 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". |
ibetitsmike
marked this pull request as ready for review
August 29, 2026 13:21
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Chat mutation endpoints in
coderd/x/chatd/chatd.goeach hand-assembled the same ritual: lock the chat, validate, run thechatstate.ChatMachinetransition, reload, translate errors, and publish the StateUpdate pubsub and watch events. Ten verbs repeated this at 40 to 80 lines each, and forgetting the publish step was a silent live-update bug every new endpoint could reintroduce.This moves the ritual behind one in-package
chatMutator(mutator.go) with one method per verb: send, edit, submit tool results, interrupt, compact, clear, archive/unarchive, delete queued, promote queued, and reconcile invalid state. TheServermethods become one-call wrappers, and per-verb differences (extra validation, intentionally skipped publishes) stay encoded inside the mutator rather than at call sites. Behavior preserving: transition semantics, publication order, payloads, and error classification are unchanged, andchatstateis untouched.Tests: per-endpoint tests that only re-proved the shared ritual were folded into one table-driven
TestChatMutatorcovering the ritual once (transition, reload, publish on success, no publish on failure, error translation) plus per-verb validation rows.Net diff: 4 files, +844 / -932 (net -88 across production and tests).
Validated with
go test ./coderd/x/chatd/...andgo test -race -count=3 -run TestChatMutator ./coderd/x/chatd. Dogfood UAT exercised every mutation verb end to end against a real deployment at this exact head and passed, including live-update checks on the open chat and the chat list after each verb and clean API errors on the error paths.