Skip to content

fix(agents): respect explicit user compat overrides for non-native openai-completions#44432

Merged
frankekn merged 2 commits intoopenclaw:mainfrom
cheapestinference:fix/respect-explicit-compat-overrides
Mar 13, 2026
Merged

fix(agents): respect explicit user compat overrides for non-native openai-completions#44432
frankekn merged 2 commits intoopenclaw:mainfrom
cheapestinference:fix/respect-explicit-compat-overrides

Conversation

@cheapestinference
Copy link
Copy Markdown
Contributor

Summary

  • normalizeModelCompat currently forces supportsUsageInStreaming: false and supportsDeveloperRole: false for all non-api.openai.com endpoints, even when the user has explicitly set these flags to true in their model config.
  • This change makes normalizeModelCompat honour explicit true overrides from the user's model compat definition, while keeping the default safe behaviour (force off) for endpoints without explicit config.
  • Users of OpenAI-compatible APIs that support stream_options: { include_usage: true } (e.g. vLLM, SGLang, LiteLLM, custom proxies) can now get proper token usage reporting by setting compat.supportsUsageInStreaming: true on their model definition.

Motivation

Many OpenAI-compatible backends correctly handle stream_options and 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

  • Updated existing tests: explicit true overrides are now respected instead of being silently overridden
  • Added new test: default behaviour (no explicit config) still forces flags off
  • All 34 model-compat tests pass
  • Verified end-to-end: custom provider with compat.supportsUsageInStreaming: true now receives stream_options: { include_usage: true } and reports correct token counts

🤖 Generated with Claude Code

@openclaw-barnacle openclaw-barnacle bot added agents Agent runtime and tooling size: XS labels Mar 12, 2026
@greptile-apps
Copy link
Copy Markdown
Contributor

greptile-apps bot commented Mar 12, 2026

Greptile Summary

This PR makes normalizeModelCompat honour explicit true overrides from a model's compat config for non-native OpenAI-completions endpoints, rather than blanket-forcing both supportsDeveloperRole and supportsUsageInStreaming to false. The change is narrowly scoped to src/agents/model-compat.ts and its test file.

Key observations:

  • Logic is correct. The new forcedDeveloperRole / forcedUsageStreaming boolean guards correctly implement "opt-in via explicit true; default to safe off". All four combinations (both set, one set, neither set) produce the expected output.
  • Tests are well-updated. Two existing tests that asserted the old "always force off" behaviour have been inverted to match the new semantics, and a new test covering the default (no compat) case has been added.
  • Minor style nit. forcedDeveloperRole || false and forcedUsageStreaming || false on lines 83–84 are redundant — both variables are already typed as boolean via the === true strict equality check.
  • Minor test gap. The test at line 265 (respects supportsUsageInStreaming: true) doesn't also assert that supportsDeveloperRole is still forced to false for the same model, leaving a small regression surface unverified.

Confidence Score: 4/5

  • This PR is safe to merge — the logic change is correct, well-tested, and strictly additive (opt-in only).
  • The implementation correctly handles all flag combinations, the default safe behaviour is preserved, and the test suite covers the new scenarios. Only minor style redundancies and a small test coverage gap were found — no logical or runtime errors.
  • No files require special attention.
Prompt To Fix All 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.

---

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

Comment on lines +83 to +84
supportsDeveloperRole: forcedDeveloperRole || false,
supportsUsageInStreaming: forcedUsageStreaming || false,
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Suggested change
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.

Comment on lines +265 to +274
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);
});
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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:

Suggested change
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.

@frankekn frankekn self-assigned this Mar 13, 2026
@openclaw-barnacle openclaw-barnacle bot added size: M app: macos App: macos and removed size: XS labels Mar 13, 2026
@frankekn frankekn force-pushed the fix/respect-explicit-compat-overrides branch from 8e34db9 to 78b559b Compare March 13, 2026 08:16
@openclaw-barnacle openclaw-barnacle bot added size: XS and removed app: macos App: macos size: M labels Mar 13, 2026
frankekn added a commit to cheapestinference/openclaw that referenced this pull request Mar 13, 2026
@openclaw-barnacle openclaw-barnacle bot added gateway Gateway runtime size: M and removed size: XS labels Mar 13, 2026
cheapestinference and others added 2 commits March 13, 2026 17:15
…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]>
@frankekn frankekn force-pushed the fix/respect-explicit-compat-overrides branch from 95332a6 to e2d9c2b Compare March 13, 2026 09:22
@openclaw-barnacle openclaw-barnacle bot added size: XS and removed gateway Gateway runtime size: M labels Mar 13, 2026
@frankekn frankekn merged commit 60cb1d6 into openclaw:main Mar 13, 2026
30 checks passed
@frankekn
Copy link
Copy Markdown
Contributor

Thanks @cheapestinference.

Landed in 60cb1d6 from e2d9c2b.

mrosmarin added a commit to mrosmarin/openclaw that referenced this pull request Mar 13, 2026
* 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)
  ...
hougangdev pushed a commit to hougangdev/clawdbot that referenced this pull request Mar 14, 2026
ecochran76 pushed a commit to ecochran76/openclaw that referenced this pull request Mar 14, 2026
Interstellar-code pushed a commit to Interstellar-code/operator1 that referenced this pull request Mar 16, 2026
sbezludny pushed a commit to sbezludny/openclaw that referenced this pull request Mar 27, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agents Agent runtime and tooling size: XS

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants