FallbackChatClient: classify transport-level failures as transient#427
Merged
Conversation
The SDK retry policy can give up on a transport-level failure (DNS, TCP reset, "Resource temporarily unavailable") with "Retry failed after N tries." — no HTTP response is received, so ClientResultException.Status is 0 and HttpRequestException.StatusCode is null. The previous classifier required a known HTTP status code and mapped 0/null to Unknown, which re-throws immediately and skips the configured fallback model. Now Status==0 ClientResultException, null-StatusCode HttpRequestException, inner SocketException/IOException, and the "Retry failed after" / "temporarily unavailable" message wrappers all classify as Transient, so the Balanced tier actually falls through to OpenRouter when Azure's endpoint is unreachable. Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
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
ClientResultExceptionwithStatus == 0(no HTTP response received). The previous classifier required a known HTTP status, mapped 0/null toUnknown, and re-threw immediately — so the Balanced tier never fell back to OpenRouter when Azure's endpoint was unreachable.ClassifyExceptionnow treats four previously-Unknown shapes asTransient:ClientResultExceptionwithStatus == 0HttpRequestExceptionwithStatusCode == nullSocketExceptionorIOException"Retry failed after"or"temporarily unavailable"(catch-all wrapper)Retry failed after 4 tries. (Resource temporarily unavailable (rocky-ml1nznjr-eastus2.cognitiveservices.azure.com:443))).Background
A subagent fan-out + synthesis run failed end-to-end against the Balanced-tier Azure endpoint with the message above. OpenRouter is configured as the Balanced fallback but was never tried — both the subagent's own LLM call and the synthesis call gave up after the SDK's internal retries, because
FallbackChatClientcouldn't recognize the resulting exception as transient.Test plan
dotnet test tests/RockBot.Llm.Tests/RockBot.Llm.Tests.csproj— 134/134 passFallbackChatClient: falling back from … to …) the next time Azure throttles the Balanced endpoint🤖 Generated with Claude Code