Skip to content

refactor(coderd): share the chat model config write error mapping - #31019

Open
ibetitsmike wants to merge 1 commit into
mainfrom
mike/chat-settings-shared-handlers-model-errors
Open

ibetitsmike wants to merge 1 commit into
mainfrom
mike/chat-settings-shared-handlers-model-errors

Conversation

@ibetitsmike

Copy link
Copy Markdown
Collaborator

Create, update, and delete of chat model configs each mapped their transaction errors to responses with their own switch. This PR moves update's mapping into writeChatModelConfigWriteError and calls it from all three handlers, with each handler's 500 message as an argument. It adds 33 lines and removes 69.

What changes: every handler now has every case of update's mapping. Create gains the 404 case, and delete gains the 412, 400, and 409 cases. The delete transaction returns none of those errors. Create returns a not-found error only if a row it reads disappears inside its transaction, which holds the organization's model config write lock; before, that was a 500.

Why it is safe: I ran 7 mutants of writeChatModelConfigWriteError and its callers with go test -overlay. The tests below fail on 5: skip the precondition check, return 500 for a provider model error, return 404 instead of 403 for an authorization error, return 500 for a not-found error, and change the 500 message. Two survive on main as well:

  • The 409 case: the only unique index besides the primary key allows one default config per organization, and every writer changes the default under the write lock, so no test can reach it.
  • The delete 500 message: no test makes delete fail with a 500. The message is the same literal as on main.

Review focus: the order of the 403 and 404 cases. httpapi.Is404Error also matches authorization errors, so the 403 case stays first, as in update's mapping.

Validation: on main and on this branch, go test ./coderd -run '^(TestCreateChatModelConfig|TestUpdateChatModel|TestDeleteChatModelConfig|TestChatModelConfigAudit|TestChatModelActionScopesWithOrgRead|TestCreateChatModelRejectsACLKeys|TestChatModelReasoningMode.*|TestChatModelACLShareDenied)$' -count=1 passes (10 tests, 103 with subtests). The pre-commit hook passed (make gen, formatting, golangci-lint, slim build).

Xum, an AI agent, opened this PR for @ibetitsmike and wrote this description.

Create, update, and delete of chat model configs each mapped transaction
errors to responses with their own switch. Share update's mapping in
writeChatModelConfigWriteError.
@ibetitsmike

Copy link
Copy Markdown
Collaborator Author

@codex review

Xum, an AI agent, requested this review for @ibetitsmike.

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 19, 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-10-19T22:49:50.185296Z 61b0f81 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. What shall we delve into next?

Reviewed commit: 61b0f81074

ℹ️ 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 October 19, 2026 22:48

This branch has not been deployed

No deployments
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