Skip to content

refactor(coderd/x/chatd): centralize chat mutations behind a single mutator - #28756

Open
ibetitsmike wants to merge 5 commits into
mainfrom
mike/chatd-mutator
Open

refactor(coderd/x/chatd): centralize chat mutations behind a single mutator#28756
ibetitsmike wants to merge 5 commits into
mainfrom
mike/chatd-mutator

Conversation

@ibetitsmike

Copy link
Copy Markdown
Collaborator

Chat mutation endpoints in coderd/x/chatd/chatd.go each hand-assembled the same ritual: lock the chat, validate, run the chatstate.ChatMachine transition, 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. The Server methods 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, and chatstate is untouched.

Tests: per-endpoint tests that only re-proved the shared ritual were folded into one table-driven TestChatMutator covering 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/... and go 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.

Xum (AI) authored this PR on behalf of @ibetitsmike.

@ibetitsmike

Copy link
Copy Markdown
Collaborator Author

@codex review

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Aug 29, 2026

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review Completed 2026-08-29T13:25:38.922105Z 116d0c2 Draft marked ready
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. More of your lovely PRs please.

Reviewed commit: 116d0c21c9

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

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
ibetitsmike marked this pull request as ready for review August 29, 2026 13:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant