Skip to content

refactor(coderd/x/chatd/chatsanitize): drop Anthropic guard escalation passes - #30970

Draft
ibetitsmike wants to merge 3 commits into
mike/chatsanitize-guard-test-movefrom
mike/chatsanitize-guard-drop-escalation
Draft

ibetitsmike wants to merge 3 commits into
mike/chatsanitize-guard-test-movefrom
mike/chatsanitize-guard-drop-escalation

Conversation

@ibetitsmike

@ibetitsmike ibetitsmike commented Oct 18, 2026 •

Copy link
Copy Markdown
Collaborator

ApplyAnthropicProviderToolGuard now validates the result of its targeted repair once, then returns it or fails closed. This removes 163 production lines (2 added): the escalation that ran after a failed repair (an all-messages repair, then two strip passes) and its helpers isSafeAnthropicProviderToolPrompt, providerExecutedToolMessageIndexes, stripAnthropicProviderToolHistoryFromMessages and addAnthropicProviderToolSanitizationStats, plus their internal tests. git grep finds no other callers.

Why it is safe

The escalation ran but could never repair a prompt. SanitizeAnthropicProviderToolHistory loops until nothing is left to remove outside the last assistant message when that message carries signed or redacted reasoning, so after the targeted repair any violation left is in that message. Every later pass skips that message, so the guard failed anyway.

  • A differential test (not committed) ran the old and new guard on 1,000,000 random prompts and on every prompt the existing chatsanitize, chatloop and chatd Anthropic tests pass in. Outputs and errors matched in 1,000,000 of 1,000,000. 200,020 of 1,000,000 prompts reached the escalation; 0 came out repaired.
  • New subtest invalid pair in latest signed assistant fails closed pins the failure path (nil prompt, ErrAnthropicProviderToolPromptUnsafe, log fields). It passes before and after; no other test covered that path.
  • New sanitizer row drops provider result without output text takes over the one deleted assertion no other test made: it kills the mutant that keeps an empty-output provider result as empty text. The log detail cap test stays. All 12 mutants of the code the deleted tests touched fail a remaining test.

Review focus

Failures log less: the fallback and strip warnings are gone, and the error log drops immutable_latest_signed_assistant (always true), no longer says "nuclear strip", and its message_index values point into the prompt the guard validated.

Validation

  • go test ./coderd/x/chatd/chatsanitize/... ./coderd/x/chatd/chatloop/... -count=1, go test ./coderd/x/chatd/ -run 'Anthropic|Guard|Sanitiz' -count=1 -p 4 -parallel 4, go vet, golangci-lint on chatsanitize: pass.

Stack

This stack moves the Anthropic guard unit test into chatsanitize, then deletes the guard escalation that can never repair a prompt.

  1. test(coderd/x/chatd): move the Anthropic guard unit test into its own file #30968 Move the Anthropic guard unit test into its own file
  2. test(coderd/x/chatd): move the Anthropic guard unit test into chatsanitize #30969 Move the Anthropic guard unit test into chatsanitize
  3. refactor(coderd/x/chatd/chatsanitize): drop Anthropic guard escalation passes #30970 Drop the Anthropic guard escalation passes

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

@ibetitsmike
ibetitsmike added this pull request to stack #30971 October 18, 2026 15:57
@ibetitsmike ibetitsmike changed the title mike/chatsanitize guard drop escalation refactor(coderd/x/chatd/chatsanitize): drop Anthropic guard escalation passes Oct 18, 2026
@ibetitsmike

Copy link
Copy Markdown
Collaborator Author

@codex review

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 18, 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-18T17:35:58.223979Z 8d6cf8e Manual request
ℹ️ 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. Keep it up!

Reviewed commit: d4c3aa1474

ℹ️ 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

Copy link
Copy Markdown
Collaborator Author

@codex review

Xum, an AI agent, requested this review for Mike.

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Keep them coming!

Reviewed commit: 8d6cf8e360

ℹ️ 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".

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