fix(coderd): preserve signed reasoning during provider-switch sanitization#27424
Open
ibetitsmike wants to merge 1 commit into
Open
fix(coderd): preserve signed reasoning during provider-switch sanitization#27424ibetitsmike wants to merge 1 commit into
ibetitsmike wants to merge 1 commit into
Conversation
…ation Provider-switch sanitization treated assistant rows whose model config was soft-deleted (e.g. by a model re-sync) as foreign because origin lookup used GetChatModelConfigByID, which filters deleted rows. It then stripped provider-executed tool blocks from the latest assistant message, mutating signed thinking blocks and causing Anthropic to reject every retry with "thinking blocks in the latest assistant message cannot be modified". Resolve origin identity with a new GetChatModelConfigByIDIncludeDeleted query that ignores enabled/deleted state, since a soft-deleted config still records which provider instance produced the row. As defense in depth, never strip rows in the trailing run of consecutive assistant rows when it carries Anthropic signed or redacted reasoning and the wire provider is Anthropic; that run serializes into the latest assistant message, which the API validates for replay fidelity. Rows or metadata that fail to parse inside that run fail closed and protect the run.
Collaborator
Author
|
@codex review |
|
Codex Review: Didn't find any major issues. Keep it up! 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". |
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.
Problem
Chats (including subagents) on dev.coder.com were permanently stuck with:
Anthropic validates that the latest assistant message replays byte-for-byte. Production logs and DB state show the failing chats hit this sequence on every generation attempt:
GetChatModelConfigByID, which filtersdeleted = FALSE. A model-config re-sync had soft-deleted the referenced config row, so resolution failed withErrNoRowseven though the row pointed at the sameai_provider_idas the active target config.web_searchtool blocks out of assistant rows, including the latest assistant message carrying signedthinkingblocks.Fix
GetChatModelConfigByIDIncludeDeletedquery and take onlyAIProviderID. A soft-deleted config still records which provider instance produced the row; enabled/deleted/model-resolvability gates are target-usability concerns and stay strict on the target path. Legacy configs without a provider FK remain fail-closed.model.Provider(), so Bedrock-routed Anthropic counts), never strip rows in the trailing run of consecutive assistant rows when that run carries Anthropic signed or redacted reasoning. That run serializes into the latest assistant message on the wire. Rows or reasoning metadata that fail to parse inside the run fail closed and protect it. A WARN log with aprotected_rowscount fires when the protection engages.Stripping only ever mutated in-memory prompt rows, never DB rows, so already-stuck chats recover on deploy without intervention.
Testing
GetChatModelConfigByIDIncludeDeleted(soft-deleted row hidden from the strict query, returned by the new one).coderd/x/chatd,chatprompt, anddbauthzsuites pass;make lintandmake genclean.