Skip to content

feat(thinking): allow custom model compat to opt into xhigh - #48904

Closed
Milchstrassse wants to merge 6 commits into
openclaw:mainfrom
Milchstrassse:feat/xhigh-custom-model-compat
Closed

Milchstrassse wants to merge 6 commits into
openclaw:mainfrom
Milchstrassse:feat/xhigh-custom-model-compat

Conversation

@Milchstrassse

Copy link
Copy Markdown

Summary

Describe the problem and fix in 2–5 bullets:

  • Problem: custom models.providers.*.models[*] definitions could not opt into xhigh; validation and help paths only trusted built-in/provider-advertised support and rejected or downgraded those refs.
  • Why it matters: OpenAI-compatible custom endpoints that genuinely support stronger reasoning were forced down to high and surfaced misleading guidance.
  • What changed: added compat.supportsXHighThinking, taught thinking helpers to honor config/catalog overrides in a browser-safe way, and threaded config-aware hints/validation through reply, gateway, agent, cron, TUI, and llm-task entry points with regression coverage.
  • What did NOT change (scope boundary): no CI/format rescue commits from the superseded branch, no provider-runtime allowlist changes, and no local project execution in this environment.

AI-assisted: Yes (Codex)
Testing: Untested locally; statically reviewed only (project execution was intentionally not run in this environment)
Prompts/session logs: available in the Codex session history

Change Type (select all)

  • Bug fix
  • Feature
  • Refactor
  • Docs
  • Security hardening
  • Chore/infra

Scope (select all touched areas)

  • Gateway / orchestration
  • Skills / tool execution
  • Auth / tokens
  • Memory / storage
  • Integrations
  • API / contracts
  • UI / DX
  • CI/CD / infra

Linked Issue/PR

User-visible / Behavior Changes

  • Custom model definitions can now opt into xhigh by setting models.providers.*.models[*].compat.supportsXHighThinking: true.
  • Config can explicitly disable xhigh for an otherwise provider-advertised model with compat.supportsXHighThinking: false.
  • /think help, validation errors, gateway session patches, agent CLI validation, cron fallback, and llm-task errors now reflect config-aware xhigh support.

Security Impact (required)

  • New permissions/capabilities? (Yes/No) No
  • Secrets/tokens handling changed? (Yes/No) No
  • New/changed network calls? (Yes/No) No
  • Command/tool execution surface changed? (Yes/No) No
  • Data access scope changed? (Yes/No) No
  • If any Yes, explain risk + mitigation: N/A

Repro + Verification

Environment

  • OS: macOS
  • Runtime/container: not run locally
  • Model/provider: static review only
  • Integration/channel (if any): reply pipeline, gateway session patch, TUI, agent CLI, cron isolated agent, llm-task
  • Relevant config (redacted): models.providers.robot.models[0].compat.supportsXHighThinking = true

Steps

  1. Add a custom model definition with compat.supportsXHighThinking: true.
  2. Hit any xhigh validation/help path such as /think, gateway session patching, agent CLI validation, or llm-task.
  3. Flip the same flag to false on a provider-advertised xhigh model and repeat the same paths.

Expected

  • xhigh is surfaced and accepted for explicit custom opt-ins.
  • Explicit false suppresses xhigh and updates the hint/error text consistently.

Actual

  • Not executed locally; verified statically that schema, thinking resolution, downgrade checks, and user-facing hints now read the same config-aware support source.

Evidence

Attach at least one:

  • Failing test/log before + passing after
  • Trace/log snippets
  • Screenshot/recording
  • Perf numbers (if relevant)

Static inspection snippets:

$ git diff --check --cached
(no output)

$ git diff --cached --stat
17 files changed, 418 insertions(+), 31 deletions(-)

Human Verification (required)

What you personally verified (not just CI), and how:

  • Verified scenarios: traced compat.supportsXHighThinking from config/schema into supportsXHighThinking(), then through reply handling, session patch validation, agent CLI checks, cron downgrade logic, TUI help/completions, and llm-task validation.
  • Edge cases checked: catalog overrides take precedence over config for the same ref, explicit false suppresses built-in/provider-advertised xhigh, and the thinking helper stays browser-safe by consuming injected config instead of runtime config lookup.
  • What you did not verify: no local code execution, tests, builds, CI reruns, or codex review --base origin/main in this environment.

Review Conversations

  • I replied to or resolved every bot review conversation I addressed in this PR.
  • I left unresolved only the conversations that still need reviewer or maintainer judgment.

If a bot review conversation is addressed by this PR, resolve that conversation yourself. Do not leave bot review conversation cleanup for maintainers.

Compatibility / Migration

  • Backward compatible? (Yes/No) Yes
  • Config/env changes? (Yes/No) Yes (new optional compat.supportsXHighThinking)
  • Migration needed? (Yes/No) No
  • If yes, exact upgrade steps: N/A

Failure Recovery (if this breaks)

  • How to disable/revert this change quickly: remove compat.supportsXHighThinking from the affected model config or revert this commit.
  • Files/config to restore: models.providers.*.models[*].compat, src/auto-reply/thinking.ts, and the caller validations listed in this PR.
  • Known bad symptoms reviewers should watch for: xhigh appears for a model that should stay at high, or a config-opted model still gets downgraded/rejected.

Risks and Mitigations

List only real risks for this PR. Add/remove entries as needed. If none, write None.

  • Risk: a misconfigured custom model can advertise xhigh even if the backend does not actually support it.
  • Mitigation: opt-in remains explicit per model, explicit false still disables xhigh, and all validation/help paths now consistently read the same override source.
  • Risk: browser-facing code could accidentally depend on runtime config access while reading custom overrides.
  • Mitigation: the thinking helper only consumes injected config snapshots via ThinkingSupportSource and does not call runtime config loaders.

@openclaw-barnacle openclaw-barnacle Bot added gateway Gateway runtime extensions: llm-task Extension: llm-task agents Agent runtime and tooling size: M labels Mar 17, 2026
@greptile-apps

greptile-apps Bot commented Mar 17, 2026

Copy link
Copy Markdown
Contributor

Greptile Summary

This PR extends the thinking-level system so that custom model definitions (under models.providers.*.models[*]) can explicitly opt in or out of xhigh via a new compat.supportsXHighThinking: boolean flag. The change introduces a ThinkingSupportSource abstraction that carries both a config snapshot and a catalog reference into all thinking-level helpers, then threads this source through every validation and hint path across reply, gateway, agent, cron, TUI, and llm-task. The approach is backward compatible, browser-safe, and well-covered by new tests.

Key observations:

  • The override resolution priority (catalog beats config, both beat provider-runtime) is consistent between resolveExplicitXHighOverride and collectExplicitXHighRefs.
  • All 8+ call sites that previously called supportsXHighThinking / formatThinkingLevels / formatXHighModelHint without a source have been updated.
  • One logic gap: supportsXHighThinking returns the explicit config override before checking isBinaryThinkingProvider, so a model configured with supportsXHighThinking: true under a binary-thinking provider (e.g. zai) would pass all xhigh validation gates while listThinkingLevelLabels would still return ["off", "on"], creating an inconsistency that could let xhigh through to the backend for a provider that doesn't support it. Adding an early isBinaryThinkingProvider guard would close this gap.
  • Minor UX: formatXHighModelHint uses "including …" phrasing that implies the config-defined models are part of the provider-advertised set, which can be misleading when no provider-runtime models support xhigh.

Confidence Score: 3/5

  • Safe to merge with the binary-thinking-provider inconsistency addressed, as the misconfiguration required to trigger it is unlikely in practice.
  • The overall approach is sound, all existing xhigh validation paths are consistently updated, and the new code is well-tested. Score is lowered from 5 due to the supportsXHighThinking / isBinaryThinkingProvider ordering gap, which means a misconfigured binary-thinking provider model could bypass xhigh validation and cause unexpected backend errors, and the formatXHighModelHint phrasing that can produce misleading error messages for users with only config-defined xhigh models.
  • src/auto-reply/thinking.ts — supportsXHighThinking should check isBinaryThinkingProvider before returning an explicit config override.
Prompt To Fix All With AI
This is a comment left during a code review.
Path: src/auto-reply/thinking.ts
Line: 204-212

Comment:
**Explicit config override bypasses binary-thinking provider guard**

`supportsXHighThinking` returns the explicit config/catalog override immediately without first checking `isBinaryThinkingProvider`. This means that if a user (or catalog) configures `compat.supportsXHighThinking: true` for a provider that `isBinaryThinkingProvider` recognises as binary (e.g. `zai`), the function returns `true`, while `listThinkingLevelLabels` (which checks `isBinaryThinkingProvider` first) would still return `["off", "on"]`.

The practical consequence is that all the validation paths that gate on `supportsXHighThinking` alone — `agent-command.ts`, `get-reply-run.ts`, `directive-handling.impl.ts`, `sessions-patch.ts`, `cron/isolated-agent/run.ts`, and `llm-task-tool.ts` — would allow `xhigh` through for a misconfigured binary-thinking model, while the formatted level list would not include it and could confuse callers downstream.

Consider adding an early guard:

