Skip to content

fix(openrouter): thinking levels collapse to "off, ultra" on a cold process - #166705

Merged
obviyus merged 1 commit into
mainfrom
fix/openrouter-cold-thinking-levels
Oct 7, 2026
Merged

obviyus merged 1 commit into
mainfrom
fix/openrouter-cold-thinking-levels

Conversation

@obviyus

@obviyus obviyus commented Oct 7, 2026 •

Copy link
Copy Markdown
Collaborator

What Problem This Solves

Fixes: OpenRouter models offer only off, ultra on a fresh process, so openclaw agent --local (and a Gateway's first turn) rejects valid levels such as --thinking low and silently turns a configured thinkingDefault: max into off.

User Impact

User impact: configured OpenRouter models get their real thinking levels on the first turn of every process. openai/gpt-5 offers minimal–high (no off, since reasoning is mandatory), anthropic/claude-sonnet-4.5 offers off/on, deepseek/deepseek-r1 is always on, and a configured max on gpt-5 sends high instead of minimal.

Why This Change Was Made

The OpenRouter thinking policy and dynamic model row read model capabilities from process memory only. That is deliberate (#160651, #166528): those reads run on synchronous session paths and must not touch SQLite or the network. On a cold process nothing has loaded yet when the prepared model runtime completes configured OpenRouter refs, so the row says reasoning: false and the level is chosen from that. Capabilities only load later, in prepareDynamicModel, after the level is fixed.

The static catalog build already runs asynchronously before that completion, and only for providers whose configured refs need it. Core now passes that selected scope (providerIds, an existing catalog-context field) into static catalog hooks, and OpenRouter's static hook awaits its capability loader when OpenRouter is selected: a worker read of the persisted catalog, or one fetch when nothing is persisted yet. Unscoped static runs (doctor validation, the catalog worker, the bundled static fallback) pass no scope and stay network-free. The synchronous reads are unchanged. The provider SDK catalog docs describe the scoped static run.

Evidence

Live, real OpenRouter key, fresh isolated state per run, openclaw agent --local, request bodies captured at the HTTP client:

Model / input main (630e969) this PR
gpt-5 --thinking low rejected: Use one of: off, ultra reasoning: {effort: "low"}
gpt-5 --thinking low after a successful turn (SQLite populated) rejected: off, ultra effort: "low"
gpt-5 default effort: "minimal" (off clamped) effort: "medium"
gpt-5 thinkingDefault: max effort: "minimal" effort: "high"
gpt-5 --thinking off accepted rejected: Use one of: minimal, low, medium, high, ultra
claude-sonnet-4.5 --thinking low rejected: off, ultra reasoning: {enabled: true}
claude-sonnet-4.5 default enabled: false enabled: true
claude-sonnet-4.5 --thinking off enabled: false enabled: false
deepseek-r1 --thinking low rejected: off, ultra enabled: true
deepseek-r1 --thinking off accepted (enabled: true sent) rejected: Use one of: always on, ultra

The claude-sonnet-4.5 default change (enabled: false → enabled: true) is the cold path now matching warm behavior on main. OpenRouter reports this model as {mandatory: false} with no default, and OpenClaw applies its existing default for reasoning-capable models. A main Gateway (f186273, isolated, claude-sonnet-4.5 configured, no --thinking) sends enabled: false on turn 1, then enabled: true on turns 2 and 3.

Gateway (isolated state and port, gpt-5 configured): first turn with --thinking low was rejected with off, ultra on main and sends effort: "low" with this PR; later turns were already correct on main.

Tests: new extensions/openrouter/static-catalog.test.ts fails on main (row stays reasoning: false) and passes here; it also checks that unscoped static runs make no request. Existing OpenRouter, capability-cache, provider-discovery and implicit-catalog suites pass.

Test cost (pnpm test <file> --maxWorkers=1, local): extensions/openrouter/static-catalog.test.ts 23s wall (Vitest 15.9s, test body 19ms); src/agents/models-config.providers.implicit.discovery-scope.test.ts 24s wall (Vitest 17.5s, 20 tests). Both are mostly transform time. Hosted CI run 37671257993 on 1f582fe passed all 79 jobs in 10m52s; the run does not report time per file.

Merge danger: two-way door. No stored data, config or schema changes; reverting restores the previous cold behavior. Blast radius: OpenRouter users (first turn may now wait for one catalog read or fetch before selection, which the turn already did later), plus any static catalog hook that starts reading the new optional providerIds (none besides OpenRouter today).

@clawsweeper

clawsweeper Bot commented Oct 7, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

Pull request received. I will update this pull request when review starts.

ClawSweeper review in progress

ClawSweeper is reviewing this revision. This supersedes any previous blocked status.

View the workflow run.

@obviyus
obviyus force-pushed the fix/openrouter-cold-thinking-levels branch from 615df41 to 1f582fe Compare October 7, 2026 19:00
@openclaw-barnacle openclaw-barnacle Bot added the docs Improvements or additions to documentation label Oct 7, 2026
@clawsweeper clawsweeper Bot added P2 Normal backlog priority with limited blast radius. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. labels Oct 7, 2026
@clawsweeper

clawsweeper Bot commented Oct 7, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed October 7, 2026, 3:20 PM ET / 19:20 UTC (Revision 2).

ClawSweeper review

What this changes

The PR loads OpenRouter model capabilities during scoped asynchronous catalog preparation so first-turn thinking choices match the model’s advertised support.

Merge readiness

✅ Ready for maintainer review

The PR remains necessary and has no blocking findings. The previous test-cost request is resolved, and the supplied live evidence demonstrates the cold-start repair.

Priority: P2
Reviewed head: 1f582feb21810a30a113390abb3340db3f7ac48d

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) A focused repair with strong real-entry before/after evidence, useful regression coverage, and resolved prior feedback.
Proof confidence 🦞 diamond lobster (5/6) Sufficient (live_output): The captured live request-output matrix exercises the changed OpenRouter preparation owner through isolated local-agent and Gateway turns, showing valid cold-start thinking payloads across fresh and persisted state. No stored-data contract changes are introduced.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Verified Sufficient (live_output): The captured live request-output matrix exercises the changed OpenRouter preparation owner through isolated local-agent and Gateway turns, showing valid cold-start thinking payloads across fresh and persisted state. No stored-data contract changes are introduced.
Evidence reviewed 9 items Pinned introduced change: The introduced delta forwards the existing optional provider scope through static catalog preparation and awaits the existing OpenRouter capability loader only when OpenRouter is selected.
Current main still needs the repair: Fetched main still has an unscoped static hook that only builds seed rows, while dynamic model completion reads loaded capabilities and defaults missing reasoning metadata to false. The early load is absent.
Preparation precedes synchronous completion: Runtime facts await selected static catalogs before configured runtime models are completed. The capability loader uses the existing worker-backed persisted catalog and bounded fetch; synchronous model and thinking hooks remain memory-only.
Findings None None.
Security None None.

How this fits together

OpenClaw prepares model metadata before selecting an agent’s thinking level. The OpenRouter plugin supplies capabilities that determine available thinking choices and the reasoning payload sent to the provider.

flowchart TD
 A[Configured model references] --> B[Scoped catalog preparation]
 B --> C{OpenRouter selected}
 C -->|Yes| D[Load persisted or remote capabilities]
 D --> E[Complete model metadata]
 C -->|No| E
 E --> F[Select thinking level]
 F --> G[OpenRouter request]
Loading

Before merge

None.

Agent review details

Security

None.

PR surface

Source +15, Tests +93, Docs +7. Total +115 across 6 files.

View PR surface stats
Area Files Added Removed Net
Source 3 19 4 +15
Tests 2 94 1 +93
Docs 1 7 0 +7
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 6 120 5 +115

Review metrics

Metric Value Why it matters
Production versus regression coverage production +19/-4; tests +94/-1 The small production increase forwards existing scope and moves capability preparation earlier, with regression coverage for offline isolation and resulting thinking choices.

Technical review

Best possible solution:

Prepare OpenRouter capabilities once before cold-process thinking selection while preserving memory-only synchronous hooks and offline catalog generation.

Do we have a high-confidence way to reproduce the issue?

Yes: the supplied baseline local-agent and Gateway runs show cold-process rejection of valid thinking levels, and current-main source explains that ordering defect. This reviewer did not execute the runtime.

Is this the best way to solve the issue?

Yes: awaiting the existing capability owner at the asynchronous preparation boundary repairs ordering without adding another cache or synchronous I/O.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning medium; reviewed against cbfbdc8ddb95.

Labels

Label changes:

No label changes.

Label justifications:

  • P2: The repair addresses incorrect first-turn OpenRouter thinking choices with a provider-limited blast radius.
  • rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🦞 diamond lobster and patch quality is 🐚 platinum hermit.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Sufficient (live_output): The captured live request-output matrix exercises the changed OpenRouter preparation owner through isolated local-agent and Gateway turns, showing valid cold-start thinking payloads across fresh and persisted state. No stored-data contract changes are introduced.
  • proof: sufficient: Contributor real behavior proof is sufficient. The captured live request-output matrix exercises the changed OpenRouter preparation owner through isolated local-agent and Gateway turns, showing valid cold-start thinking payloads across fresh and persisted state. No stored-data contract changes are introduced.

Evidence

What I checked:

  • Pinned introduced change: The introduced delta forwards the existing optional provider scope through static catalog preparation and awaits the existing OpenRouter capability loader only when OpenRouter is selected. (extensions/openrouter/index.ts:304, 1f582feb2181)
  • Current main still needs the repair: Fetched main still has an unscoped static hook that only builds seed rows, while dynamic model completion reads loaded capabilities and defaults missing reasoning metadata to false. The early load is absent. (extensions/openrouter/index.ts:304, cbfbdc8ddb95)
  • Preparation precedes synchronous completion: Runtime facts await selected static catalogs before configured runtime models are completed. The capability loader uses the existing worker-backed persisted catalog and bounded fetch; synchronous model and thinking hooks remain memory-only. (src/agents/prepared-model-runtime.facts.ts:306, 1f582feb2181)
  • Existing capability contract and upgrade behavior: ProviderCatalogContext already defines optional providerIds. The SDK documentation explains scoped static preparation and preserves network-free unscoped runs. No schema, stored format, config value, credential route, or dependency changes are introduced; mandatory-reasoning restrictions follow the existing documented model contract. Public docs: docs/plugins/sdk-provider-plugins/model-catalogs.md. (docs/plugins/sdk-provider-plugins/model-catalogs.md:472, 1f582feb2181)
  • Real cold-process behavior proof: The captured PR body reports real-key isolated local-agent runs with HTTP request bodies: GPT-5 low is rejected on baseline and sends effort low after the fix, including with a persisted catalog in a fresh process; max sends high. Binary and mandatory-reasoning models are covered, as is the Gateway first turn. The Claude default comparison also shows baseline warm turns already enable reasoning. This directly exercises the changed preparation-to-selection path. (1f582feb2181)
  • Previous review request resolved: The retained previous review had no findings and requested test-cost reporting. The captured body now records 23s and 24s single-worker wall times, a 19ms new test body, and 10m52s hosted CI duration, explicitly noting that CI does not report per-file timing. The contributor requested re-review at fix(openrouter): thinking levels collapse to "off, ultra" on a cold process #166705 (comment). (1f582feb2181)

Likely related people:

  • Peter Steinberger: Raw commit 6a6f7ba adds extensions/openrouter/index.ts:241 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: medium; commits: 6a6f7ba3e37b; files: extensions/openrouter/index.ts)
  • Olli0103: Suggested for follow-up; no historical authorship or introduction is verified. (role: unverified routing candidate; confidence: low)

Rating scale

Score Internal tier Crab rank Meaning
6/6 S 🦀 challenger crab Exceptional readiness
5/6 A 🦞 diamond lobster Very strong readiness
4/6 B 🐚 platinum hermit Good normal PR; ordinary maintainer review
3/6 C 🦐 gold shrimp Useful, but confidence is limited
2/6 D 🦪 silver shellfish Proof or implementation needs work
1/6 F 🧂 unranked krab Not merge-ready
N/A NA 🌊 off-meta tidepool Rating does not apply

Overall follows the weaker of proof and patch quality.
Shiny media proof means a screenshot, video, or linked artifact directly shows the changed behavior. Runtime, network, CSP, and security claims still need visible diagnostics.

Workflow

  • ClawSweeper keeps one durable marker-backed review comment per issue or PR.
  • Re-runs edit this comment so the latest verdict, findings, and automation markers stay together instead of adding duplicate bot comments.
  • A fresh review can be triggered by eligible @clawsweeper re-review comments, exact-item GitHub events, scheduled/background review runs, or manual workflow dispatch.
  • PR/issue authors and users with repository write access can comment @clawsweeper re-review or @clawsweeper re-run on an open PR or issue to request a fresh review only.
  • Maintainers can also comment @clawsweeper review to request a fresh review only.
  • Fresh-review commands do not start repair, autofix, rebase, CI repair, or automerge.
  • Maintainer-only repair and merge flows require explicit commands such as @clawsweeper autofix, @clawsweeper automerge, @clawsweeper fix ci, or @clawsweeper address review.
  • Maintainers can comment @clawsweeper explain to ask for more context, or @clawsweeper stop to stop active automation.

