fix(retry): lowercase header keys and surface Gemini RetryInfo - #363
Open
someotherdustin wants to merge 2 commits into
Open
someotherdustin wants to merge 2 commits into
someotherdustin wants to merge 2 commits into
Conversation
Gemini's real 429 retry hint is a structured RetryInfo detail on genai.APIError, not a header, so toProviderErr previously dropped it entirely and left ResponseHeaders nil. Parse it and synthesize a lowercase retry-after header so retry.go's getRetryDelayInMs picks it up like it does for every other provider. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01GHeU92PFdTi47wa2zCMS1o
toHeaderMap kept http.Header's canonical MIME casing (e.g. "Retry-After") in its output map while only lowercasing a throwaway copy of the input, so retry.go's exact-case "retry-after"/ "retry-after-ms" lookups never matched. Lowercase the output keys directly so the existing retry-after handling actually engages. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01GHeU92PFdTi47wa2zCMS1o
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.
Fantasy's retry handling looks up response headers by exact lowercase key (
"retry-after","retry-after-ms"), but two provider error paths never produced those keys, so retry-after hints from Anthropic, OpenAI, and Gemini were silently ignored.toHeaderMapnever lowercased its own outputproviders/anthropic/error.goandproviders/openai/error.goboth had atoHeaderMapthat copiedhttp.Header's canonical MIME casing (e.g."Retry-After") into its output map, while lowercasing a throwaway copy of the input map instead.retry.go's exact-case lookups never matched, so the retry-after handling never engaged for these two providers.Fixed by lowercasing the output keys directly.
Gemini's retry hint is structured, not a header
Gemini doesn't send a
Retry-Afterheader on 429s — the real hint is agoogle.rpc.RetryInfodetail ongenai.APIError.providers/google/error.go'stoProviderErrdropped it entirely and leftResponseHeadersnil.Added
retryHeadersFromDetailsto find theRetryInfodetail, parse itsretryDelayduration, and synthesize a lowercaseretry-afterheader soretry.go'sgetRetryDelayInMspicks it up the same way it does for the other providers.Testing
go build ./...andgo vet ./...passgo test ./providers/anthropic/... ./providers/openai/... ./providers/google/...pass, including new regression tests:TestToHeaderMap_LowercasesKeys(anthropic, openai)TestToProviderErr_SurfacesRetryInfoDelay,TestToProviderErr_NoRetryInfoLeavesHeadersNil(google)golangci-lint runon the touched packages: 0 issuesNew-feature discussion: not applicable (bug fix).
AI assistance: this patch and its tests were prepared with Claude Code.
🤖 Generated with Claude Code
https://claude.ai/code/session_0167DoqhYHRGBgqFUChZ9hPA