```
export function supportsXHighThinking(
  provider?: string | null,
  model?: string | null,
  source?: ThinkingSupportSource,
): boolean {
  if (isBinaryThinkingProvider(provider, model)) {
    return false;
  }
  const explicitOverride = resolveExplicitXHighOverride(provider, model, source);
  if (typeof explicitOverride === "boolean") {
    return explicitOverride;
  }
  // ... rest of provider-runtime lookup
}
```

This also makes `supportsXHighThinking` and `listThinkingLevelLabels` agree for all inputs.

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/auto-reply/thinking.ts
Line: 270-276

Comment:
**Potentially misleading "including" phrasing in hint**

When explicit refs exist, the hint is formatted as:

```
"provider models that advertise xhigh reasoning (including robot/gpt-5.4)"
```

The word "including" implies `robot/gpt-5.4` is a member of the "provider models that advertise xhigh reasoning" set, when in reality it is separately opted in via config. If no provider-runtime models actually support `xhigh` in the current deployment (only the custom one does), the phrasing is misleading — a user reading the error might look for `robot/gpt-5.4` in a provider catalogue and not find it there.

Consider a phrasing that explicitly distinguishes the two sources, e.g.:

```
"provider models that advertise xhigh reasoning, or config-defined models: robot/gpt-5.4"
```

or simply listing only the config-defined models when `explicitRefs` is non-empty and no enumerable provider-runtime list is available.

How can I resolve this? If you propose a fix, please make it concise.

Last reviewed commit: 94b0917

Comment thread src/auto-reply/thinking.ts Resolved
Comment thread src/auto-reply/thinking.ts Resolved
@wufunc

wufunc commented Mar 18, 2026

Copy link
Copy Markdown

I tested this against a real custom provider setup and the direction in this PR looks right to me.

Concrete repro from my side:

  • custom provider: gmn
  • model: gmn/gpt-5.4
  • global config: agents.defaults.thinkingDefault = "xhigh"
  • current behavior on main: /think / /thinking reports:
Current thinking level: high.
Options: off, minimal, low, medium, high, adaptive.

So the underlying issue is real for config-defined custom models, and I agree with the design choice here: explicit opt-in via models.providers.*.models[*].compat.supportsXHighThinking = true is safer than inferring xhigh support purely from the model id.

While comparing the call sites against this diff, I noticed two user-visible surfaces that still seem uncovered:

  1. src/auto-reply/commands-registry.data.ts
    The /think command arg choices still call listThinkingLevels(provider, model) without passing config context. That means native command choice menus may still omit xhigh even after the text-command path is fixed.

  2. src/acp/translator.ts
    ACP session presentation still builds availableLevelIds from listThinkingLevels(row.modelProvider, row.model) without config context, so ACP / control-session mode pickers may still miss xhigh for config-defined custom models.

One more edge case I would strongly recommend handling before merge:

  • supportsXHighThinking() should short-circuit binary-thinking providers before honoring explicit config/catalog overrides. Otherwise a misconfigured binary provider could pass xhigh validation while its visible level list still behaves like a binary provider.

Overall: the main approach in this PR matches the problem I reproduced locally, but I think the native command choices + ACP presentation + binary-provider guard should be covered so the user-facing behavior is consistent everywhere.

@Milchstrassse
Milchstrassse force-pushed the feat/xhigh-custom-model-compat branch from 94b0917 to fe33c21 Compare March 19, 2026 09:36
@Milchstrassse

Copy link
Copy Markdown
Author

Addressed the remaining review gaps in fe33c21:

  • guard supportsXHighThinking() against binary-thinking providers before explicit overrides
  • make the xhigh hint wording distinguish provider-advertised support from config-defined opt-ins
  • thread config-aware thinking levels into native /think command choices
  • thread config-aware thinking levels into ACP session mode presentation
  • add targeted regression coverage for the binary-provider case, native command choices, and ACP session modes

I also rebased the branch onto current main, so GitHub should refresh mergeability and rerun checks from the new head.

Testing note: I did not run project code locally in this environment; verification here was static review only.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

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.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: fe33c21d0e

ℹ️ About Codex in GitHub

Codex has been enabled to automatically 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 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment on lines +181 to +183
return collectExplicitXHighRefs(source)
.filter((entry) => entry.supported)
.map((entry) => entry.ref);

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.

P2 Badge Exclude binary providers from xhigh hint candidates

supportsXHighThinking now correctly blocks xhigh for binary-thinking providers, but this hint path only filters by the raw supported flag from config/catalog. If a user sets compat.supportsXHighThinking: true on a binary provider model (for example a zai/* entry), formatXHighModelHint({ config }) will still advertise that ref as xhigh-capable even though every validator rejects xhigh for it. That creates contradictory guidance in /think and error messages; the hint list should also enforce the same binary-provider gate used by supportsXHighThinking.

Useful? React with 👍 / 👎.

@clawsweeper

clawsweeper Bot commented Apr 28, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: keeping this open for maintainer follow-up; there is still a little grit to resolve.

Keep this PR open. Current main has a provider-profile-based thinking architecture, but it still does not implement the PR’s central behavior: allowing a custom models.providers.*.models[*] definition to opt into xhigh through compat.supportsXHighThinking, or an equivalent config/catalog path that exposes xhigh for custom OpenAI-compatible model refs. The PR discussion also includes a concrete reproduction from a real custom provider setup, so this is not low-signal cleanup.

Best possible solution:

Keep this PR open for maintainer review or contributor refresh. The best path is to adapt the custom-model xhigh opt-in to current main’s resolveThinkingProfile/thinkingLevels architecture, choose the public config contract, carry the relevant model compat/catalog data into thinking policy resolution, update the strict and generated config schemas plus docs, and add focused regression coverage across reply, gateway session patching, ACP/TUI presentation, agent CLI, cron, and llm-task.

What I checked:

  • PR discussion confirms the user problem and review state: The PR body describes custom models.providers.*.models[*] definitions being unable to opt into xhigh; wufunc reproduced the issue with gmn/gpt-5.4 and thinkingDefault = "xhigh"; the author later addressed review gaps in fe33c21, including binary-provider guards, native command choices, ACP presentation, and tests. The latest ClawSweeper comment also kept the PR open for the same missing core behavior. (02c10d73a99e)
  • Config type still lacks the requested public field: ModelCompatConfig includes supportedReasoningEfforts, reasoningEffortMap, and related compat fields, but not supportsXHighThinking, so the exact config key proposed by the PR is not in the current TypeScript config contract. (src/config/types.models.ts:57, f256eeba431b)
  • Strict config schema still rejects the proposed key: ModelCompatSchema is strict and enumerates accepted compat keys. It includes supportedReasoningEfforts and reasoningEffortMap, but not supportsXHighThinking. The generated schema likewise has no supportsXHighThinking entry under model compat. (src/config/zod-schema.core.ts:187, f256eeba431b)
  • Thinking support is provider-profile/catalog based, not config-compat based: resolveThinkingProfile accepts only provider, model, and optional catalog; it consults provider thinking hooks, binary hooks, and legacy provider supportsXHighThinking. supportsXHighThinking(provider, model) is just a wrapper over that profile and has no config source parameter. (src/auto-reply/thinking.ts:133, f256eeba431b)
  • Catalog path cannot carry per-model compat today: ThinkingCatalogEntry and ModelCatalogEntry carry provider/id/reasoning-style metadata only. buildConfiguredModelCatalog reads configured models but drops compat, so current catalog-aware thinking cannot see a per-model custom xhigh opt-in. (src/agents/model-selection-shared.ts:769, f256eeba431b)
  • Current user-facing surfaces use the provider policy consistently but still miss custom compat opt-in: Gateway rows expose thinkingLevels from listThinkingLevelOptions, llm-task validates through api.runtime.agent.resolveThinkingPolicy, and agent-command rejects unsupported explicit thinking levels. Those paths are consistent with the current provider profile architecture, but none read custom model compat overrides. (src/gateway/session-utils.ts:1079, f256eeba431b)

Remaining risk / open question:

  • The PR predates current main’s provider-owned resolveThinkingProfile and gateway thinkingLevels architecture, so a refresh should adapt to that model rather than reintroducing older config-aware helper threading unchanged.
  • Maintainers need to decide the public API shape: keep the proposed compat.supportsXHighThinking, map existing compat.supportedReasoningEfforts into thinking profiles, or introduce a broader configured thinking-profile field.
  • Any config opt-in must keep binary-provider guards, hints, validators, and runtime payload mapping aligned so a misconfigured custom model does not advertise xhigh where validators reject it, or pass validation where the provider cannot handle it.

Codex review notes: model gpt-5.5, reasoning high; reviewed against f256eeba431b.

@steipete

Copy link
Copy Markdown
Contributor

Thanks @Milchstrassse. I landed a maintainer rewrite of this in #74273, now on main as 93d5cd1.

The landed version keeps the fix focused on configured custom-model compat: compat.supportedReasoningEfforts now flows through the model catalog, /think and Gateway/session validation, agent CLI validation/defaulting, and plugin runtime thinking policy, with regression coverage for those paths.

Closing this PR as superseded by #74273.

@steipete steipete closed this Apr 29, 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 extensions: llm-task Extension: llm-task gateway Gateway runtime size: L

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants