Repository navigation
fix: retry Gemini server errors and fall back to other models (#250) - #270
Open
mecampbellsoup wants to merge 1 commit into
Open
mecampbellsoup wants to merge 1 commit into
mecampbellsoup wants to merge 1 commit into
Conversation
…tomates#250) A 503 "high demand" on the default model failed the whole run, even though the upload was done and an older model was answering. Retry 5xx on the same upload with backoff, then ask WATCH_GEMINI_FALLBACK_MODELS in order; the report names the model that answered and the ones that failed. Auth, rejected and network errors still stop at once. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01JzgQzQPSrKcadVCMTgMyse
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.
Fixes #250.
A 503 "high demand" from the default Gemini model fails the whole run on the first try, even after the upload has finished and while older models are answering normally.
What changes
WATCH_GEMINI_RETRIESsets the count (default2,0disables).WATCH_GEMINI_FALLBACK_MODELSare asked in order (defaultgemini-3.5-flash,gemini-2.5-flash; empty disables).--engine local.ask()is untouched. The newask_with_recovery()wraps it, and failures now raise aGeminiError(aSystemExitsubclass that carries its category), so existing callers and tests behave as before.How it was checked
With a free-tier key on 2026-11-10, a two-token text request got HTTP 503 from
gemini-3.7-flash,gemini-3.8-flashandgemini-flash-lateston every try (3/3 each). On the Interactions API's agentic path that the skill uses,gemini-3.5-flashandgemini-2.5-flashanswered 2/2 each, whilegemini-3.7-flashreturned 503 in under half a second. That matches the table in the #250 comment.The real run of this branch, on a 3:22 CNBC clip, with default settings:
pytest -q: 262 passed. The new tests cover retry with backoff on the same upload, fallback once retries are spent, 429 moving on without a retry, auth/rejected/network errors stopping at once, every model failing, the config settings, and the report line.🤖 Generated with Claude Code
https://claude.ai/code/session_01JzgQzQPSrKcadVCMTgMyse