Repository navigation
fix(py): give each tool-loop turn its own generate span in traces - #64
Merged
Merged
Conversation
cabljac
approved these changes
Nov 10, 2026
huangjeff5
force-pushed
the
fix/py-trace-generate-per-turn-spans
branch
from
November 10, 2026 19:41
12539a8 to
1cb3887
Compare
huangjeff5
enabled stacked auto-merge (squash)
November 10, 2026 19:41
This was referenced Nov 15, 2026
Merged
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.
Each tool-loop turn after the first now gets its own
generatespan, nested under the turn before it. Before, every turn's model call sat flat under the one outergenerate, so a 3-turn call showed three model spans side by side and a failure on turn 3 painted only the outer span red.Changes
generatespan per follow-up turn:generate_turnruns the next turn insiderun_in_new_span('generate', ..., action_type='util'). Turn n+1'swrap_generatemiddleware, model call, and tools all sit inside it. Turn 3 nests under turn 2, and so on.error(and stacked PR fix(py): Dev UI traces show why generate failed, where it started, and interrupted tools #63 writes the failure cause ontogenkit:errorandstatus.messagefor each failedgeneratespan).response.text,finish_reason, andmessagesare unchanged. With no instrumentation configured, the extra span is a no-op.Breaking changes
None. The trace has more spans, nested. Return values and public APIs are unchanged.
Cross-SDK
Matches JS (
generateHelperopens ageneratespan per turn before runningwrapGeneratehooks and recurses):WrapGeneratechain, whereas Python follows JS and opens the turn span outsidewrap_generateso every turn is guaranteed ageneratespan even when a middleware short-circuits or raises before callingnext(), and turnNhas the same shape as turn0(the post-hook request is already recorded on the model span).step_name: JS names the span fromstepName; Python ignoresstep_nametoday and leaves that for a follow-up so this PR stays focused on per-turn span nesting.