Skip to content

refactor(plugin-state): move runtime consumers to the worker - #166528

Merged
steipete merged 2 commits into
mainfrom
dbasync/w6pluginstate
Oct 7, 2026
Merged

steipete merged 2 commits into
mainfrom
dbasync/w6pluginstate

Conversation

@steipete

@steipete steipete commented Oct 7, 2026 •

Copy link
Copy Markdown
Contributor

What Problem This Solves

Rescue-command approvals and bundled OpenRouter capability loading still execute plugin-state SQLite work on the Gateway thread.

Why This Change Was Made

Move those consumers to the existing plugin-state worker. A rescue replacement keeps predecessor revocation and registration in one FIFO request with two committed transactions, preserving revocation if replacement fails. Each transaction and commit checks current caller authority; approved effects recheck that authority after waits. OpenRouter captures its physical store before loading/fetching, replaces the catalog in one worker transaction, and joins accepted refreshes through the existing model-runtime close owner. Retained plugin-state handles reuse transaction-owned schema and ownership checks after BEGIN.

User Impact

The measured moved operations issue zero MAIN-thread SQL. Schemas, stored formats, TTLs, quotas, and update behavior are unchanged. There are no new dependencies or OPENCLAW_* names.

Released synchronous keyed stores and opaque callback mutations remain under the v2026.9.8 SDK contract. The released OpenRouter synchronous getter retains its cold persisted read; bundled resolution uses the loaded-memory getter and consumes completed missing-model retry markers there. Normal context-engine activation already joins worker cleanup; synchronous cleanup remains for the provider-catalog SDK and CLI onboarding. Shared SDK kernels therefore remain in the static inventory: T1 836 → 836 (runtime caller cutover; zero raw-site retirement).

Production LOC: +280 / −71 / net +209 across nine production files. Fifteen files total including tests, routing, and documentation.

Statement budget

Five unchanged shared-harness workloads per revision on the same host. Cells are median [min–max]; warmed values are per turn. No background SQL was removed.

Phase MAIN base MAIN candidate All-thread base All-thread candidate
Boot 2,835 [2,833–2,837] 2,837 [2,833–2,843] 3,935 [3,929–3,941] 3,950 [3,931–4,090]
Connect 14 [10–14] 10 [0–14] 338 [325–373] 324 [192–369]
First turn 514 [510–568] 515 [510–555] 6,169 [6,098–6,627] 6,213 [6,136–6,508]
Warmed turn 35.3 [32.3–36.2] 33.6 [32.7–36.8] 2,502.2 [2,478.2–2,518.2] 2,489.8 [2,474–2,519.5]
Second-session / child 143 [143–212] 176 [143–189] 7,838 [7,515–8,027] 7,995 [7,679–8,033]
Control-plane 0 [0–0] 0 [0–0] 57 [55–69] 67 [53–103]
Cron 62 [37–103] 37 [37–39] 2,018 [1,937–2,191] 2,000 [1,916–2,022]
Compaction 27 [27–27] 27 [27–36] 811 [780–845] 800 [784–837]
Shutdown 223 [223–227] 223 [221–227] 2,261 [2,253–2,287] 2,231 [2,215–2,247]

The old Cron MAIN 62-statement sample reproduced twice on unmodified base with the identical SQL multiset: ordinary work 12 + the existing late placement-orphan sweep 27 + publication reconciliation 23. The original 39→62 MAIN delta was the late orphan sweep +27 offset by four fewer publication freshness statements. Its minute sweep waits for idle work and can land in different phase windows. First-turn candidate medians fit the observed base ranges; warmed medians decrease.

Statement gate accepted using observed base variance. The first-turn increases (MAIN +1; all-thread +44), second-session increases (MAIN +33; all-thread +157, or +2.003062%), and control-plane all-thread increase (+10, or +17.5439%) are within base run-to-run variance: candidate medians are inside the base ranges, and min–max ranges overlap. The maintainer explicitly approved this assessment. Warmed MAIN and all-thread medians decrease; Cron medians also decrease. Boot all-thread +15 (+0.3812%) is within the 2% budget. Raw totals are preserved without rounding them down to pass or filtering background work.

Control's selected median-sample delta is the pre-existing device-pair notifier +12, scheduled busy-timeout maintenance +2, and schema freshness −4. The same notifier cohort occurs on unmodified base, including a control phase totaling 69 statements. Its unchanged 10-second timer reads subscribers, seen requests, and device pairings.

Second-session's selected all-thread median-sample delta is MAIN +46 and worker +111 (the MAIN median has a different representative run). MAIN includes scheduled publication +27, OAuth +7, registry +4, placement retirement +5, and net foreground freshness +3. The latter includes six additional reads through the unchanged 250ms verbose-level cache, offset by three fewer other freshness reads. Worker differences come from existing shared-state/session readers, maintenance, and transcript work; plugin-state work decreases by four. Traces lack cross-thread request IDs, so this attribution does not claim exact per-RPC equivalence. No new query defect was identified in the changed owner paths.

Focused real-entry measurements (three repetitions per revision, medians):

Flow MAIN before → after All threads before → after
First rescue proposal 17 → 0 17 → 14
Warm rescue proposal 15 → 0 15 → 14
Decline 7 → 0 7 → 7
Empty approval 6 → 0 6 → 6
Accepted approval 7 → 0 18 → 16
OpenRouter cold load (eight models) 74 → 0 74 → 26
OpenRouter refresh 70 → 0 70 → 24
Runtime quarantine activation 0 → 0 10 → 9
Retained SDK activation 10 → 10 10 → 10

OpenRouter cold-load after range: 26–30 total statements. Counted setup/admission and close do not increase. Whole focused workload: MAIN 2,554 → 2,138; all-thread 3,161 → 3,045. No failed SQL in focused workloads. The full shared workloads retain inherited audit-pruning BEGIN lock failures during shutdown (base 0–2 per run; candidate 1–3); all ten workloads and graceful closes completed successfully. No non-shutdown SQL failed.

Evidence

Post-integration landing gate (2026-10-07)

Main fa420c6eb2752a78430cef1f2e3bf15cc17d8e9e was merged without conflicts into candidate 2db4c052b7d4308d02de6ad978054e33b6ad83c3. The coordinator approved the phase-move interpretation below and authorized landing through normal exact-head CI and ClawSweeper gates.

Three fixed full workloads per revision on the same loaded macOS host, with identical workload/observer bytes and fresh source-mapped builds. Successful native statements include all background work and all threads. Medians and ranges are unfiltered; warmed values are per turn.

Phase Main median [min–max] Integrated candidate median [min–max] Median delta
Boot 3,917 [3,882–3,935] 3,882 [3,881–3,913] −35
Connect 371 [325–378] 360 [332–416] −11
First turn 6,023 [5,986–6,025] 5,957 [5,887–5,983] −66 (−1.096%)
Warmed turn 2,360.1 [2,353.4–2,367.8] 2,327.7 [2,323.6–2,334.9] −32.4 (−1.373%)
Second session 7,464 [7,370–7,616] 7,332 [7,229–7,596] −132
Control-plane 48 [47–50] 52 [48–54] +4 (+8.333%)
Cron 1,976 [1,929–1,983] 1,960 [1,915–1,965] −16
Compaction 770 [761–902] 1,001 [996–1,015] +231 (+30%)
Shutdown 2,236 [1,082–2,242] 918 [916–918] −1,318

Statement budget — phase move

Coordinator approved on 2026-10-07. Memory sync/FTS admission moves between compaction and shutdown depending on timing. Their combined all-thread statement window decreases in every corresponding run:

Run Main compaction + shutdown Candidate compaction + shutdown
1 761 + 2,236 = 2,997 1,001 + 918 = 1,919
2 902 + 1,082 = 1,984 1,015 + 916 = 1,931
3 770 + 2,242 = 3,012 996 + 918 = 1,914

Control's +4 is scheduled WAL maintenance +4, pending-input history admission +3, and existing upstream-link/freshness/ownership reads −3; all occur in baseline traces. The coordinator accepted these phase moves, replacing the NEEDS DISCUSSION disposition. First and warmed turns decrease, whole-workload medians decrease 46,282→44,716 (−3.38%), and shutdown-only native database-is-locked failures disappear in the candidate samples. Raw counts remain unchanged; normal CI and ClawSweeper gates are not waived.

Representative median-sample attribution:

Phase Attribution of its exact delta
Control-plane +4 Scheduled WAL maintenance +4; pending-input history admission +3; existing upstream-link, freshness, and ownership reads −3.
Compaction +231 Memory schema/FTS admission +132; memory-origin reads +43; other memory sync/publication +43; memory transcript-corpus reads +10; scheduled shared-state WAL maintenance +4; freshness −2; agent execution scope +1.

The positive SQL/stack groups also occur in the baseline traces, and the 61 source files represented by the compaction stacks are unchanged between the pinned revisions. The coordinator accepted the timing-dependent phase placement using these existing owners and the combined-window evidence above; the traces do not claim exact per-RPC causal equivalence. No extra runs were added to obtain a passing result, and no background work was removed from the counts.

All six Gateway workloads and their graceful closes passed. Main retained shutdown-only failed native database operations (database locked) of [2, 0, 2] per run; candidate had [0, 0, 0]. The unchanged counting contract excludes failed operations from successful-statement totals and reports them separately. On the integrated tree, 105 focused tests across eight files passed in 1,026.14s, covering rescue approvals, OpenRouter, real Gateway close, runtime-process build graph, and both import closures. Post-integration pnpm tsgo:core, pnpm tsgo:core:test, pnpm tsgo:extensions, and pnpm tsgo:extensions:test passed; madge found zero cycles. Fresh Codex P2 autoreview was scoped-clean. Released signatures were checked against stable v2026.9.8 and latest local tag v2026.10.1-beta.1; the new replacement helpers remain internal.

Original-head CI run 37595107001 passed, including openclaw/ci-gate. The non-required PR-context failure was a template-heading mismatch; the body headings have been corrected. ClawSweeper completed its exact-original-head review with no findings. The coordinator resolved the statement-budget discussion. Native review and normal hosted gates are being refreshed for the integration head before landing.

  • 174 focused tests passed across 11 files using pnpm test <files> --maxWorkers=1: 758.77s wall on a heavily loaded host. Coverage includes approvals, concurrent replacement/consumption, invalid replacement revocation, post-wait authority, foreign TTL expiry, catalog persistence/store affinity, worker ownership, and SDK consumers.
  • Real Gateway close regression passed: 305.99s wall / 31.39s test time. It proves scheduler cancellation cannot orphan an accepted catalog refresh and database retirement joins its persistence; the real server lifecycle is the boundary under test.
  • Shared-registry import gates passed: test/scripts/runtime-process-build-graph.test.ts, src/auto-reply/reply/get-reply.imports.test.ts, and src/state/openclaw-state.worker.imports.test.ts (18.74s + 76.24s shard wall).
  • Worker cutover routing includes OpenRouter capability and command-provider tests in the host-owned project; other direct/indirect consumers were checked and their focused suites run.
  • Database-worker ratchet passed; madge reports zero cycles (87.65s).
  • Fresh Codex P2 autoreview of the final patch is scoped-clean, with no accepted/actionable findings.
  • Final missing-model bookkeeping regression failed before the fix (loaded getter did not retire the awaited-miss marker), then all 65 OpenRouter/provider cases passed in 376.94s. Targeted core lint passed in 71.42s. This in-memory cleanup adds no SQL or SDK signature change and is outside the ordinary mock-provider measurement/update flows.
  • Canonical SDK diff passed: 151 public entrypoints, 3,649 exports, and 11,106 reachable declaration sections are byte-identical (base render 620.27s; candidate render 1,300.15s).
  • Published-driver update cell passed on Testbox: published 2026.9.8 → candidate, update exit 0 in 195.586s, finished phase, readiness HTTP 200, running build identity verified, durable/incognito preservation checks passed. Canonical package build passed in 212.7s.
  • Final lint corrections remove an unused generic and spell two returns explicitly; normalized emitted JavaScript for both complete modules is byte-identical to the measured/update-tested candidate. The internal helper is absent from the public SDK surface.
  • One full frozen install restored the QA workspace dependency link missing from Gateway-only preparation; tracked package and lock files are unchanged.
  • All canonical check-changed lanes passed across the local run and its exact-plan continuation. Core lint passed in 538.05s. Local extension declaration preparation timed out; after Testbox stayed queued for 15 minutes, the authorized AWS fallback completed all ten remaining lanes in 484.02s of gate time (542.04s remote command): extension lint 289.90s, script lint 37.69s, database-first guard 86.59s, import cycles 17.75s, and remaining guards green. Final source hashes were verified on the runner. Testbox and AWS leases are released, and owned runner processes have exited.

Initial rescue verification exposed the single-transaction admission helper refusing the second transaction. The corrected domain operation requires exactly transaction/commit/transaction/commit, with current authority checked at all four grants. Statement measurement then identified and removed a duplicate pre-transaction ownership read while retaining the authoritative read after BEGIN.

Overlap

Focused overlap with #160918 in OpenRouter model resolution and #166094 in plugin-state/rescue cleanup. The umbrella draft #162433 is not used as an implementation base. Other wave-6 and turn-budget lanes retain their owners; no session-turn cache or service is introduced. Whoever lands second must merge current main and adapt overlapping hunks.

@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 complete

ClawSweeper finished reviewing this revision. The review result is being finalized.

View the workflow run.

@openclaw-barnacle openclaw-barnacle Bot added docs Improvements or additions to documentation gateway Gateway runtime agents Agent runtime and tooling extensions: openrouter size: L labels Oct 7, 2026
@steipete

steipete commented Oct 7, 2026

Copy link
Copy Markdown
Contributor Author

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Oct 7, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Exact review queued.

Re-review progress:

@clawsweeper

clawsweeper Bot commented Oct 7, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed October 7, 2026, 5:35 AM ET / 09:35 UTC (Revision 3).

ClawSweeper review

What this changes

Move rescue-command approval storage and bundled OpenRouter capability loading into the existing database worker while preserving approval ordering, released SDK behavior, and shutdown settlement.

Merge readiness

✅ Ready for maintainer review

This PR remains necessary: current main still performs these consumer operations synchronously. No actionable introduced defect was found, and the recorded integrated proof supports the cutover. The statement-budget interpretation is already accepted; no further maintainer decision is needed.

Priority: P2
Reviewed head: 2db4c052b7d4308d02de6ad978054e33b6ad83c3

Review scores

