← Back to Pull requests

fix(llmobs): keep streamed tool calls apart when the delta has no index #22270

Open
unknown opened this pull request with 255 lines diff across 3 files
View on GitHub
unknown unknown commented on Dec 01, 2026 22:00 UTC
Author

Description

Re-opening #21111 from a branch in this repository with signed commits. The change is the original contributor's, rebased onto current main as a single commit that keeps Alex Castillo as author.

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 leaves tool_calls[].index unset. openai_construct_tool_call_from_streamed_chunk looked up the stored call by index, so every call with index=None was appended to the first one, and the streamed LLMObs span showed a single tool call with concatenated arguments.

When a delta has no index, an id that matches a collected call continues that call, a new id starts a new call, and a delta without an id continues the latest call. Indexed deltas behave as before. The final sort now keeps unindexed calls in arrival order after the indexed ones, since None can't be compared with None.

The same reducer is used by the LiteLLM integration and AI Guard's OpenAI streaming evaluation, so those paths get the fix too.

Customer impact

Parallel tool calls streamed by OpenAI-compatible backends that omit tool_calls[].index (such as Gemini's endpoint) now appear as separate tool calls with their own ids and arguments. A release note is included.

Testing

New TestOpenAIConstructMessageWithUnindexedToolCalls in tests/llmobs/test_integrations_utils.py covers separate parallel calls, id-less continuation, repeated-name continuation, interleaved fragments rejoined by id, and repeated ids.

Risks

Low. Only deltas without an index take the new branch. Calls from backends that send empty or missing ids still merge, as before.

Additional Notes

Original PR: https://github.com/DataDog/dd-trace-py/pull/21111 (fork PR, unsigned commits).

Claude session: 07f47f22-4d15-4fbc-b026-f1f4daafed1e
Resume: claude --resume 07f47f22-4d15-4fbc-b026-f1f4daafed1e

🤖 Generated with Claude Code

Diff: 255 lines (+191 / -64) across 3 files Reviewer: gnufede Review duration: 3895m
All Vouch review confidence checks passed
Residual risk 0.24 = Change Risk (0.44) × (1 − Review Confidence (0.47)). Review depth and reviewer attention state are adequate.
Model 1 · Change Risk (XGBoost)
Score: 0.44 · 255 lines diff across 3 files
0.44
Model 2 · Review Depth (DistilBERT)
Depth Score: 0.02 · 1 substantive comment(s)
0.02
Model 3 · Review Timing & Attention
Session adequacy: 100% · Reviewer familiarity: 35%
46%
Bedrock Claude 3 · Risk Narration
(disconnected)
Groq
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
Shallow Review Depth shallow_review_depth
0.344
Diff Size diff_size
0.332
Ai Authored ai_authored
0.050
Real PR Conversation Timeline
1 comments
"Review active on #22270"
general weight: 0.35
Reviewers
Assignees
Unassigned
Labels
risk: low confidence: 46.7% reviewed
Vouch Risk Breakdown
AI-powered review risk analysis
Change Risk
Change Risk · Model 1 (XGBoost)
Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
Score: 44.1% (MEDIUM) · Higher = larger blast radius
44.1%
Review Confidence
Review Confidence · Models 2 & 3
Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
Score: 46.7% · Lower = rushed or shallow review
46.7%
Residual Risk
Residual Risk · Core Equation
Residual = Change × (1 − Confidence)
Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
Score: 23.5% · Safe to merge
23.5%