Skip to content

Fail fast on permanent HTTP errors from Gemini Interactions, Agents and Files calls - #135

Merged
brianstrauch merged 2 commits into
temporalio:mainfrom
avanish-garg:fix/google-genai-permanent-errors
Oct 22, 2026
Merged

brianstrauch merged 2 commits into
temporalio:mainfrom
avanish-garg:fix/google-genai-permanent-errors

Conversation

@avanish-garg

Copy link
Copy Markdown
Contributor

What was changed

  • New _classify_status_error and _classify_errors in _gemini_activity.py. _classify_errors is a context manager that maps genai.errors.APIError through the existing _classify_api_error, and the vendored client's status errors (BadRequestError, NotFoundError, RateLimitError, ...) to an ApplicationError with the error's class name as type and 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.
  • The vendored errors are matched on an integer status_code of 400 or more instead of importing google.genai._gaos.lib.compat_errors, a private module path.
  • The 10 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.
  • No change to payloads, activity names or the public API.

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

  1. Closes [Bug] google_genai: a permanent 4xx from the Interactions, Agents and Files APIs is retried until the activity times out #134

  2. How was this tested:
    New tests in tests/test_gemini.py use a local HTTP server that answers every request with one status and a real genai.Client pointed at it: all 14 activities above return a non-retryable ApplicationError for a 400 (parametrized, run through ActivityEnvironment); 401/403/404 on interactions.create are non-retryable with the right type after 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 where interactions.create against a 400 fails the workflow with a non-retryable BadRequestError after exactly 1 HTTP request. On main (install rebuilt with make sync and checked against the source) all 34 new tests fail; with the change make lint is clean and make test passes (110, 34 of them new). Retry-After is not honoured, same as the existing models classifier. Not run against the real Gemini API.

  3. Any docs updates needed?
    No. The README "Retries & errors" section already describes this behaviour; it now holds for Interactions, Agents and Files as well.

…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
avanish-garg marked this pull request as ready for review October 22, 2026 10:18
@avanish-garg
avanish-garg requested a review from a team as a code owner October 22, 2026 10:18

@brianstrauch brianstrauch left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you!

@brianstrauch
brianstrauch enabled auto-merge (squash) October 22, 2026 15:25
@brianstrauch
brianstrauch merged commit 5e91c26 into temporalio:main Oct 22, 2026
15 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug] google_genai: a permanent 4xx from the Interactions, Agents and Files APIs is retried until the activity times out

2 participants