Repository navigation
fix(py): plugins classify only the failures they can name - #6586
Conversation
Since the action raises the body's exception, the plugin's status is what Retry and Fallback act on. Plugins now map provider HTTP statuses, provider error types, caller-input errors, malformed replies and credential errors, and never report OK or UNKNOWN for a failure. Raw network errors stay unclassified so Retry handles them and Fallback skips them.
There was a problem hiding this comment.
Code Review
This pull request standardizes and improves error classification and exception handling across multiple Genkit provider plugins, including Amazon Bedrock, Anthropic, Google GenAI, Ollama, OpenAI, and Vertex AI. The changes ensure that API, credential, and transport failures are mapped to standard GenkitError statuses (such as UNAUTHENTICATED, INVALID_ARGUMENT, RESOURCE_EXHAUSTED, FAILED_PRECONDITION, and INTERNAL) where appropriate, while allowing transient network or retryable errors to propagate raw so they can be retried. Additionally, mid-stream errors during streaming calls are now correctly classified, and extensive unit tests have been added to validate these error-mapping behaviors. I have no feedback to provide as there are no review comments.
…rors # Conflicts: # py/packages/genkit-anthropic/tests/anthropic_error_handling_test.py # py/packages/genkit-google-genai/src/genkit_google_genai/_evaluators/_evaluation.py # py/packages/genkit-google-genai/src/genkit_google_genai/_google.py # py/packages/genkit-google-genai/src/genkit_google_genai/_models/_embedder.py # py/packages/genkit-google-genai/src/genkit_google_genai/_models/_gemini.py # py/packages/genkit-google-genai/src/genkit_google_genai/_models/_veo.py # py/packages/genkit-google-genai/test/google_plugin_test.py # py/packages/genkit-google-genai/test/models/googlegenai_embedder_test.py # py/packages/genkit-openai/tests/openai_model_test.py
… into fix/py-plugins-classify-errors
A down or slow Ollama server is a transport failure with no reported status. Retry retries it; Fallback does not switch models on it.
…rors # Conflicts: # py/packages/genkit-ollama/tests/plugin_api_test.py # py/packages/genkit-vertexai/tests/model_garden/model_garden_test.py
…rors # Conflicts: # py/packages/genkit-amazon-bedrock/src/genkit_amazon_bedrock/models.py # py/packages/genkit-google-genai/src/genkit_google_genai/_interactions/_client.py
…nd mark every provider error
…rors # Conflicts: # py/packages/genkit-google-genai/src/genkit_google_genai/_models/_embedder.py
Since #6576,
ai.generateraises whatever the plugin raised: the plugin's status is the one Retry and Fallback act on. This PR fixes the first-party plugins that reported a status they didn't know (OK, UNKNOWN, INTERNAL for auth) or reported none where they did know one.Main Changes
GenkitErrorwhose status is in its list and treats anything else as unclassified (Retry retries, Fallback skips). Plugins now map a provider HTTP status, a provider error type, caller-input errors (INVALID_ARGUMENT), malformed replies (INTERNAL) and credential errors (UNAUTHENTICATED). Raw network errors (httpx, aiohttp, urllib3, an SDK'sAPIConnectionError,OllamaConnectionError) stay unclassified. A network blip is for Retry; Fallback should only switch models for a failure the plugin can name.overloaded_errorthat arrives mid-stream after a 200 came back asstatus='OK'. These now take the real status (HTTP status, or the in-band error type), or are re-raised raw when there isn't one.except Exceptionturned every failure into INTERNAL, including a missing ADC or a rejected token. Fallback then switched to the next model and hid the misconfiguration. A shared_auth.pymapsDefaultCredentialsError/RefreshErrorto UNAUTHENTICATED across the generate, stream, embed, cache, Veo, evaluator and lazy-client paths. A refresh that google.auth marksretryablestays raw so Retry still covers token-endpoint blips. Everything else from that catch-all is now re-raised raw.num_predictINTERNAL, so Retry repeated a request that can never succeed. Both are swapped. A media URL that returns 403, 404 or 410 (Gemini, Ollama) is INVALID_ARGUMENT, not NOT_FOUND, so Fallback doesn't switch models over a broken image link.list_actions, and OpenAI's in-band stream errors went through no mapping at all. They now go throughwrap_http_erroror the provider's error type. Bedrock's batch embedder now keepsretry_after_mswhen it re-wraps a throttle error, so Retry waits as long as AWS asked.Differs from Go
The rule matches Go's
WrapAPIErrorhelpers (compat_oai,anthropic,googlegenai): map the provider's reported status, leave transport errors raw, never emit UNKNOWN. Python goes further in three places:Not changed
OllamaConnectionErroris still a plainConnectionError, same as Go's Ollama plugin and every other plugin's transport errors. Retry retries it; Fallback does not switch models. An app that wants "local first, cloud on outage" catchesOllamaConnectionErroritself.ResponseError(status_code=-1)mid-stream, or an Anthropic stream error of an unknown type, has no status to report. Retry handles it.from_http_codestill returns UNKNOWN for an unlisted 4xx (e.g. 418). That's core behavior and out of scope here.Each fix has a test, and reverting any single fix fails at least one test. pyright, pyrefly and ty report the same counts as the base branch on the touched packages.