Repository navigation
Fail fast on permanent HTTP errors from Gemini Interactions, Agents and Files calls - #135
Merged
brianstrauch merged 2 commits intoOct 22, 2026
Conversation
…nd Files calls The Interactions and Agents activities raise google-genai's vendored client errors (BadRequestError, NotFoundError, ...), which are not genai.errors.APIError, and the Files and File Search store activities let genai.errors.APIError escape unclassified. Only the two models activities mapped errors, so a 400/401/403/404 from the other activities was retried by the default policy until the activity timed out, against the README's promise that non-transient statuses fail the workflow fast. Add a context manager that maps both error families to ApplicationError with the same retryable set (408, 429, 5xx) and use it in those activities.
avanish-garg
marked this pull request as ready for review
October 22, 2026 10:18
brianstrauch
enabled auto-merge (squash)
October 22, 2026 15:25
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.
What was changed
_classify_status_errorand_classify_errorsin_gemini_activity.py._classify_errorsis a context manager that mapsgenai.errors.APIErrorthrough the existing_classify_api_error, and the vendored client's status errors (BadRequestError,NotFoundError,RateLimitError, ...) to anApplicationErrorwith the error's class name astypeand the same retryable set (408, 429, 500, 502, 503, 504). Everything else, including connection errors and timeouts that carry no HTTP status, is re-raised unchanged and stays retryable.status_codeof 400 or more instead of importinggoogle.genai._gaos.lib.compat_errors, a private module path.gemini_interactions_*/gemini_agents_*activities and the four Files / File Search store activities (gemini_files_upload,gemini_files_download,gemini_files_register,gemini_file_search_stores_upload) now run their SDK call inside it. The two models activities are untouched.Why?
The README says non-transient statuses fail the workflow fast, but only
models.*did. A 400/401/403/404 from Interactions, Agents or Files was retried by the default policy until the activity timed out (8 requests in 8 seconds in the repro in the issue), so a bad argument or a revoked key looked like a hung workflow.Checklist
Closes [Bug] google_genai: a permanent 4xx from the Interactions, Agents and Files APIs is retried until the activity times out #134
How was this tested:
New tests in
tests/test_gemini.pyuse a local HTTP server that answers every request with one status and a realgenai.Clientpointed at it: all 14 activities above return a non-retryableApplicationErrorfor a 400 (parametrized, run throughActivityEnvironment); 401/403/404 oninteractions.createare non-retryable with the righttypeafter a single request; 429 and 503 stay retryable; unit tests for the classifier (6 permanent statuses, 6 transient statuses, errors without a status); and one workflow test whereinteractions.createagainst a 400 fails the workflow with a non-retryableBadRequestErrorafter exactly 1 HTTP request. Onmain(install rebuilt withmake syncand checked against the source) all 34 new tests fail; with the changemake lintis clean andmake testpasses (110, 34 of them new). Retry-After is not honoured, same as the existing models classifier. Not run against the real Gemini API.Any docs updates needed?
No. The README "Retries & errors" section already describes this behaviour; it now holds for Interactions, Agents and Files as well.