Skip to content

fix(py): lead Dev UI stacks with user frames, title boxed spans, and tighten error text - #115

Merged
huangjeff5 merged 9 commits into
mainfrom
fix/py-devui-error-display
Nov 13, 2026
Merged

huangjeff5 merged 9 commits into
mainfrom
fix/py-devui-error-display

Conversation

@huangjeff5

@huangjeff5 huangjeff5 commented Nov 12, 2026 •

Copy link
Copy Markdown
Collaborator

Improves error readability across the Dev UI trace viewer and model runner by trimming internal runtime frames, titling boxed spans with their failure cause, and harmonizing error strings.

Stacked on #113 (fix/py-devui-span-exception-events).

# --- BEFORE ---
# Tool stack trace in Dev UI:
#   File ".../genkit/_core/_action.py", line 184, in _invoke
#   File ".../genkit/_core/_telemetry/_http.py", line 160, in run_in_new_span
#   File "my_tool.py", line 12, in check_stock
#     raise ValueError('freezer offline')
#
# Boxed generate span heading in Dev UI Traces:
#   "Error"
#
# Reflection runner error heading:
#   "freezer offline: ConnectionError('freezer offline')"

# --- AFTER ---
# Tool stack trace in Dev UI:
#   File "my_tool.py", line 12, in check_stock
#     raise ValueError('freezer offline')
#
# Boxed generate span heading in Dev UI Traces:
#   "freezer offline"
#
# Reflection runner error heading:
#   "UNAVAILABLE: freezer offline"

Main Changes

  • Stack traces lead with the user's frame: Python tracebacks order outermost frames first, forcing developers to scroll through 6–10 Genkit internals (run_in_new_span, _run_with_span, _invoke) before seeing their tool or flow code. format_exception_stack trims leading frames under genkit/_core and genkit/_ai across each cause in the chain while preserving full stacks for errors originating entirely inside Genkit.
  • Boxed spans title with their failure message: When ai.generate() catches a tool failure and boxes it into a ModelResponse, the span completed without raising. Without an exception event, the Dev UI Traces tab fell back to titling the box "Error". set_state('error', message=...) now attaches an exception.message event so the trace viewer displays the actual failure cause.
  • Runner heading matches the trace status string: get_reflection_json() now formats GenkitError via str(error) (STATUS: message: cause), ensuring the Dev UI runner panel and the trace viewer display identical status strings rather than raw repr() dumps of cause exceptions.
  • Dropped redundant provider error reprs: When wrapping SDK exceptions (such as google-genai APIError) whose str() is a dict repr duplicating .message, GenkitError avoids repeating the message twice in the error title.

All unit tests pass.

1_stack_trimmed_user_frame 2_generate_span_titled 3_runner_error_status_prefix

Since 0.13.0 the Dev UI poster sent spans as OTLP/JSON to /api/otlp with
no events. The telemetry server's OTLP converter drops span events anyway,
and the Traces tab reads a non-model span's heading and stack only from its
exception event, so failed Python flow and tool spans showed "Error" and no
traceback.

Spans now POST TraceData to /api/traces, the shape JS and Go send and what
Python sent before 0.13. A raised error records exception.type, .message
(str(err)) and .stacktrace the way OTel's record_exception formats them,
stored as strings so finished spans hold no frames. Interrupts record no
event so the tool span still renders as Interrupted. Failures returned
without raising keep status but get no event. Logs stay on /api/otlp.
A boxed generate or a failed dotprompt returns instead of raising, so its
span had status text but no exception event, and the Dev UI Traces tab
titled it "Error". set_state('error', message=...) now adds an exception
event with that message. The boxed response holds no traceback, so the
event has no stack; the span that raised still has the full one. A raised
exception replaces it.
- Stack traces on spans and in the runner drop the leading frames under
  genkit/_core and genkit/_ai, per traceback in the cause chain, so a
  failed tool reads from the tool's own line instead of 6-10 runtime
  frames. A traceback that is all Genkit frames is kept whole.
- The runner heading for a GenkitError is str(error), the same
  `STATUS: message[: cause]` as the span's status.message and JS's
  `STATUS: message`, instead of `message: repr(cause)`.
- GenkitError skips the cause suffix when the cause's own .message is
  the message. A google-genai APIError's str() is that message again in
  a dict repr.
- Config bound errors say "got 99.0" once; the bounds message already
  names the value, so the config check doesn't append the input.
@huangjeff5
huangjeff5 added this pull request to stack #79 November 12, 2026 06:51
Base automatically changed from fix/py-devui-span-exception-events to main November 12, 2026 23:36
# Conflicts:
#	packages/genkit/src/genkit/_core/_error.py
#	packages/genkit/src/genkit/_core/_reflection.py
#	packages/genkit/src/genkit/_core/_reflection_v2.py
#	packages/genkit/src/genkit/_core/_telemetry/_http.py
#	packages/genkit/tests/genkit/core/telemetry/trace_data_encoder_test.py
@huangjeff5
huangjeff5 merged commit 17d3af5 into main Nov 13, 2026
20 checks passed
@huangjeff5
huangjeff5 deleted the fix/py-devui-error-display branch November 13, 2026 03:16
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.

2 participants