Skip to content

Keep Pi tool spans current during execution - #2499

Open
Aaron (btaaron) wants to merge 2 commits into
mainfrom
aaron-bind-pi-tool-spans
Open

Aaron (btaaron) wants to merge 2 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 (1,911 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
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.

1 participant