`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. #30968 Move the Anthropic guard unit test into its own file
2. #30969 Move the Anthropic guard unit test into `chatsanitize`
3. #30970 Drop the Anthropic guard escalation passes
> Xum, an AI agent, opened this PR for @ibetitsmike and wrote this
description.