Repository navigation
fix(openai): Record tool calls from streamed Chat Completions output - #8058
ericapisani wants to merge 2 commits into
Conversation
Streamed Chat Completions spans only collected delta.content, so tool call deltas were dropped and gen_ai.response.tool_calls was never set. A stream that only produced tool calls also recorded an empty string as gen_ai.response.text. Accumulate tool call deltas per choice and tool call index, keeping arguments as the raw string, and set them as tool calls behind the same data collection / PII gate as the response text. Skip the response text when no content was streamed. Refs PY-3004
|
bugbot run |
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 1 potential issue.
❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.
Want reviews to match your repository better? Bugbot Learning can learn team-specific rules from PR activity. A team admin can enable Learning in the Cursor dashboard.
Reviewed by Cursor Bugbot for commit fe498b2. Configure here.
Coverage Results 📊✅ 138594 passed | ⏭️ 8620 skipped | Total: 147214 | Pass Rate: 94.14% | Execution Time: 469m 16s 📊 Comparison with Base Branch
All tests are passing successfully. ✅ Patch coverage is 100.00% (36 of 36 changed executable lines covered; target 80%). Changed files with executable lines (1)
Coverage diff@@ Coverage Diff @@
## master #8058 +/-##
==========================================
+ Coverage 90.25% 90.28% +0.03%
==========================================
Files 202 202 —
Tracked lines 26660 26709 +49
Branches 9926 9982 +56
==========================================
+ Hits 24062 24113 +51
+ Misses 2598 2596 -2
- Partials 1510 1513 +3Generated by Coverage Action |
With n > 1, OpenAI streams one choice per chunk, but the stream iterators keyed text and tool call deltas by the choice's position within the chunk. Every choice landed on position 0, so tool calls from different choices were merged into one corrupted entry and the response texts were concatenated. Key the text buffer and tool call deltas by choice.index instead, and order the recorded tool calls by choice and tool call index rather than by when they were first seen. Update the single-response streaming fixtures, which used increasing choice indices for fragments of the same response. Refs PY-3004

Description
Stacked on #8057. Streamed Chat Completions spans only collected
delta.content, so tool call deltas were dropped andgen_ai.response.tool_callswas never set. A stream that only produced tool calls also recorded an empty string asgen_ai.response.text.Accumulate tool call deltas per choice and tool call index, keeping arguments as the raw string, and set them as tool calls behind the same data collection / PII gate as the response text. Skip the response text when no content was streamed.
Issues