Skip to content

fix(py)!: an action raises the exception its body raised - #6576

Merged
huangjeff5 merged 13 commits into
fix/py-flow-io-validatedfrom
fix/py-action-raises-body-error
Oct 7, 2026
Merged

huangjeff5 merged 13 commits into
fix/py-flow-io-validatedfrom
fix/py-action-raises-body-error

Conversation

@huangjeff5

@huangjeff5 huangjeff5 commented Oct 6, 2026 •

Copy link
Copy Markdown
Contributor

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 successful ActionResponse.

# raw ConnectionError + Fallback(models=['backup'])       -> FAILED, backup never called
# Retry(statuses=['UNAVAILABLE']) + raw ConnectionError   -> still retries
# flow -> Receipt returning 'nope'                        -> INVALID_OUTPUT, trace_id is None

Decisions

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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.

@huangjeff5
huangjeff5 added this pull request to stack #6583 October 6, 2026 04:43
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
huangjeff5 force-pushed the fix/py-action-raises-body-error branch from 9852477 to d914db7 Compare October 6, 2026 06:37
@huangjeff5
huangjeff5 removed this pull request from stack #6583 October 6, 2026 06:38
@huangjeff5
huangjeff5 added this pull request to stack #6548 October 6, 2026 06:38
…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
huangjeff5 marked this pull request as ready for review October 6, 2026 08:38
Comment thread py/samples/ollama-sample/src/main.py Resolved
@huangjeff5
huangjeff5 merged commit 30cbeb1 into main Oct 7, 2026
40 of 51 checks passed
@huangjeff5
huangjeff5 deleted the fix/py-action-raises-body-error branch October 7, 2026 19:23
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.
cabljac added a commit that referenced this pull request Oct 12, 2026
The host tests use genkit.testing.define_scripted_model and
ai._registry (#6690), and expect the raw connection errors from a tool
run now that an action no longer wraps its body's exception (#6576).
cabljac added a commit that referenced this pull request Oct 13, 2026
The host tests use genkit.testing.define_scripted_model and
ai._registry (#6690), and expect the raw connection errors from a tool
run now that an action no longer wraps its body's exception (#6576).
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.
cabljac added a commit that referenced this pull request Oct 19, 2026
The host tests use genkit.testing.define_scripted_model and
ai._registry (#6690), and expect the raw connection errors from a tool
run now that an action no longer wraps its body's exception (#6576).
cabljac added a commit that referenced this pull request Oct 19, 2026
The host tests use genkit.testing.define_scripted_model and
ai._registry (#6690), and expect the raw connection errors from a tool
run now that an action no longer wraps its body's exception (#6576).
cabljac added a commit that referenced this pull request Oct 19, 2026
The host tests use genkit.testing.define_scripted_model and
ai._registry (#6690), and expect the raw connection errors from a tool
run now that an action no longer wraps its body's exception (#6576).
cabljac added a commit that referenced this pull request Oct 20, 2026
The host tests use genkit.testing.define_scripted_model and
ai._registry (#6690), and expect the raw connection errors from a tool
run now that an action no longer wraps its body's exception (#6576).
cabljac added a commit that referenced this pull request Oct 22, 2026
The host tests use genkit.testing.define_scripted_model and
ai._registry (#6690), and expect the raw connection errors from a tool
run now that an action no longer wraps its body's exception (#6576).
cabljac added a commit that referenced this pull request Oct 22, 2026
The host tests use genkit.testing.define_scripted_model and
ai._registry (#6690), and expect the raw connection errors from a tool
run now that an action no longer wraps its body's exception (#6576).
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.
hilariie pushed a commit that referenced this pull request Oct 29, 2026
The host tests use genkit.testing.define_scripted_model and
ai._registry (#6690), and expect the raw connection errors from a tool
run now that an action no longer wraps its body's exception (#6576).
hilariie pushed a commit that referenced this pull request Oct 30, 2026
The host tests use genkit.testing.define_scripted_model and
ai._registry (#6690), and expect the raw connection errors from a tool
run now that an action no longer wraps its body's exception (#6576).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants