Repository navigation
fix(openrouter): thinking levels collapse to "off, ultra" on a cold process - #166705
Conversation
|
🦞👀 Pull request received. I will update this pull request when review starts. ClawSweeper review in progressClawSweeper is reviewing this revision. This supersedes any previous blocked status. |
615df41 to
1f582fe
Compare
|
Codex review: needs maintainer review before merge. Reviewed October 7, 2026, 3:20 PM ET / 19:20 UTC (Revision 2). ClawSweeper reviewWhat this changesThe 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 Review scores
Verification
How this fits togetherOpenClaw 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]
Before mergeNone. Agent review detailsSecurityNone. PR surfaceSource +15, Tests +93, Docs +7. Total +115 across 6 files. View PR surface stats
Review metrics
Technical reviewBest 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. LabelsLabel changes: No label changes. Label justifications:
EvidenceWhat I checked:
Likely related people:
Rating scale
Overall follows the weaker of proof and patch quality. Workflow
HistoryReview history (1 earlier review cycle)
|
|
@clawsweeper re-review |
|
🦞👀 Re-review progress:
|
|
Landed in 030003c. Bug: on a cold process ( 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, Proof: real-key before/after runs on gpt-5, claude-sonnet-4.5 and deepseek-r1 through |
…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]>
What Problem This Solves
Fixes: OpenRouter models offer only
off, ultraon a fresh process, soopenclaw agent --local(and a Gateway's first turn) rejects valid levels such as--thinking lowand silently turns a configuredthinkingDefault: maxintooff.User Impact
User impact: configured OpenRouter models get their real thinking levels on the first turn of every process.
openai/gpt-5offers minimal–high (no off, since reasoning is mandatory),anthropic/claude-sonnet-4.5offers off/on,deepseek/deepseek-r1is always on, and a configuredmaxon gpt-5 sendshighinstead ofminimal.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: falseand the level is chosen from that. Capabilities only load later, inprepareDynamicModel, 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:--thinking lowUse one of: off, ultrareasoning: {effort: "low"}--thinking lowafter a successful turn (SQLite populated)off, ultraeffort: "low"effort: "minimal"(off clamped)effort: "medium"thinkingDefault: maxeffort: "minimal"effort: "high"--thinking offUse one of: minimal, low, medium, high, ultra--thinking lowoff, ultrareasoning: {enabled: true}enabled: falseenabled: true--thinking offenabled: falseenabled: false--thinking lowoff, ultraenabled: true--thinking offenabled: truesent)Use one of: always on, ultraThe 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) sendsenabled: falseon turn 1, thenenabled: trueon turns 2 and 3.Gateway (isolated state and port, gpt-5 configured): first turn with
--thinking lowwas rejected withoff, ultraon main and sendseffort: "low"with this PR; later turns were already correct on main.Tests: new
extensions/openrouter/static-catalog.test.tsfails on main (row staysreasoning: 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.ts23s wall (Vitest 15.9s, test body 19ms);src/agents/models-config.providers.implicit.discovery-scope.test.ts24s 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).