fix: restore streaming usage for openai-compatible providers#50045
fix: restore streaming usage for openai-compatible providers#50045xiwuqi wants to merge 8 commits into
Conversation
Greptile SummaryThis PR fixes a bug where non-native The fix is a single two-line change in Key points:
Confidence Score: 4/5
Last reviewed commit: "fix: restore streami..." |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 0dc136c8f6
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 3880391f5b
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: b8a42a4a66
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
|
+1 for merging this. We're hitting this exact issue with Bailian (DashScope) providers on OpenClaw 2026.3.13. Confirmed in production:
The default-to- Suggestion: consider adding a log warning when This PR + #50845 together would fully resolve the compaction failure chain for non-native providers. Would love to see both merged. |
jalehman
left a comment
There was a problem hiding this comment.
Changes Requested
Thank you for this contribution! We've reviewed this PR and have some feedback before it can move forward.
Generic default-on usage streaming is still too broad
This change flips supportsUsageInStreaming back on for generic non-native openai-completions providers by default, but that is the same broad behavior we previously had to revert after several OpenAI-compatible backends rejected stream_options with 400/422 responses. As written, the new carveouts are still narrower than the set of providers and base URL patterns that were already known to fail.
Please keep the default conservative for those generic backends, or expand the carveouts and regression coverage so the previously broken cases are explicitly protected before broadening the default again. In particular, we need confidence that LM Studio, LocalAI, TGI, Ollama /v1, Mistral API, and any similar known-bad paths will not start sending include_usage again.
Once these are addressed, we'll re-review. Feel free to ask questions if anything is unclear.
|
Thanks, this makes sense. I checked the current Given that, I am not going to keep pushing the default wider in this PR. If it makes sense later, I can revisit this as a narrower allowlist/provider-specific change with explicit regression coverage for the known-bad paths you called out. |
|
I've pushed a narrower follow-up on top of this PR. What changed:
Validation I reran locally:
If this direction looks right, I'm happy to keep iterating from here. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 7d3d175dad
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| const provider = normalizeProviderId(model.provider); | ||
| if (provider === "azure-openai") { | ||
| return !usesLegacyAzureChatCompletionsApiVersion(model.baseUrl); | ||
| } |
There was a problem hiding this comment.
Detect Azure custom endpoints by host, not only provider ID
Modern Azure OpenAI endpoints added through the supported custom-provider flow still won't pick up this compat default. src/commands/onboard-custom.ts:576-583 stores Azure URLs under a generated provider ID derived from the endpoint host, not the literal azure-openai, but shouldEnableStreamingUsageByDefault() only takes the Azure branch when normalizeProviderId(model.provider) === "azure-openai". Those onboarded Azure configs therefore fall through to the generic false path and continue dropping streamed usage unless the user manually adds compat.supportsUsageInStreaming: true.
Useful? React with 👍 / 👎.
7d3d175 to
43234da
Compare
43234da to
f53d67e
Compare
|
Closing this one to stop iterating on a stale/conflicting branch. The current branch is far behind main and still carries the older broadening direction that maintainers asked to keep conservative. If I revisit this issue, I’ll do it as a fresh, narrower PR from current main with provider/endpoint-specific coverage instead of continuing to patch this branch. |
Summary
openai-completionsmodels were normalized withcompat.supportsUsageInStreaming = false, so OpenClaw stopped sendingstream_options: { include_usage: true }for OpenAI-compatible streaming requests.normalizeModelCompat()now keeps streaming usage enabled by default for non-nativeopenai-completionsmodels, while still forcingdeveloperrole and JSONstrictmode off unless explicitly opted in.api.openai.combehavior is unchanged, and providers/models that explicitly setcompat.supportsUsageInStreaming: falsestill opt out.Change Type (select all)
Scope (select all touched areas)
Linked Issue/PR
User-visible / Behavior Changes
OpenAI-compatible providers that stream token usage in a final usage-only chunk now keep nonzero usage accounting by default, without requiring users to manually set
compat.supportsUsageInStreaming: true.Security Impact (required)
Yes/No): NoYes/No): NoYes/No): NoYes/No): NoYes/No): NoYes, explain risk + mitigation:Repro + Verification
Environment
openai-completions)baseUrl, no explicitcompat.supportsUsageInStreamingSteps
openai-completionsprovider (custom/proxy/OpenAI-compatible).compat.supportsUsageInStreaming.Expected
stream_options: { include_usage: true }.Actual
supportsUsageInStreaming: false.stream_options.include_usage, so streamed runs recorded zero usage unless users explicitly opted in.Evidence
Human Verification (required)
What you personally verified (not just CI), and how:
src/agents/model-compat.test.tsnow confirms generic custom OpenAI-compatible providers default tosupportsUsageInStreaming: true.streamSimpleOpenAICompletions()end-to-end with a mocked SSE response and verifies bothstream_options.include_usageand the final persisted usage values.compat.supportsUsageInStreaming: falsestill stays false.api.openai.commodels remain untouched.supportsDeveloperRoleandsupportsStrictModeare still forced off for non-native endpoints when not explicitly set.pnpm buildis blocked in this Windows environment becausecanvas:a2ui:bundleshells out tobash scripts/bundle-a2ui.shandbashis unavailable here.pnpm checkfails in this environment on pre-existing missing optional extension dependencies unrelated to this diff.Review Conversations
Compatibility / Migration
Yes/No): YesYes/No): NoYes/No): NoFailure Recovery (if this breaks)
compat.supportsUsageInStreaming: falseon the affected provider/model.src/agents/model-compat.ts,src/agents/model-compat.test.tsstream_options.include_usagewould start erroring unless it already has (or is given) an explicit opt-out.Risks and Mitigations
stream_options: { include_usage: true }.compat.supportsUsageInStreaming: falseremains supported and is preserved exactly as before.AI Assistance
This change was prepared with AI assistance via Codex, then reviewed, validated, and submitted by the author.