Repository navigation
fix(py)!: an action raises the exception its body raised - #6576
Merged
huangjeff5 merged 13 commits intoOct 7, 2026
Merged
Conversation
Contributor
There was a problem hiding this comment.
Code Review
This pull request refactors exception handling across Genkit actions, flows, tools, and middleware. Instead of wrapping action failures in a GenkitError, the original exceptions (such as ValueError, KeyError, or Interrupt) are now re-raised directly to the caller, while still preserving trace IDs where applicable. Additionally, unclassified provider SDK errors (like ConnectionError) are now treated as INTERNAL failures for fallback and retry policies. Review feedback suggests simplifying the trace ID update logic in get_reflection_json to avoid redundant object instantiation, and extracting the retry condition logic in _retry.py into a helper method for consistency with _fallback.py.
Running a flow, tool, model, or embedder now raises the body's own exception instead of GenkitError(INTERNAL, 'Error while running action <name>') with the original on .cause, so `except ValueError` works. GenkitError and PublicError keep their status as before. When tracing is on, the raised exception carries the run's trace id as `e.trace_id`. The Dev UI builds its error from the original exception, so it shows the body's message, and it always carries the run's trace id, including for a GenkitError the body raised. The Fallback and Retry middleware treat an exception that isn't a GenkitError as INTERNAL, so a provider ConnectionError still falls back or retries exactly when it did before.
huangjeff5
force-pushed
the
fix/py-action-raises-body-error
branch
from
October 6, 2026 06:37
9852477 to
d914db7
Compare
…ace ids - Fallback moves to the next model only on a classified GenkitError; a raw error propagates, same as Go's isFallbackRetryable and JS. - Retry retries an unclassified error regardless of statuses, same as Go and JS; statuses only gates GenkitError. - Action.run no longer writes trace_id onto the raised exception, same as Go. The trace id stays on the span and on ActionResponse.
…ry and Fallback status_matches(error, statuses, unclassified=...) decides both: a GenkitError by its status, a raw exception by the caller's unclassified answer (Retry: True, Fallback: False). Both default lists derive from TRANSIENT_STATUSES, so they can't drift.
huangjeff5
marked this pull request as ready for review
October 6, 2026 08:38
apascal07
approved these changes
Oct 6, 2026
…ix/py-action-raises-body-error # Conflicts: # py/packages/genkit/src/genkit/_core/_action.py # py/packages/genkit/src/genkit/_core/_error.py # py/packages/genkit/tests/genkit/core/error_test.py
…ix/py-action-raises-body-error
cabljac
added a commit
that referenced
this pull request
Oct 12, 2026
An action now raises its body's exception as is, not wrapped in a GenkitError (#6576). The two tests that pin infrastructure failures passing through a tool expect the raw RuntimeError and McpConnectionFailedError.
cabljac
added a commit
that referenced
this pull request
Oct 12, 2026
Main replaced the private programmable test model with the public genkit.testing.define_scripted_model, made ai.registry private (#6690), and lets an action raise its body's exception as is (#6576). The client tests use the scripted model and ai._registry, and expect the raw McpConnectionFailedError and McpConnectionClosedError from a tool run. Main also deleted py/tests/smoke, so the rebase drops this slice's edits there.
hilariie
pushed a commit
that referenced
this pull request
Oct 16, 2026
An action now raises its body's exception as is, not wrapped in a GenkitError (#6576). The two tests that pin infrastructure failures passing through a tool expect the raw RuntimeError and McpConnectionFailedError.
hilariie
pushed a commit
that referenced
this pull request
Oct 16, 2026
Main replaced the private programmable test model with the public genkit.testing.define_scripted_model, made ai.registry private (#6690), and lets an action raise its body's exception as is (#6576). The client tests use the scripted model and ai._registry, and expect the raw McpConnectionFailedError and McpConnectionClosedError from a tool run. Main also deleted py/tests/smoke, so the rebase drops this slice's edits there.
hilariie
pushed a commit
that referenced
this pull request
Oct 29, 2026
An action now raises its body's exception as is, not wrapped in a GenkitError (#6576). The two tests that pin infrastructure failures passing through a tool expect the raw RuntimeError and McpConnectionFailedError.
hilariie
pushed a commit
that referenced
this pull request
Oct 29, 2026
Main replaced the private programmable test model with the public genkit.testing.define_scripted_model, made ai.registry private (#6690), and lets an action raise its body's exception as is (#6576). The client tests use the scripted model and ai._registry, and expect the raw McpConnectionFailedError and McpConnectionClosedError from a tool run. Main also deleted py/tests/smoke, so the rebase drops this slice's edits there.
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.
When a model fails with an exception that has no status: Retry always retries it; Fallback never switches. A failed exception does not carry
trace_id. The id stays on the span and on a successfulActionResponse.Decisions
StreamingCallbackError(the caller's ownon_chunk) is never retried and never switches.get_reflection_json(..., trace_id=self.trace_id).