Measure Result What it means
Overall readiness 🦞 diamond lobster (5/6) A focused owner-preserving refactor with strong recorded production-path measurements, compatibility evidence, and meaningful lifecycle coverage.
Proof confidence 🦞 diamond lobster (5/6) Sufficient (live_output): The captured body records rescue and OpenRouter production-entry measurements with zero Gateway-thread SQL, integrated Gateway workloads with successful close, and published-driver update observations. Source and focused regressions support ordering, revocation, store affinity, and close settlement. No stored-format or schema change requires migration; existing-state compatibility is supported by the retained contracts and recorded update cell. No target code was executed during this review.
Patch quality 🦞 diamond lobster (5/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Verified Sufficient (live_output): The captured body records rescue and OpenRouter production-entry measurements with zero Gateway-thread SQL, integrated Gateway workloads with successful close, and published-driver update observations. Source and focused regressions support ordering, revocation, store affinity, and close settlement. No stored-format or schema change requires migration; existing-state compatibility is supported by the retained contracts and recorded update cell. No target code was executed during this review.
Evidence reviewed 8 items Pinned introduction and clean checkout: Reviewed the supplied base-to-head introduction. Raw head records match the two supplied original-head parents. The checkout remained clean, and the introduced diff passed whitespace inspection. The supplied test merge was not used to infer removal of main behavior.
Current main still needs the rescue cutover: Pinned current-main source uses the synchronous keyed store for approval consumption, deletion, and registration. A local main-blob read encountered a fetch failure; the exact source was successfully inspected through GitHub's contents endpoint.
Current main still needs the catalog cutover: Pinned current-main OpenRouter capability loading reads persisted entries synchronously and clears/registers catalog rows through the synchronous store. The branch replaces those runtime operations rather than duplicating an existing worker implementation.
Findings None None.
Security None None.

How this fits together

Plugin state stores rescue approvals and OpenRouter model capabilities in OpenClaw's shared SQLite database. These records feed approved administrative actions and model resolution; the worker moves their database work off the Gateway thread.

flowchart TD
  A[Rescue commands] --> B[Current caller authority]
  B --> E[Plugin state worker]
  C[OpenRouter catalog] --> D[Captured physical store]
  D --> E
  E --> F[Shared SQLite database]
  F --> G[Approved administrative actions]
  F --> H[Loaded model capabilities]
Loading

Before merge

None.

Agent review details

Security

None.

PR surface

Source +209, Tests +199, Docs +17. Total +425 across 15 files.

View PR surface stats
Area Files Added Removed Net
Source 9 280 71 +209
Tests 5 239 40 +199
Docs 1 17 0 +17
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 15 536 111 +425

Review metrics

Metric Value Why it matters
Focused Gateway-thread SQL First rescue proposal 17 → 0; OpenRouter cold load 74 → 0 Recorded real-entry measurements directly assess the consumer operations this cutover moves.
Production versus test growth Production net +209 lines; tests net +197 lines Production growth supports captured-store replacement and lifecycle admission; tests cover ordering, revocation, persistence, and shutdown.

Technical review

Best possible solution:

Use the existing worker for runtime storage operations while preserving shipped SDK adapters, route-scoped approvals, physical-store affinity, and graceful shutdown settlement.

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

Not applicable to a refactor bug reproduction; current-main source confirms the synchronous consumer paths, and the recorded before/after measurements exercise those paths.

Is this the best way to solve the issue?

Yes. Reusing the existing worker and lifecycle owners is a focused cutover, with explicit preservation of released synchronous SDK contracts.

AGENTS.md: found and applied where relevant.

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

Labels

Label changes:

  • add rating: 🦞 diamond lobster: Overall readiness is 🦞 diamond lobster; proof is 🦞 diamond lobster and patch quality is 🦞 diamond lobster.
  • remove rating: 🐚 platinum hermit: Current PR rating is rating: 🦞 diamond lobster, so this older rating label is no longer current.

Label justifications:

  • P2: This is a bounded runtime database improvement with preserved user-facing contracts and no demonstrated urgent regression.
  • rating: 🦞 diamond lobster: Overall readiness is 🦞 diamond lobster; proof is 🦞 diamond lobster and patch quality is 🦞 diamond lobster.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Sufficient (live_output): The captured body records rescue and OpenRouter production-entry measurements with zero Gateway-thread SQL, integrated Gateway workloads with successful close, and published-driver update observations. Source and focused regressions support ordering, revocation, store affinity, and close settlement. No stored-format or schema change requires migration; existing-state compatibility is supported by the retained contracts and recorded update cell. No target code was executed during this review.
  • proof: sufficient: Contributor real behavior proof is sufficient. The captured body records rescue and OpenRouter production-entry measurements with zero Gateway-thread SQL, integrated Gateway workloads with successful close, and published-driver update observations. Source and focused regressions support ordering, revocation, store affinity, and close settlement. No stored-format or schema change requires migration; existing-state compatibility is supported by the retained contracts and recorded update cell. No target code was executed during this review.

Evidence

What I checked:

  • Pinned introduction and clean checkout: Reviewed the supplied base-to-head introduction. Raw head records match the two supplied original-head parents. The checkout remained clean, and the introduced diff passed whitespace inspection. The supplied test merge was not used to infer removal of main behavior. (2db4c052b7d4)
  • Current main still needs the rescue cutover: Pinned current-main source uses the synchronous keyed store for approval consumption, deletion, and registration. A local main-blob read encountered a fetch failure; the exact source was successfully inspected through GitHub's contents endpoint. (src/system-agent/rescue-message.ts:11, 5077ad4f99aa)
  • Current main still needs the catalog cutover: Pinned current-main OpenRouter capability loading reads persisted entries synchronously and clears/registers catalog rows through the synchronous store. The branch replaces those runtime operations rather than duplicating an existing worker implementation. (src/agents/embedded-agent-runner/openrouter-model-capabilities.ts:12, 5077ad4f99aa)
  • Replacement ordering and live authority: Approval replacement runs committed predecessor deletion followed by registration within one worker request. Host admission requires transaction/commit/transaction/commit and checks current physical-store and caller authority at each grant. Rescue consumption also rechecks authority after the worker wait and passes the guard to the existing persistent-effect owner. (src/plugin-state/plugin-state-worker-client.ts:109, 2db4c052b7d4)
  • Physical-store binding and close settlement: Catalog loading captures its physical store before awaited reads and network work. Accepted persistence is registered with the existing model-runtime close owner. The real Gateway-close regression verifies that scheduler cancellation cannot retire the database before the accepted catalog is persisted. (src/gateway/server-close.plugin-state.test.ts:15, 2db4c052b7d4)
  • Complete captured proof and accepted budget interpretation: The fully inspected live body matches captured SHA-256 fa51c032f23f70773a8fdeda92895450f0e23c50a524e87b26bd111cd303ebd0. It records focused real-entry measurements with zero MAIN-thread SQL for moved operations, six successful integrated Gateway workloads and graceful closes, and 105 integrated focused tests. The maintainer-authored body records coordinator acceptance of the timing-dependent phase moves, with whole-workload median statements decreasing 46,282 to 44,716; ordinary CI gates remain intact. (2db4c052b7d4)

Likely related people:

  • steipete: Suggested for follow-up; no historical authorship or introduction is verified. (role: unverified routing candidate; confidence: low)
  • 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 (2 earlier review cycles)
  • reviewed 2026-10-07T08:42:57.902Z sha 393c843 :: needs maintainer review before merge. :: none
  • reviewed 2026-10-07T08:52:49.152Z sha 393c843 :: needs maintainer review before merge. :: none

@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
Integrate main at fa420c6 without conflict resolutions. Preserve the approved plugin-state worker cutover and existing SDK contracts.
@steipete

steipete commented Oct 7, 2026

Copy link
Copy Markdown
Contributor Author

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Oct 7, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Exact review queued.

Re-review progress:

@clawsweeper clawsweeper Bot added rating: 🦞 diamond lobster Very strong PR readiness with only minor maintainer review expected. and removed rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. labels Oct 7, 2026
@steipete
steipete merged commit 6a6f7ba into main Oct 7, 2026
136 checks passed
@steipete
steipete deleted the dbasync/w6pluginstate branch October 7, 2026 09:50
@steipete

steipete commented Oct 7, 2026

Copy link
Copy Markdown
Contributor Author

Merged via squash.

obviyus added a commit that referenced this pull request Oct 7, 2026
…rocess (#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 (#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.

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]>
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Oct 8, 2026
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 gateway Gateway runtime P2 Normal backlog priority with limited blast radius. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🦞 diamond lobster Very strong PR readiness with only minor maintainer review expected. size: L 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