fix(agents): respect explicit user compat overrides for non-native openai-completions#44432
Conversation
Greptile SummaryThis PR makes Key observations:
Confidence Score: 4/5
Prompt To Fix All With AIThis is a comment left during a code review.
Path: src/agents/model-compat.ts
Line: 83-84
Comment:
**Redundant `|| false` on boolean expressions**
`forcedDeveloperRole` and `forcedUsageStreaming` are already guaranteed to be `boolean` (the result of a strict equality check `=== true`), so `|| false` is a no-op and can be dropped for clarity.
```suggestion
supportsDeveloperRole: forcedDeveloperRole,
supportsUsageInStreaming: forcedUsageStreaming,
```
How can I resolve this? If you propose a fix, please make it concise.
---
This is a comment left during a code review.
Path: src/agents/model-compat.test.ts
Line: 265-274
Comment:
**Partially-set compat override not fully asserted**
When only `supportsUsageInStreaming: true` is set, `supportsDeveloperRole` should still be forced to `false`. The test currently only checks `supportsUsageInStreaming`, leaving the complementary flag's behaviour unverified for this specific combination. Consider adding the assertion to catch a potential regression where the other flag slips through:
```suggestion
const normalized = normalizeModelCompat(model);
expect(supportsUsageInStreaming(normalized)).toBe(true);
expect(supportsDeveloperRole(normalized)).toBe(false);
```
How can I resolve this? If you propose a fix, please make it concise.Last reviewed commit: 6921b11 |
| supportsDeveloperRole: forcedDeveloperRole || false, | ||
| supportsUsageInStreaming: forcedUsageStreaming || false, |
There was a problem hiding this comment.
Redundant || false on boolean expressions
forcedDeveloperRole and forcedUsageStreaming are already guaranteed to be boolean (the result of a strict equality check === true), so || false is a no-op and can be dropped for clarity.
| supportsDeveloperRole: forcedDeveloperRole || false, | |
| supportsUsageInStreaming: forcedUsageStreaming || false, | |
| supportsDeveloperRole: forcedDeveloperRole, | |
| supportsUsageInStreaming: forcedUsageStreaming, |
Prompt To Fix With AI
This is a comment left during a code review.
Path: src/agents/model-compat.ts
Line: 83-84
Comment:
**Redundant `|| false` on boolean expressions**
`forcedDeveloperRole` and `forcedUsageStreaming` are already guaranteed to be `boolean` (the result of a strict equality check `=== true`), so `|| false` is a no-op and can be dropped for clarity.
```suggestion
supportsDeveloperRole: forcedDeveloperRole,
supportsUsageInStreaming: forcedUsageStreaming,
```
How can I resolve this? If you propose a fix, please make it concise.| it("respects explicit supportsUsageInStreaming true on non-native endpoints", () => { | ||
| const model = { | ||
| ...baseModel(), | ||
| provider: "custom-cpa", | ||
| baseUrl: "https://proxy.example.com/v1", | ||
| compat: { supportsUsageInStreaming: true }, | ||
| }; | ||
| const normalized = normalizeModelCompat(model); | ||
| expect(supportsUsageInStreaming(normalized)).toBe(true); | ||
| }); |
There was a problem hiding this comment.
Partially-set compat override not fully asserted
When only supportsUsageInStreaming: true is set, supportsDeveloperRole should still be forced to false. The test currently only checks supportsUsageInStreaming, leaving the complementary flag's behaviour unverified for this specific combination. Consider adding the assertion to catch a potential regression where the other flag slips through:
| it("respects explicit supportsUsageInStreaming true on non-native endpoints", () => { | |
| const model = { | |
| ...baseModel(), | |
| provider: "custom-cpa", | |
| baseUrl: "https://proxy.example.com/v1", | |
| compat: { supportsUsageInStreaming: true }, | |
| }; | |
| const normalized = normalizeModelCompat(model); | |
| expect(supportsUsageInStreaming(normalized)).toBe(true); | |
| }); | |
| const normalized = normalizeModelCompat(model); | |
| expect(supportsUsageInStreaming(normalized)).toBe(true); | |
| expect(supportsDeveloperRole(normalized)).toBe(false); |
Prompt To Fix With AI
This is a comment left during a code review.
Path: src/agents/model-compat.test.ts
Line: 265-274
Comment:
**Partially-set compat override not fully asserted**
When only `supportsUsageInStreaming: true` is set, `supportsDeveloperRole` should still be forced to `false`. The test currently only checks `supportsUsageInStreaming`, leaving the complementary flag's behaviour unverified for this specific combination. Consider adding the assertion to catch a potential regression where the other flag slips through:
```suggestion
const normalized = normalizeModelCompat(model);
expect(supportsUsageInStreaming(normalized)).toBe(true);
expect(supportsDeveloperRole(normalized)).toBe(false);
```
How can I resolve this? If you propose a fix, please make it concise.8e34db9 to
78b559b
Compare
…enai-completions
When a user explicitly sets `supportsUsageInStreaming: true` or
`supportsDeveloperRole: true` in their model compat config,
`normalizeModelCompat` now honours that choice instead of forcing
both flags off for all non-native openai-completions endpoints.
The default safe behaviour is unchanged: without an explicit opt-in
both flags are still forced off for non-api.openai.com backends.
This lets users of OpenAI-compatible APIs that do support
`stream_options: { include_usage: true }` (e.g. vLLM, SGLang,
custom proxies) get proper token usage reporting without patching
node_modules.
Co-Authored-By: Claude Opus 4.6 <[email protected]>
95332a6 to
e2d9c2b
Compare
|
Thanks @cheapestinference. |
* main: (168 commits) fix: stabilize macos daemon onboarding fix(ui): keep shared auth on insecure control-ui connects (openclaw#45088) docs(plugins): clarify workspace shadowing fix(node-host): harden perl approval binding fix(node-host): harden pnpm approval binding fix(discovery): add missing domain to wideArea Zod config schema (openclaw#35615) chore(gitignore): add docker-compose override (openclaw#42879) feat(ios): add onboarding welcome pager (openclaw#45054) fix(signal): add groups config to Signal channel schema (openclaw#27199) fix: restore web fetch firecrawl config in runtime zod schema (openclaw#42583) fix: polish Android QR scanner onboarding (openclaw#45021) fix(android): use Google Code Scanner for onboarding QR fix(config): add missing params field to agents.list[] validation schema (openclaw#41171) docs(contributing): update Android app ownership fix(agents): rephrase session reset prompt to avoid Azure content filter (openclaw#43403) test(config): cover requiresOpenAiAnthropicToolPayload in compat schema fixture fix(agents): respect explicit user compat overrides for non-native openai-completions (openclaw#44432) Android: fix HttpURLConnection leak in TalkModeVoiceResolver (openclaw#43780) Docker: add OPENCLAW_TZ timezone support (openclaw#34119) fix(agents): avoid injecting memory file twice on case-insensitive mounts (openclaw#26054) ...
…enai-completions (openclaw#44432) Reviewed-by: @frankekn
…enai-completions (openclaw#44432) Reviewed-by: @frankekn
…enai-completions (openclaw#44432) Reviewed-by: @frankekn (cherry picked from commit 60cb1d6)
…enai-completions (openclaw#44432) Reviewed-by: @frankekn
Summary
normalizeModelCompatcurrently forcessupportsUsageInStreaming: falseandsupportsDeveloperRole: falsefor all non-api.openai.comendpoints, even when the user has explicitly set these flags totruein their model config.normalizeModelCompathonour explicittrueoverrides from the user's modelcompatdefinition, while keeping the default safe behaviour (force off) for endpoints without explicit config.stream_options: { include_usage: true }(e.g. vLLM, SGLang, LiteLLM, custom proxies) can now get proper token usage reporting by settingcompat.supportsUsageInStreaming: trueon their model definition.Motivation
Many OpenAI-compatible backends correctly handle
stream_optionsand return usage data in streaming chunks. The current blanket override prevents users from enabling this even when they know their endpoint supports it, leaving token counts at zero.The user already has a config mechanism (
models[].compat) to declare endpoint capabilities — this PR makes that mechanism effective.Test plan
trueoverrides are now respected instead of being silently overriddencompat.supportsUsageInStreaming: truenow receivesstream_options: { include_usage: true }and reports correct token counts🤖 Generated with Claude Code