fix(llmobs): keep streamed tool calls apart when the delta has no index #21111
All Vouch review confidence checks passed
Residual risk 0.32 = Change Risk (0.55) × (1 − Review Confidence (0.41)).
Review depth and reviewer attention state are adequate.
Model 1 · Change Risk (XGBoost)
Score: 0.55 · 355 lines diff across 4 files
Model 2 · Review Depth (DistilBERT)
Depth Score: 0.02 · 1 substantive comment(s)
Model 3 · Review Timing & Attention
Session adequacy: 100% · Reviewer familiarity: 35%
Bedrock Claude 3 · Risk Narration
(disconnected)
Groq Risk Narration
AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
Model 1 · Change Risk Attribution
SHAP Weights
Diff Size
diff_size
0.351
Shallow Review Depth
shallow_review_depth
0.344
Ai Authored
ai_authored
0.050
Real PR Conversation Timeline
1 comments
"Review active on #21111"
general
weight: 0.35
pcbeingused333
Description
Gemini's OpenAI-compatible endpoint (
https://generativelanguage.googleapis.com/v1beta/openai) streams each parallel tool call whole (id, name and arguments) in its own chunk and leavestool_calls[].indexunset.openai_construct_tool_call_from_streamed_chunklooks up the stored call byindex, so every call withindex=Noneis appended to the first one. The streamed LLMObs span then shows a single tool call with the first call's id and the arguments concatenated.Replaying a captured
gemini-3.5-flashstream with two parallelget_weathercalls through theopenaiclient andopenai_construct_message_from_streamed_chunks:When a delta has no index, an id that matches a call already collected continues that call, a new id starts a new call, and a delta without an id continues the latest call. Indexed deltas take the same path as before. The final sort used
x.get("index", 0), which raisesTypeErroronce two calls haveindex=None, so unindexed calls are now kept in arrival order after the indexed ones.The same reducer is used by the litellm integration and by AI Guard's OpenAI streaming evaluation, so those paths get the fix too (they are not covered by the tests below).
Testing
TestOpenAIConstructMessageWithUnindexedToolCallsintests/llmobs/test_integrations_utils.py:-
test_parallel_calls_without_index_stay_separate: the two-call Gemini shape. It fails onmain(one merged call) and passes with the fix.-
test_unindexed_fragment_without_id_or_name_continues_latest_call: an unindexed argument fragment without id or name is appended to the latest call.-
test_unindexed_fragments_repeating_the_same_id_continue_the_call: unindexed fragments that repeat the call's id on every chunk stay one call (as onmain).tests/llmobs/test_integrations_utils.py: 165 passed with the fix, vs 164 passed / 1 failed onmain.ruff check/ruff format --check(0.14.10) clean on the changed files.ddtrace/llmobssources (andddtrace/internal/utils/service.py) on top. The reducer is identical between 4.16.0 and main. The AI Guard streaming tests weren't run locally for the same reason. The full suite runs in this PR's CI.Risks
Low. Only deltas without an index take the new branch; OpenAI and other backends that send
indexbehave as before.Additional Notes
This change was made with Claude Code; the tests above were run on the branch to check it.
🤖 Generated with Claude Code