fix(ai,coding-agent): deliver Anthropic error status and recover a native tool-search 400 on the same model - #1487
Merged
Merged
Conversation
…ame model A native tool-search 400 hard-errored the model and the hard-error branch always switched to the next fallback candidate, demoting the user mid-task even though the same model succeeds once native injection is off (senpi #1482). The adapter's 400 fallback now records a one-shot pending flag on the provider-scoped ToolSearchService, and the session's hard-error branch consumes it first: no tryFallback(), a zero-delay auto_retry_start, and the shared continuation on the same model. A second rejection takes the ordinary hard-error chain.
… retry Wiring case: emitBeforeProviderRequest with a supported Anthropic model and an MCP feed injects native search, after_provider_response 400 sets the pending flag once, it is consumed once, and injection stays off. Session cases: one same-model retry with no fallback events, and a normal fallback switch on the second consecutive 400.
…ecovery # Conflicts: # packages/coding-agent/CHANGELOG.md
This was referenced Sep 8, 2026
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.
Summary
Fixes the remaining native tool-search 400 cluster:
onResponse/after_provider_response, because the SDK rejects HTTP errors instead of returning a Response and the only callback ran on success. The native tool-search adapter's permanent 400 fallback was dead code on the live error path.Changes
packages/ai/src/api/anthropic-messages.ts: when the completeretryProviderRequestoperation finally rejects, a numeric HTTP status carried by the SDK error is delivered once throughoptions.onResponsebefore the error propagates; errors without a status (network, aborts) report nothing rather than a fabricated code.tool-search/service.ts: the provider-scope-scopedToolSearchServicecarries a one-shot pending flag (noteNativeInjectionFailure/takeNativeInjectionFailure) recording that a native-injected request was rejected.tool-search/index.ts: the adapter's 400onFallbackrecords that reason on the service.agent-session.ts: the hard-error branch consumes the flag first — notryFallback(), a zero-delayauto_retry_start, and the shared continuation on the SAME model (the adapter is already disabled for the session, and the retry rebuilds the request so the fix(ai): fold gateway-namespaced Anthropic tool references onto the request's tools #1480 reference repair applies). The flag is consumed once, so a second rejection takes the ordinary hard-error chain.Evidence (all remote, mengmotaMac, bun 1.4.0)
933307abb6):onResponsecalled 0 times on 400/500 rejections;takeNativeInjectionFailure is not a function;noteNativeInjectionFailure is not a function. The status-less case passes without fabrication.anthropic-on-response-error3/3;test/tool-search/native-anthropic.test.ts16/16;test/suite/retry-fallback-hard-error.test.ts11/11 (2 new: one same-model retry with zero fallback events, one normal switch on the second 400); ai integrity + deferred-tools + provider-native-replay 52/52; retry-fallback-hardening + refusal + mcp/native-anthropic 20/20.bun run checkgreen; changelog gate PASS (nearest trackers for both production paths +[Unreleased]entries).Closes #1481, closes #1482.
Summary by cubic
Fixes native tool-search 400 recovery so the same model is retried in place instead of demoting the user to a fallback, and delivers Anthropic HTTP error statuses that previously never reached the response hook.
onResponse/after_provider_responsenever fired on error and the native adapter's 400 fallback was dead code.onResponsebefore propagating; errors without a status (network, aborts) report nothing.Closes #1481 and #1482.
Written for commit 6bedcc1. Summary will update on new commits.