Skip to content

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

Closed
Milchstrassse wants to merge 16 commits into
openclaw:mainfrom
Milchstrassse:feat/configurable-xhigh-thinking-support
Closed

Milchstrassse wants to merge 16 commits into
openclaw:mainfrom
Milchstrassse:feat/configurable-xhigh-thinking-support

Conversation

@Milchstrassse

Copy link
Copy Markdown

AI-assisted: Yes (OpenClaw-assisted). Testing: targeted / lightly tested.

Summary

Describe the problem and fix in 2–5 bullets:

  • Problem: xhigh support is currently gated by a hard-coded provider/model allowlist, so custom refs such as robot/gpt-5.4 get rejected or downgraded to high even when the upstream endpoint really supports the higher thinking level.
  • Why it matters: users of custom OpenAI-compatible providers have to remap their model refs onto built-in openai/* names just to avoid false downgrades, which is brittle and defeats explicit custom model catalogs.
  • What changed: this PR adds models.providers.*.models[*].compat.supportsXHighThinking and makes the major xhigh gating paths honor that explicit per-model compat flag before falling back to the built-in allowlist.
  • What did NOT change (scope boundary): default behavior for existing built-in refs is unchanged when the new compat flag is omitted, and this PR does not add provider auto-detection or any new network/runtime probing.

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 explicitly opt into xhigh with compat.supportsXHighThinking: true.
  • /think options and invalid-xhigh messages now reflect explicit custom compat flags instead of relying only on the built-in allowlist.
  • Existing behavior stays the same when the new compat flag is absent.

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:

Repro + Verification

Environment

  • OS: Ubuntu Linux (local dev VM)
  • Runtime/container: local source checkout, corepack pnpm, Vitest
  • Model/provider: custom OpenAI-compatible provider (for example robot/gpt-5.4 via openai-responses)
  • Integration/channel (if any): chat directive path, gateway session patch path, cron isolated-agent path, and llm-task
  • Relevant config (redacted):
{
  "models": {
    "providers": {
      "robot": {
        "baseUrl": "https://example.test/v1",
        "api": "openai-responses",
        "models": [
          {
            "id": "gpt-5.4",
            "reasoning": true,
            "compat": {
              "supportsXHighThinking": true
            }
          }
        ]
      }
    }
  }
}

Steps

  1. Configure a custom model ref such as robot/gpt-5.4.
  2. Set thinkingDefault or an explicit /thinking xhigh request for that custom ref.
  3. Before this patch, OpenClaw rejects or downgrades xhigh because the ref is not in the hard-coded allowlist.
  4. After this patch, add compat.supportsXHighThinking: true to that model definition.
  5. Re-run the same /think or /thinking xhigh flow.

Expected

  • Custom model refs that explicitly opt in via compat should be treated as xhigh-capable.
  • Hints and validation messages should match the effective support matrix.
  • Existing built-in allowlist behavior should remain unchanged when no override is configured.

Actual

  • Before: custom refs such as robot/gpt-5.4 were downgraded to high even when the upstream supported xhigh.
  • After: explicit compat opt-in enables xhigh for that custom ref, and the same config-aware support check is used across command, gateway, cron, reply, and llm-task paths.

Evidence

Attach at least one:

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

Before (real runtime log):

Thinking level "xhigh" is not supported for robot/gpt-5.4; downgrading to "high".

Targeted verification run locally after the patch:

corepack pnpm exec oxlint src/auto-reply/thinking.ts \
  src/auto-reply/thinking.test.ts \
  src/auto-reply/reply/get-reply-run.ts \
  src/auto-reply/reply/directive-handling.impl.ts \
  src/commands/agent.ts \
  src/gateway/sessions-patch.ts \
  src/cron/isolated-agent/run.ts \
  extensions/llm-task/src/llm-task-tool.ts \
  src/auto-reply/reply.directive.directive-behavior.applies-inline-reasoning-mixed-messages-acks-immediately.test.ts

corepack pnpm exec vitest run src/auto-reply/thinking.test.ts
corepack pnpm exec vitest run \
  src/auto-reply/reply.directive.directive-behavior.applies-inline-reasoning-mixed-messages-acks-immediately.test.ts \
  -t "allows custom provider config to opt into xhigh"

Human Verification (required)

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

  • Verified scenarios:
    • Added a custom-provider unit test showing compat.supportsXHighThinking: true enables xhigh for robot/gpt-5.4.
    • Added a unit test showing compat.supportsXHighThinking: false can explicitly disable xhigh even for an otherwise built-in-supported ref.
    • Added a targeted directive test showing /think exposes xhigh and /thinking xhigh succeeds for an opted-in custom provider.
    • Confirmed the config-aware support check is now wired into command, gateway session patch, cron, reply, and llm-task entry points.
  • Edge cases checked:
    • Missing compat override preserves the current hard-coded allowlist behavior.
    • Explicit false wins over the built-in allowlist.
  • What you did not verify:
    • I did not run the full repository test suite.
    • I did not fully rework unrelated standalone failures in the larger directive test file; I only ran the new targeted scenario added by this PR.
    • I did not perform a full end-to-end TUI/UI pass.

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 (optional config addition)
  • Migration needed? (Yes/No) No
  • If yes, exact upgrade steps:

Failure Recovery (if this breaks)

  • How to disable/revert this change quickly: remove compat.supportsXHighThinking from the custom model definition, set it to false, or revert this commit.
  • Files/config to restore: custom models.providers.*.models[*].compat entries; the previous behavior is otherwise unchanged.
  • Known bad symptoms reviewers should watch for: a custom ref unexpectedly advertising xhigh, or a proxy that opted in but still rejects high-thinking requests upstream.

Risks and Mitigations

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

  • Risk: a custom proxy may opt into xhigh in config even though the upstream implementation does not actually support it.
    • Mitigation: the flag is explicit and per-model, defaults remain unchanged, and users can remove or set the flag to false immediately.
  • Risk: support hints could drift if some xhigh gate site still used the old hard-coded check.
    • Mitigation: this PR updates the main gate/validation paths (agent, gateway session patch, cron, reply flow, and llm-task) and adds targeted tests around the new behavior.

@openclaw-barnacle openclaw-barnacle Bot added gateway Gateway runtime extensions: llm-task Extension: llm-task commands Command implementations size: M labels Mar 13, 2026
@openclaw-barnacle openclaw-barnacle Bot added the agents Agent runtime and tooling label Mar 16, 2026
@Milchstrassse
Milchstrassse marked this pull request as ready for review March 16, 2026 04:02
@greptile-apps

greptile-apps Bot commented Mar 16, 2026 •

Copy link
Copy Markdown
Contributor

Greptile Summary

This PR adds compat.supportsXHighThinking to the custom model config schema and threads it through all major xhigh gating paths (agent command, gateway session patch, cron isolated-agent, reply/directive handling, and llm-task), so custom model refs can explicitly opt into or out of xhigh without being in the hard-coded built-in allowlist. Default behavior for all existing built-in refs is unchanged when the flag is omitted.

  • New config field: models.providers.*.models[*].compat.supportsXHighThinking?: boolean added to both ModelCompatConfig and the Zod schema.
  • Core logic (thinking.ts): Introduces ThinkingSupportSource and two resolution paths — a point query (resolveExplicitXHighOverride, catalog-wins) and a collection pass (collectExplicitXHighRefs, config-wins on Map overwrite). These two paths have inconsistent priority when the same model ref appears in both catalog and config with conflicting values: the support check says it's unsupported while the hint message would show it as supported, or vice versa.
  • Missed call site: src/tui/tui-command-handlers.ts line 311 still calls formatThinkingLevels without a config source. TuiOptions does not carry an OpenClawConfig, so the TUI's inline /think usage hint will not reflect custom compat flags. All other entry points were correctly updated.
  • Tests: Targeted unit tests and a directive integration test cover the new opt-in and explicit opt-out flows.

Confidence Score: 3/5

  • Safe to merge for the intended use-case but has a subtle priority inconsistency in hint generation vs. support checks that could surface in edge-case configurations.
  • The feature itself is backward-compatible and well-tested for the primary paths. However, collectExplicitXHighRefs (used by formatXHighModelHint) and resolveExplicitXHighOverride (used by supportsXHighThinking) have opposite precedence when a model ref exists in both catalog and config — config wins in the hint but catalog wins in the support check. This means the error message could advertise a model as supported while the gate rejects it. Additionally, tui-command-handlers.ts was not updated, leaving the TUI's /think inline hint unaware of custom compat flags.
  • src/auto-reply/thinking.ts — the collectExplicitXHighRefs function has inverted catalog/config priority compared to resolveExplicitXHighOverride.

Comments Outside Diff (1)

  1. src/tui/tui-command-handlers.ts, line 311-316 (link)

    TUI /think usage hint not config-aware

    This call to formatThinkingLevels was not updated to pass the config source, so the inline TUI usage hint (/think <off|...|xhigh>) will not include xhigh for custom models that opted in via compat.supportsXHighThinking: true. All other updated paths (gateway sessions-patch, commands.ts, directive handling, etc.) now correctly pass { config: cfg }.

    TuiOptions does not currently include a cfg field, so this would require a broader change to thread the config into the TUI command handler context. However, it's worth tracking so that the TUI in-session help text stays consistent with the actual server-side validation. Until then, a user with a custom opted-in model will see no xhigh in the TUI hint even though the gateway will accept xhigh for their model.

    Prompt To Fix With AI
    This is a comment left during a code review.
    Path: src/tui/tui-command-handlers.ts
    Line: 311-316
    
    Comment:
    **TUI `/think` usage hint not config-aware**
    
    This call to `formatThinkingLevels` was not updated to pass the config source, so the inline TUI usage hint (`/think <off|...|xhigh>`) will not include `xhigh` for custom models that opted in via `compat.supportsXHighThinking: true`. All other updated paths (gateway `sessions-patch`, `commands.ts`, directive handling, etc.) now correctly pass `{ config: cfg }`.
    
    `TuiOptions` does not currently include a `cfg` field, so this would require a broader change to thread the config into the TUI command handler context. However, it's worth tracking so that the TUI in-session help text stays consistent with the actual server-side validation. Until then, a user with a custom opted-in model will see no `xhigh` in the TUI hint even though the gateway will accept `xhigh` for their model.
    
    How can I resolve this? If you propose a fix, please make it concise.
Prompt To Fix All With AI
This is a comment left during a code review.
Path: src/auto-reply/thinking.ts
Line: 133-179

Comment:
**Inconsistent catalog vs. config priority in hint vs. support check**

`collectExplicitXHighRefs` iterates catalog entries first and then config entries, with the Map's `set` overwriting on duplicate keys — meaning **config wins** when both sources have an entry for the same model ref. However, `resolveExplicitXHighOverride` (used by `supportsXHighThinking`) checks catalog first and short-circuits via `??`, so **catalog wins** there.

This creates a divergence: if a model ref appears in both `catalog` and `config` with opposite `supportsXHighThinking` values, `supportsXHighThinking()` and `formatXHighModelHint()` will disagree — the hint could show a model as supported while the actual support check rejects it (or vice versa).

Concrete example:
- `catalog`: `{ provider: "openai", id: "gpt-5.4", compat: { supportsXHighThinking: false } }`
- `config`: `openai.models[{ id: "gpt-5.4", compat: { supportsXHighThinking: true } }]`

Result:
- `supportsXHighThinking("openai", "gpt-5.4", source)` → `false` (catalog wins via `??`)
- `formatXHighModelHint(source)` → includes `openai/gpt-5.4` as supported (config overwrote in Map)

To align the two paths, the catalog iteration in `collectExplicitXHighRefs` should be processed **after** config, or the `add()` helper should use an insert-if-absent pattern so that catalog takes precedence (matching `resolveExplicitXHighOverride`):

```
// Option: only insert if the key isn't already present (catalog wins like resolveExplicitXHighOverride)
const add = (...) => {
  if (!out.has(ref)) {
    out.set(ref, { ref, supported });
  }
};
// Then process config first, catalog second (so catalog overwrites config)
// OR keep current order but skip if already set
```

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/tui/tui-command-handlers.ts
Line: 311-316

Comment:
**TUI `/think` usage hint not config-aware**

This call to `formatThinkingLevels` was not updated to pass the config source, so the inline TUI usage hint (`/think <off|...|xhigh>`) will not include `xhigh` for custom models that opted in via `compat.supportsXHighThinking: true`. All other updated paths (gateway `sessions-patch`, `commands.ts`, directive handling, etc.) now correctly pass `{ config: cfg }`.

`TuiOptions` does not currently include a `cfg` field, so this would require a broader change to thread the config into the TUI command handler context. However, it's worth tracking so that the TUI in-session help text stays consistent with the actual server-side validation. Until then, a user with a custom opted-in model will see no `xhigh` in the TUI hint even though the gateway will accept `xhigh` for their model.

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

Last reviewed commit: a80cba4

Comment thread src/auto-reply/thinking.ts Resolved
@Milchstrassse
Milchstrassse requested a review from a team as a code owner March 16, 2026 06:02
@openclaw-barnacle openclaw-barnacle Bot added cli CLI command changes channel: feishu Channel integration: feishu size: L and removed size: M labels Mar 16, 2026
@openclaw-barnacle openclaw-barnacle Bot removed the cli CLI command changes label Mar 16, 2026
@openclaw-barnacle openclaw-barnacle Bot added the scripts Repository scripts label Mar 17, 2026

@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: 79719ca616

ℹ️ 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 +275 to +278
console.log(
`No tests found for ${plan.extensionDir}. Run "pnpm test:extension ${plan.extensionId} -- --dry-run" to inspect the resolved roots.`,
);
process.exit(1);
return;

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 Fail when extension test discovery returns no files

run() now logs and returns success when plan.testFiles is empty, which means pnpm test:extension <id> exits 0 without running any tests. In the extension-fast CI job (.github/workflows/ci.yml, step Run changed extension tests), this silently marks a changed extension as passing if test discovery regresses (for example, roots are misresolved or tests are renamed), whereas the previous non-zero exit correctly surfaced the gap.

Useful? React with 👍 / 👎.

Guo Zhanfan and others added 2 commits March 17, 2026 11:49
@Milchstrassse

Copy link
Copy Markdown
Author

Superseded by #48904, which rebuilds this change cleanly from current main and drops the rescue/merge noise from this branch. Closing this PR in favor of the replacement.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agents Agent runtime and tooling channel: feishu Channel integration: feishu commands Command implementations extensions: llm-task Extension: llm-task gateway Gateway runtime scripts Repository scripts size: L

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant