fix: accept Chat Completions streaming usage options - #914
Conversation
|
Warning Review limit reachedNext included review available in 34 seconds. View limit detailsLimit details: You’ve used the included review currently available. You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository. Review configuration: ⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (9)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
|
@opencode-agent Review exact current head |
|
Reusable conflict resolver stopped fail-closed. Executable or structured-data conflicts require semantic resolution at exact head |
|
Reusable conflict resolver stopped fail-closed. Exact PR head: Executable or structured-data conflicts require semantic resolution:
|
| and isinstance(cost, dict) | ||
| and cost.get("measurement_status") == "measured" | ||
| and isinstance(usage, dict) |
There was a problem hiding this comment.
🟡 Cached streams fabricate provider usage
On a cached conducted stream, chat_completion_chunks emits measured zero-token usage although no provider ran. Clients mistake cache metadata for provider-reported usage.
Prompt for agents
Prevent chat_completion_chunks from treating cache ledger usage as provider-reported usage. CostRoutingCoordinator.complete creates a measured zero-token cache record for cache hits, so cost.measurement_status alone cannot prove that result.usage came from a provider. Preserve enough provenance in the completion result, or explicitly gate out cache_status == "hit", and add an HTTP or unit regression test for stream_options.include_usage=true on a cached conducted response.
Was this helpful? React with 👍 or 👎 to provide feedback.
| choices = chunk.get("choices") | ||
| usage = chunk.get("usage") | ||
| if isinstance(usage, dict): | ||
| self._local.usage = usage | ||
| choices = chunk.get("choices") or [{}] | ||
| if choices == []: | ||
| continue | ||
| if not isinstance(choices, list) or not choices: | ||
| continue |
There was a problem hiding this comment.
| if stream and include_usage: | ||
| raise RequestError( | ||
| 400, | ||
| "invalid_stream_options", | ||
| "stream_options.include_usage=true is not supported with tools or response_format", | ||
| ) |
There was a problem hiding this comment.
Summary
stream_options.include_usage=trueon/v1/chat/completions.include_obfuscation=trueand unsupported Responses stream flags fail-closed.This fixes the exact upstream contract failure observed by
ContextualWisdomLab/accounting-information-platform#39: Strix sentstream_options.include_usage=trueand the gateway returnedinvalid_stream_options400. No provider fallback or gate bypass is changed.Validation
2526 passedruff,compileall, andgit diff --checkpassed