Skip to content

fix(pi-sdk): Fix nesting of child spans in tool spans - #2499

Merged
Aaron (btaaron) merged 3 commits into
mainfrom
aaron-bind-pi-tool-spans
Sep 18, 2026
Merged

Aaron (btaaron) merged 3 commits into
mainfrom
aaron-bind-pi-tool-spans

Conversation

@btaaron

@btaaron Aaron (btaaron) commented Sep 17, 2026

Copy link
Copy Markdown
Contributor

Unit flagged that Pi creates an automatic tool span, but currentSpan() inside the tool still returns the outer span, meaning nested spans get the wrong parent. This fix binds the existing tool span while its executor runs, preserving caller context and executor's return and error behavior. Fixes SDK-389

Tested

  • Identical harness reproduces incorrect parenting in 9/9 cases on Braintrust 3.30.0 and passes 9/9 against package built from 80af362c. All 53 context observations use correct tool span after fix. Covers overlapping sessions with reused call IDs, session reuse, nested traces, sync throw, async rejection, caller restoration
  • 14 new regression cases pass, covering both Pi stream properties, concurrent tools/prompts, executor semantics, missing/stale state, and instrumentation suppression
  • All 24 existing Pi end-to-end tests pass. SDK suite passes on Ubuntu and Windows with Node 20, 22, 24, and 26 (1911 SDK tests plus 61 automatic-instrumentation tests; 3 existing skips)

@btaaron
Aaron (btaaron) marked this pull request as ready for review September 17, 2026 19:13
@btaaron
Aaron (btaaron) enabled auto-merge (squash) September 17, 2026 19:22
@btaaron Aaron (btaaron) self-assigned this Sep 17, 2026
@lforst Luca Forstner (lforst) changed the title Keep Pi tool spans current during execution fix: Keep Pi tool spans current during execution Sep 18, 2026
@lforst Luca Forstner (lforst) changed the title fix: Keep Pi tool spans current during execution fix(pi-sdk): Fix nesting of child spans in tool spans Sep 18, 2026
@btaaron
Aaron (btaaron) merged commit fada38b into main Sep 18, 2026
57 checks passed
@btaaron
Aaron (btaaron) deleted the aaron-bind-pi-tool-spans branch September 18, 2026 12:47
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