fix(botocore): report token usage for streamed Amazon Nova invoke_model calls #21872
All Vouch review confidence checks passed
Residual risk 0.26 = Change Risk (0.60) × (1 − Review Confidence (0.57)).
Review depth and reviewer attention state are adequate.
Model 1 · Change Risk (XGBoost)
Score: 0.60 · 130 lines diff across 1 files
Model 2 · Review Depth (DistilBERT)
Depth Score: 0.17 · 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.292
Shallow Review Depth
shallow_review_depth
0.289
Sensitive Paths
sensitive_paths
0.060
Ai Authored
ai_authored
0.050
Real PR Conversation Timeline
1 comments
"Review active on #21872"
general
weight: 0.35
wconti27
Description
Streamed Amazon Nova
invoke_model_with_response_streamcalls reported 0 input/output tokens in LLM Observability. Nova's final stream chunk carries zeros inamazon-bedrock-invocationMetricsand the real counts inmetadata.usage(including cache read/write counts). When the invocation metrics are both zero, usage is now read frommetadata.usage. Other providers are unchanged. The final chunk can also carry"metadata": null; that value is now treated as absent, so the invocation metrics are still used.Builds on #21074 by @pcbeingused333
Fixes #21073.
Testing
New cassette-based test
test_llmobs_amazon_nova_invoke_stream_token_usage; it fails before the change (0 != 4) and passes after.test_bedrock.pyandtest_bedrock_llmobs.pypass (80 passed).Risks
None. The fallback applies only when both invocation-metric counts are zero or missing. Null or non-dict
metadatano longer raises at the end of a stream.Additional Notes
🤖 Generated with Claude Code