History

Review history (1 earlier review cycle)
  • reviewed 2026-10-07T19:06:59.994Z sha 1f582fe :: needs changes before merge. :: none

@obviyus

obviyus commented Oct 7, 2026

Copy link
Copy Markdown
Collaborator Author

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Oct 7, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Exact review queued.

Re-review progress:

@obviyus
obviyus merged commit 030003c into main Oct 7, 2026
170 of 171 checks passed
@obviyus
obviyus deleted the fix/openrouter-cold-thinking-levels branch October 7, 2026 19:22
@obviyus

obviyus commented Oct 7, 2026

Copy link
Copy Markdown
Collaborator Author

Landed in 030003c.

Bug: on a cold process (openclaw agent --local, or a Gateway's first turn), configured OpenRouter models offered only off, ultra. Explicit levels were rejected and a configured max became off. The thinking policy reads capabilities from memory only, and they loaded after the level was chosen.

Fix: scoped static-catalog preparation now passes the selected provider ids to static hooks. OpenRouter awaits its existing capability loader there, before configured models are completed and the level is chosen. Unscoped static runs (doctor, models list --all, catalog generation) stay network-free.

Proof: real-key before/after runs on gpt-5, claude-sonnet-4.5 and deepseek-r1 through agent --local, with request bodies captured, plus an isolated Gateway first turn (effort: low now reaches gpt-5). A new regression test fails on main. CI was green and ClawSweeper was ready on 1f582fe.

github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Oct 8, 2026
…rocess (openclaw#166705)

## What Problem This Solves

Fixes: OpenRouter models offer only `off, ultra` on a fresh process, so `openclaw agent --local` (and a Gateway's first turn) rejects valid levels such as `--thinking low` and silently turns a configured `thinkingDefault: max` into `off`.

## User Impact

User impact: configured OpenRouter models get their real thinking levels on the first turn of every process. `openai/gpt-5` offers minimal–high (no off, since reasoning is mandatory), `anthropic/claude-sonnet-4.5` offers off/on, `deepseek/deepseek-r1` is always on, and a configured `max` on gpt-5 sends `high` instead of `minimal`.

## Why This Change Was Made

The OpenRouter thinking policy and dynamic model row read model capabilities from process memory only. That is deliberate (openclaw#160651, openclaw#166528): those reads run on synchronous session paths and must not touch SQLite or the network. On a cold process nothing has loaded yet when the prepared model runtime completes configured OpenRouter refs, so the row says `reasoning: false` and the level is chosen from that. Capabilities only load later, in `prepareDynamicModel`, after the level is fixed.

The static catalog build already runs asynchronously before that completion, and only for providers whose configured refs need it. Core now passes that selected scope (`providerIds`, an existing catalog-context field) into static catalog hooks, and OpenRouter's static hook awaits its capability loader when OpenRouter is selected: a worker read of the persisted catalog, or one fetch when nothing is persisted yet. Unscoped static runs (doctor validation, the catalog worker, the bundled static fallback) pass no scope and stay network-free. The synchronous reads are unchanged. The provider SDK catalog docs describe the scoped static run.

## Evidence

Live, real OpenRouter key, fresh isolated state per run, `openclaw agent --local`, request bodies captured at the HTTP client:

| Model / input | main (c018fa5) | this PR |
| --- | --- | --- |
| gpt-5 `--thinking low` | rejected: `Use one of: off, ultra` | `reasoning: {effort: "low"}` |
| gpt-5 `--thinking low` after a successful turn (SQLite populated) | rejected: `off, ultra` | `effort: "low"` |
| gpt-5 default | `effort: "minimal"` (off clamped) | `effort: "medium"` |
| gpt-5 `thinkingDefault: max` | `effort: "minimal"` | `effort: "high"` |
| gpt-5 `--thinking off` | accepted | rejected: `Use one of: minimal, low, medium, high, ultra` |
| claude-sonnet-4.5 `--thinking low` | rejected: `off, ultra` | `reasoning: {enabled: true}` |
| claude-sonnet-4.5 default | `enabled: false` | `enabled: true` |
| claude-sonnet-4.5 `--thinking off` | `enabled: false` | `enabled: false` |
| deepseek-r1 `--thinking low` | rejected: `off, ultra` | `enabled: true` |
| deepseek-r1 `--thinking off` | accepted (`enabled: true` sent) | rejected: `Use one of: always on, ultra` |

The claude-sonnet-4.5 default change (`enabled: false` → `enabled: true`) is the cold path now matching warm behavior on main. OpenRouter reports this model as `{mandatory: false}` with no default, and OpenClaw applies its existing default for reasoning-capable models. A main Gateway (ac78700, isolated, claude-sonnet-4.5 configured, no `--thinking`) sends `enabled: false` on turn 1, then `enabled: true` on turns 2 and 3.

Gateway (isolated state and port, gpt-5 configured): first turn with `--thinking low` was rejected with `off, ultra` on main and sends `effort: "low"` with this PR; later turns were already correct on main.

Tests: new `extensions/openrouter/static-catalog.test.ts` fails on main (row stays `reasoning: false`) and passes here; it also checks that unscoped static runs make no request. Existing OpenRouter, capability-cache, provider-discovery and implicit-catalog suites pass.

Test cost (`pnpm test <file> --maxWorkers=1`, local): `extensions/openrouter/static-catalog.test.ts` 23s wall (Vitest 15.9s, test body 19ms); `src/agents/models-config.providers.implicit.discovery-scope.test.ts` 24s wall (Vitest 17.5s, 20 tests). Both are mostly transform time. Hosted CI run 37671257993 on 1f582fe passed all 79 jobs in 10m52s; the run does not report time per file.

No overlap with Pash/Sarah changes.

**Merge danger:** two-way door. No stored data, config or schema changes; reverting restores the previous cold behavior. Blast radius: OpenRouter users (first turn may now wait for one catalog read or fetch before selection, which the turn already did later), plus any static catalog hook that starts reading the new optional `providerIds` (none besides OpenRouter today).

Co-authored-by: Ayaan Zaidi <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agents Agent runtime and tooling docs Improvements or additions to documentation extensions: openrouter P2 Normal backlog priority with limited blast radius. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. size: S status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant