Skip to content

perf(gateway): restore fast saved-session model picking - #166037

Merged
steipete merged 3 commits into
mainfrom
steipete/perf-micro-models-list-regression-r54-20260919
Oct 6, 2026
Merged

steipete merged 3 commits into
mainfrom
steipete/perf-micro-models-list-regression-r54-20260919

Conversation

@steipete

@steipete steipete commented Oct 6, 2026 •

Copy link
Copy Markdown
Contributor

What Problem This Solves

Saved-session model pickers became slow after e1cb2b3 (#165614) added awaited session-authority reads around each model/runtime decision. A production sample returned nine models and three runtime choices in 626 ms with a session key, versus 50 ms without one.

User Impact

Repeated saved-session reads reuse the prepared catalog projection while retaining current session checks at admission and publication. Saved account/model/runtime choices and provenance remain intact. Personal accounts and drafts keep their request-scoped revocation path; recovered native runtimes become selectable without discovery on each read. No configuration or storage migration is required.

Why This Change Was Made

Evaluate prepared auth facts synchronously, remove the per-entry Promise machinery, and extend the existing generation-owned, single-flight model-list cache to detached shared-session selections. Read runtime eligibility from current prepared readiness when publishing cached choices. Actual account discovery retains its own authorization checks.

Production TypeScript is +312/−290, net +22 lines. The necessary growth captures nine selection/provenance fields, excludes personal credentials, and carries cold-preparation authority without retaining the session object or live request. Those account-revocation and saved-selection contracts prevent reusing an unscoped key or caching the original scope. There is no new cache owner. A separately generated guard baseline removes one obsolete exemption (−1 tooling line). The gate also exposed an inherited unused voice-call constant export; removing that single export keyword keeps its value and behavior unchanged and lets the repository-wide dead-export check pass.

Evidence

Final head 1ac5d4e5247acb220ea233a4a41be5f5bd1af834 passed CI run 37446216434: 54 successful jobs, zero failures, 530 s elapsed. Dependency review passed with no dependency changes. The existing auto-merge watcher merged this PR at 2026-10-06 10:04:22Z as f8b06fbb69b68e74e42224871514b84095126aa7; ancestry on main is verified. No manual merge, production restart, or deployment was performed.

On Blacksmith Testbox (openclaw-check), six persistent WebSocket clients read nine synthetic OpenAI models, three Codex runtime choices, and a saved shared-account pin. At application head 3f39199ef7e1, 600 scoped requests measured 12.0 ms p50 / 27.3 ms p99; unscoped reads measured 5.3 / 16.4 ms. Provider discovery, native discovery, and preparedModelCatalog task deltas were zero during both windows. The scoped maximum was 68.6 ms. Combined fixture/Gateway/client/worker peak RSS was about 1.69 GiB, not a production-process memory measurement.

The paired 4f6dfcb693d1 control measured 14.1/166.7 ms p50/p99, versus 12.6/44.0 ms with the pre-rebase patch. The final confirmation above used a fresh lease after the readiness fix and a clean rebase. The independent handler regression reduced warmed session-authority acquisitions from 46 to 2, failed against the control, and passed after the repair. Catalog worker activity was already zero in the control: the measured regression was session-authority amplification.

  • Final benchmark: tbx_01m482za2gxtt6kp9zh7g1skwf, real source Gateway/worker lifecycle and persistent WebSockets; passed. Provider and native harness endpoints are synthetic; no live Codex app-server or inference is claimed.
  • Focused prior-head proof: prepared-model regression 2/2, catalog decisions 19/19, visibility 26/26, lifecycle 18/18, runtime choices 9/9, web-search status 14/14, and model-command recovery 16/16. Standalone pnpm test src/gateway/server-methods/models.prepared.test.ts --maxWorkers=1: 24.46 s wall / 2.16 s test execution. Final CI completed 54 successful jobs in 530 s workflow wall time; per-file CI timing was not separately collected.
  • Review caught stale runtime eligibility after readiness recovery. Both new recovery assertions fail on the old reader; all nine cases pass after the fix on tbx_01m480sfzyycnwt7ffh9g2z5vj. The final full-patch review has no actionable P0–P2 findings; rebase preserved every changed source file. The final six-file validation cleanup was also reviewed with no actionable P0–P2 findings.
  • Staged gate on tbx_01m482za2gxtt6kp9zh7g1skwf: node scripts/check-changed.mjs --staged --base ca43d19197888f3d42237b4425f08a473779266f passed all 27 core test type graphs (1,328.77 s), core types (51.63 s), graph boundaries (73.93 s), formatting, ratchets, dependency/plugin boundaries, and schema guards before stopping at the inherited unused export. After cleanup, targeted core/extension lint and the complete dead-export scan passed (280.8 s command time). The remaining planned script lint, native-schema, legacy-store, media, sidecar-loader, import-cycle, webhook-ordering, and pairing guards passed separately. This is completed check coverage across the original run and targeted repairs, not a claimed single uninterrupted gate exit 0.
  • Final cleanup proof on tbx_01m486jr6j0mncgttsjr812sm0, provider blacksmith-testbox, profile openclaw-check: all six checks passed, 233.4 s total command time. Commands: pnpm lint:plugins:no-extension-test-core-imports; pnpm test:serial src/plugins/doctor-contract-declarations.test.ts src/plugins/doctor-contract-closure-guard.test.ts (6/6, 7 s); pnpm tsgo:extensions (58 s); pnpm tsgo:extensions:test (89 s); node scripts/run-vitest.mjs src/agents/model-catalog-decisions.test.ts (19/19, 30 s); node scripts/run-vitest.mjs src/gateway/server-methods/models.prepared.test.ts (2/2, 19 s). Both final leases were stopped after completion.

The first PR CI run (37440278843, head 07871fc79f27) exposed two stale test assumptions. The connection/publication fixture waited for a catalog acquisition that cached reads now omit; its barriers now wrap the existing live session authority and preserve both stale-publication suppression and unrelated-session survival. The service-tier fixture deliberately read a retired projection and now expects the existing typed supersession rejection. An intermediate fixture probe exposed the independent one-second dispatcher response cache; removing its redundant warm-up restored the intended in-flight scenario. These repairs change tests only. On tbx_01m487k233fsrhtys0cbs7kmzr, pnpm test src/gateway/server-methods/models-connect-publication.integration.test.ts --maxWorkers=1 passed 1/1 (27.60 s command wall; 14.608 s test), and pnpm test src/gateway/server-methods/models-list-result.service-tiers.test.ts --maxWorkers=1 passed 5/5 (22.62 s command wall). The final fixture review is clean at P0–P2. Staged validation passed across the native gate plus focused repairs: all 27 core test type graphs, core graph boundary, ratchets, targeted test lint, all 1,324 script lint inputs, coercion/deprecation guards, and all three export scans. The gate caught inferred generic return types and one shadowed test variable; explicit Promise<Awaited<T>> annotations and a spy rename resolved them. The timeout ratchet was regenerated to remove exactly one timed wait. These last changes are type/name/baseline-only; the passing behavioral proof remains valid. The final five-check lint/guard command completed in 173.7 s, and the lease was stopped.

One existing raw-SQLite session fixture failed with SQLITE_BUSY in a 159/160 gateway/account/security run. It bypasses the changed model-list path; its complete unchanged 89-test file-order replay passed on tbx_01m480sfzyycnwt7ffh9g2z5vj. This is non-reproduction, not a claimed fix.

Historical deployment Gateways at 40592729 and 2983dfcf were not launched and no full bisect was run; attribution uses the parent-relative source change, live scoped/unscoped sample, and reproducible control. Production was only read, with no restart or deployment. Production latency after deployment remains unmeasured.

Restore fast model picker reads after per-model authority checks multiplied
session worker round trips. Project prepared auth facts synchronously and
reuse the existing generation-owned projection cache for detached shared
session selections. Keep personal accounts request-scoped and validate each
request at admission and publication.

Read runtime eligibility from current prepared readiness so cached choices
recover after a native runtime becomes available. Cover bounded worker reads,
concurrent preparation, saved selection changes, and readiness recovery.
Remove obsolete awaits from synchronous catalog consumers and dead request-authority assignments. Prune the obsolete mock-export exemption and the inherited unused voice-call constant export exposed by the full-tree gate.
@clawsweeper

clawsweeper Bot commented Oct 6, 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 channel: voice-call Channel integration: voice-call gateway Gateway runtime agents Agent runtime and tooling size: L labels Oct 6, 2026
@steipete
steipete enabled auto-merge (squash) October 6, 2026 09:06
@clawsweeper

clawsweeper Bot commented Oct 6, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs changes before merge. Reviewed October 6, 2026, 5:28 AM ET / 09:28 UTC (Revision 2).

ClawSweeper review

What this changes

The PR speeds saved-session model picking by reusing prepared catalog projections, evaluating prepared authentication facts synchronously, and refreshing runtime eligibility when cached choices are read.

Regression provenance

Possible regression — probable (reviewed change; failure trace). No predecessor PR is attributed.

Merge readiness

⛔ Needs changes before merge - 3 items remain

The performance repair remains useful and has convincing Gateway benchmark evidence. Two fixture failures remain in the pinned head; the body reports validated repairs awaiting publication.

Priority: P2
Reviewed head: 07871fc79f272eb24fbb846336de3b48cbd10b41

Review scores

Measure Result What it means
Overall readiness 🦐 gold shrimp (3/6) Strong production-boundary performance evidence supports the repair, but two confirmed fixture failures remain in the reviewed branch.
Proof confidence 🦞 diamond lobster (5/6) Sufficient (live_output): The supplied Testbox benchmark exercises the changed catalog owner through persistent WebSockets and the production Gateway/worker lifecycle, showing improved scoped latency without discovery amplification. Synthetic native endpoints limit the claim to picker behavior, which matches the change. No stored-data contract changes require migration proof.
Patch quality 🦐 gold shrimp (3/6) 2 actionable review findings remain.

Verification

Check Result Evidence
Real behavior Verified Sufficient (live_output): The supplied Testbox benchmark exercises the changed catalog owner through persistent WebSockets and the production Gateway/worker lifecycle, showing improved scoped latency without discovery amplification. Synthetic native endpoints limit the claim to picker behavior, which matches the change. No stored-data contract changes require migration proof.
Evidence reviewed 8 items Pinned introduction and merge ownership: Reviewed the merge-base-to-head introduction. Raw test-merge parent records match the pinned base followed by the exact PR head; fetched-main drift was not attributed to this PR.
Still necessary on current main: Fetched main still restricts prepared model-list reuse to unscoped requests. The latest supplied release lacks this generation-cache module; no merged fixing replacement was established.
Cache and authority boundaries: Saved shared selections retain nine detached fields; personal pins and drafts bypass this cache. Preparation disables discovery, and the handler retains current authority checks immediately before response publication. No stored-data format or public plugin API changes were found.
Findings 2 actionable findings [P2] Move the publication-race barriers to live session authority
[P2] Expect supersession when reading the retired tier projection
Security None None.

How this fits together

The Gateway model catalog combines configured models, saved session selections, and prepared account and runtime facts. It returns model-picker choices after checking current session access.

flowchart TD
  A[Model picker request] --> B[Current session access]
  B --> C[Saved selection facts]
  C --> D[Generation catalog cache]
  E[Prepared account and runtime facts] --> D
  D --> F[Current publication check]
  F --> G[Model and runtime choices]
Loading

Before merge

  • Move the publication-race barriers to live session authority (P2) - Saved-session reads now use the prepared projection instead of readPreparedCatalog, so this barrier never opens and the integration test times out before exercising supersession. Exact-head CI confirms the timeout. Update both acquisition barriers to the live session authority path while retaining stale-publication suppression and unrelated-session survival assertions; the body describes this repair, but it is absent from the pinned head.
  • Expect supersession when reading the retired tier projection (P2) - Runtime choices now consult the current decision owner during read(). After this fixture explicitly retires that owner, readRuntime(a, "codex") throws the existing supersession error instead of returning a row without tiers, causing both parameterized cases to fail in exact-head CI. Assert the typed rejection while preserving the earlier account-scope and tier-filter assertions.
  • Complete next step (P2) - Publish the prepared publication-race and retired-projection fixture repairs so they are included in the reviewed head.

Findings

  • [P2] Move the publication-race barriers to live session authority — src/gateway/server-methods/models-connect-publication.integration.test.ts:278-283
  • [P2] Expect supersession when reading the retired tier projection — src/gateway/server-methods/models-list-result.service-tiers.test.ts:291-293
Agent review details

Security

None.

PR surface

Source +22, Tests +218, Docs +2, Other -1. Total +241 across 26 files.

View PR surface stats
Area Files Added Removed Net
Source 14 312 290 +22
Tests 10 266 48 +218
Docs 1 2 0 +2
Config 0 0 0 0
Generated 0 0 0 0
Other 1 0 1 -1
Total 26 580 339 +241

Review metrics

Metric Value Why it matters
Saved-session authority amplification 46 to 2 warmed acquisitions The reported failing-control regression directly measures the round-trip amplification this repair targets.

Technical review

Best possible solution:

Keep generation-owned catalog reuse and live publication checks, with regression fixtures synchronized to those boundaries.

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

Yes for the pinned-head fixture failures: source and exact-head CI annotations identify both failing paths. The performance regression has supplied control and Gateway measurements; this review did not execute it.

Is this the best way to solve the issue?

Yes for the production approach: it reuses the existing generation cache and preserves request-owned publication authority. The remaining repair belongs in the two stale fixtures.

Full review comments:

  • [P2] Move the publication-race barriers to live session authority — src/gateway/server-methods/models-connect-publication.integration.test.ts:278-283
    Saved-session reads now use the prepared projection instead of readPreparedCatalog, so this barrier never opens and the integration test times out before exercising supersession. Exact-head CI confirms the timeout. Update both acquisition barriers to the live session authority path while retaining stale-publication suppression and unrelated-session survival assertions; the body describes this repair, but it is absent from the pinned head.
    Confidence: 0.99
  • [P2] Expect supersession when reading the retired tier projection — src/gateway/server-methods/models-list-result.service-tiers.test.ts:291-293
    Runtime choices now consult the current decision owner during read(). After this fixture explicitly retires that owner, readRuntime(a, "codex") throws the existing supersession error instead of returning a row without tiers, causing both parameterized cases to fail in exact-head CI. Assert the typed rejection while preserving the earlier account-scope and tier-filter assertions.
    Confidence: 0.99

Overall correctness: patch is incorrect
Overall confidence: 0.97

AGENTS.md: found and applied where relevant.

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

Labels

Label changes:

  • add P2: This is a bounded model-picker latency repair with measured improvement and no demonstrated core outage.
  • add proof: sufficient: Contributor real behavior proof is sufficient. The supplied Testbox benchmark exercises the changed catalog owner through persistent WebSockets and the production Gateway/worker lifecycle, showing improved scoped latency without discovery amplification. Synthetic native endpoints limit the claim to picker behavior, which matches the change. No stored-data contract changes require migration proof.
  • add rating: 🦐 gold shrimp: Overall readiness is 🦐 gold shrimp; proof is 🦞 diamond lobster and patch quality is 🦐 gold shrimp.
  • add status: ⏳ waiting on author: ClawSweeper has contributor-facing work open and is waiting for author action. Sufficient (live_output): The supplied Testbox benchmark exercises the changed catalog owner through persistent WebSockets and the production Gateway/worker lifecycle, showing improved scoped latency without discovery amplification. Synthetic native endpoints limit the claim to picker behavior, which matches the change. No stored-data contract changes require migration proof.

Label justifications:

  • P2: This is a bounded model-picker latency repair with measured improvement and no demonstrated core outage.
  • rating: 🦐 gold shrimp: Overall readiness is 🦐 gold shrimp; proof is 🦞 diamond lobster and patch quality is 🦐 gold shrimp.
  • status: ⏳ waiting on author: ClawSweeper has contributor-facing work open and is waiting for author action. Sufficient (live_output): The supplied Testbox benchmark exercises the changed catalog owner through persistent WebSockets and the production Gateway/worker lifecycle, showing improved scoped latency without discovery amplification. Synthetic native endpoints limit the claim to picker behavior, which matches the change. No stored-data contract changes require migration proof.
  • proof: sufficient: Contributor real behavior proof is sufficient. The supplied Testbox benchmark exercises the changed catalog owner through persistent WebSockets and the production Gateway/worker lifecycle, showing improved scoped latency without discovery amplification. Synthetic native endpoints limit the claim to picker behavior, which matches the change. No stored-data contract changes require migration proof.

Evidence

Acceptance criteria:

  • [P1] pnpm test src/gateway/server-methods/models-connect-publication.integration.test.ts --maxWorkers=1.
  • [P1] pnpm test src/gateway/server-methods/models-list-result.service-tiers.test.ts --maxWorkers=1.
  • [P1] git diff --check.

What I checked:

  • Pinned introduction and merge ownership: Reviewed the merge-base-to-head introduction. Raw test-merge parent records match the pinned base followed by the exact PR head; fetched-main drift was not attributed to this PR. (19817c2ce188)
  • Still necessary on current main: Fetched main still restricts prepared model-list reuse to unscoped requests. The latest supplied release lacks this generation-cache module; no merged fixing replacement was established. (src/gateway/server-methods/models.ts:117, f997ec377556)
  • Cache and authority boundaries: Saved shared selections retain nine detached fields; personal pins and drafts bypass this cache. Preparation disables discovery, and the handler retains current authority checks immediately before response publication. No stored-data format or public plugin API changes were found. (src/gateway/server-methods/chat-metadata-model-list.ts:113, 07871fc79f27)
  • Real Gateway performance proof: The captured PR body reports six persistent WebSocket clients exercising the production Gateway and worker lifecycle on application head 3f39199: 600 scoped requests measured 12.0 ms p50 and 27.3 ms p99, with zero provider discovery, native discovery, and catalog-task deltas. Synthetic provider and harness endpoints appropriately bound the claim to catalog performance, not native inference. (3f39199ef7e1)
  • Publication fixture failure: Exact-head CI reports 'Initial catalog acquisition did not start'. The fixture still gates readPreparedCatalog, which saved-session cache reuse now bypasses. The captured body describes a passing repair using live session-authority barriers, but that repair is absent from the reviewed head. (src/gateway/server-methods/models-connect-publication.integration.test.ts:279, 07871fc79f27)
  • Retired-projection fixture failure: Exact-head CI reports 'Model catalog changed while selecting runtimes' from the service-tier fixture. Its final assertion reads an explicitly retired projection; runtime choices now consult the current decision owner during publication. The body reports a validated typed-rejection assertion that has not been pushed. (src/gateway/server-methods/models-list-result.service-tiers.test.ts:293, 07871fc79f27)

Likely related people:

  • steipete: Suggested for follow-up; no historical authorship or introduction is verified. (role: unverified routing candidate; confidence: low)

Rank-up moves

Optional improvements that raise the rating; they are not merge blockers.

  • Publish the reported fixture repairs and validate both affected files on the resulting head.

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-06T09:07:30.296Z sha 07871fc :: 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: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. labels Oct 6, 2026
Pause publication races at live session authority instead of catalog acquisition, assert typed rejection of retired projections, and shrink the obsolete timed-wait baseline.
@steipete
steipete merged commit f8b06fb into main Oct 6, 2026
138 of 140 checks passed
@steipete
steipete deleted the steipete/perf-micro-models-list-regression-r54-20260919 branch October 6, 2026 10:04
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Oct 7, 2026
)

* perf(gateway): reuse saved-session model catalog projections

Restore fast model picker reads after per-model authority checks multiplied
session worker round trips. Project prepared auth facts synchronously and
reuse the existing generation-owned projection cache for detached shared
session selections. Keep personal accounts request-scoped and validate each
request at admission and publication.

Read runtime eligibility from current prepared readiness so cached choices
recover after a native runtime becomes available. Cover bounded worker reads,
concurrent preparation, saved selection changes, and readiness recovery.

* fix(gateway): finish model catalog validation cleanup

Remove obsolete awaits from synchronous catalog consumers and dead request-authority assignments. Prune the obsolete mock-export exemption and the inherited unused voice-call constant export exposed by the full-tree gate.

* test(gateway): align catalog fixtures with prepared reads

Pause publication races at live session authority instead of catalog acquisition, assert typed rejection of retired projections, and shrink the obsolete timed-wait baseline.
obviyus added a commit that referenced this pull request Oct 9, 2026
…e CLI sign-in unless sign-in seeded them (#167963)

## What Problem This Solves

Fixes: after Claude CLI sign-in (`openclaw models auth login --provider anthropic --method cli`), any `anthropic/<id>` that sign-in did not seed fails with `No API key found for provider "anthropic" … missing-provider-auth`. This affects Claude models published after sign-in and IDs typed with `--model`, `/model` or `models set`, such as `anthropic/claude-haiku-4-5`.

## User Impact

User impact: Claude-CLI-only users can type or pick any Claude model and it runs through Claude Code. The model picker still lists only models the Claude CLI catalog serves, so `claude-mythos-5` (direct API only) stays hidden. Users with an Anthropic API key and no Claude CLI sign-in keep the API route. Exact model entries that name another runtime still win. A session pinned to an Anthropic API-key account keeps that account's models, including `claude-mythos-5`, in its picker.

Existing installs that signed in on an affected build get the new routing only after they rerun `openclaw models auth login --provider anthropic --method cli`. This PR adds no Doctor migration.

User-authored `provider/*` wildcards for other CLI backends behave exactly as on `main`. For example, `google/*` → `google-gemini-cli` keeps the same picker rows, and its typed IDs run as before. The picker gate is keyed on the `anthropic/*` → `claude-cli` entry that sign-in writes.

## Why This Change Was Made

Since #129052, Claude CLI sign-in persists no OpenClaw auth profile. At run time, `resolveCliRuntimeExecutionProvider` (src/agents/model-runtime-aliases.ts) found no runtime policy for unseeded IDs and no `claude-cli` profile it could alias. The turn then fell to the embedded Anthropic API path. An instrumented isolated Gateway on 58ba7ed showed `policy=undefined … viaAuthProfile=undefined` and then `useCliExecution=false`.

- Sign-in (`extensions/anthropic/cli-migration.ts`) now also writes the existing, documented provider wildcard `agents.defaults.models["anthropic/*"] = { agentRuntime: { id: "claude-cli" } }`. It does not overwrite a wildcard that already names another runtime.
- Catalog decisions (`src/agents/model-catalog-cli-wildcard.ts`, used by `model-catalog-decisions.ts`) mark a row unavailable, with no "sign in" reason, when all of these hold: native Claude CLI credentials supplied the availability (`evidence: "runtime"`), the row reaches `claude-cli` only through that sign-in wildcard, the Claude CLI catalog does not list it (bundled manifest plus published catalog), and it is not a configured row. Availability from a selected or pinned API account is never narrowed. Run-time routing is unchanged, so typed IDs still run.

Production change: 3 lines in cli-migration.ts, 15 net lines in model-catalog-decisions.ts and a new 58-line module (about 45 code lines). No config keys, schema or SDK surface change.

Provenance (f8b06fb, #166037): prepared catalog decisions keep saved account, model and runtime choices and their provenance. `createCliRuntimeModelAuthEvaluator` returns a pinned non-native account's own provider-auth result, and `evaluateNative` keeps host results for selected accounts. The wildcard gate now only narrows availability that came from native Claude CLI credentials, so a saved account choice keeps the models that account can use.

## Evidence

Real proofs used the machine's existing native `claude` login, OpenClaw's real sign-in flow, isolated profiles and a loopback Gateway:

- Before, on `main` 58ba7ed: `models set anthropic/claude-haiku-4-5` plus one turn failed with `missing-provider-auth`, and the instrumentation showed no CLI route.
- After, on b35cc8e: the picker lists `available` rows that exactly match the 11 Claude CLI catalog IDs. `claude-mythos-5` and `claude-haiku-4-5` are not listed.
- After: a turn typed with `--model anthropic/claude-haiku-4-5` returned `OK` with `runner=cli` and `winnerProvider=claude-cli`.
- After: `models set anthropic/claude-haiku-4-5` plus a turn returned `OK` through `claude-cli`.
- API-key control: on a profile with `paste-api-key` (key piped on stdin) and no Claude CLI sign-in, an `anthropic/claude-haiku-4-5` turn returned `OK` with `runner=embedded` and `winnerProvider=anthropic`. Mythos stays listed for API users, as on `main`.
- Regressions:
  - `extensions/anthropic/cli-migration.test.ts`, including the registered non-interactive sign-in entry: 4 failures without the fix, 40/40 pass with it.
  - `src/agents/model-catalog-decisions.test.ts`: the Claude CLI wildcard test fails without the gate (`expected true to be false`). With the gate, it covers a listed row, an API-only row (unavailable, no reason), an exact pinned row, a configured typed row, an exact override to `openclaw`, and an unchanged `google/*` → `google-gemini-cli` row even when that backend lists its own rows.
  - Same test, selected-account case (added on 41f26e5): with the wildcard and a session pinned to an Anthropic API-key profile, `claude-mythos-5` is available with `selectedProfileId: "anthropic:work"` in both `evaluateEntry` and `evaluateNative`. With only native Claude CLI credentials it stays unavailable. On 651801e this fails (`expected { availability: false … } to match object { availability: true … }`). With the fix, 24/24 pass in the file, and `model-auth-availability.test.ts` plus `cli-migration.test.ts` pass.

- New-model simulation on 651801e, in a throwaway worktree with `claude-fable-5` removed from local knowledge: both bundled manifest rows (`anthropic`, `claude-cli`), the `fable-5` alias, the model-catalog-core alias and the Claude CLI context alias. `models.catalogRefresh.url` pointed at a loopback copy of `catalog.openclaw.ai/models/v2/catalog.json`, served at first without `anthropic/claude-fable-5` and `claude-cli/claude-fable-5`.
  - Before: `models.list {view:"configured", refresh:true}` (the Control UI view) returned 10 Claude rows and no Fable 5 row.
  - I added both rows back only in the served copy, with a newer `generatedAt`, then ran `openclaw models refresh` and `models.list {refresh:true}`. The Gateway PID did not change. The first response was unchanged because adoption starts after that response. The next read listed `claude-cli/claude-fable-5` as available, but not `anthropic/claude-fable-5`. A Gateway restart gave the same rows, so the refresh lifecycle is not the cause.
  - Turns: `--model anthropic/claude-fable-5` returned `OK` on the same Gateway PID with `runner=cli`, `winnerProvider=claude-cli` and `winnerModel=claude-fable-5`. `--model claude-cli/claude-fable-5`, the row the picker shows, also returned `OK` through `claude-cli`.
- Gates on 41f26e5: `node scripts/check-changed.mjs` exited 0. It ran the tsgo lanes, oxlint on core and the changed extension files, the full dead-export scan, format checks, ratchets and the import-cycle check. `pnpm exec oxlint --type-aware` on the changed files exited 0.

Upgrade cell (published v2026.9.9 → this PR, disposable Docker container from the `scripts/e2e/Dockerfile` `bare` stage, candidate packed with `scripts/package-openclaw-for-docker.mjs` from 41f26e5, build `2026.9.9-41f26e5206fc`). `api.anthropic.com` resolved to loopback in the container, so the fake key never left it. npm `latest` is still 2026.9.9.
- Existing state was written by the published CLI. It had a Claude CLI-style `agents.defaults.models` with three `anthropic/*` IDs on `claude-cli` and no wildcard, primary `anthropic/claude-opus-5-5`, and an `anthropic:work` API-key profile from `paste-api-key` with a fake key. Through the v2026.9.9 Gateway, `sessions.create` and then `sessions.patch {model:"anthropic/claude-sonnet-5@anthropic:work"}` saved this session selection: `providerOverride=anthropic, modelOverride=claude-sonnet-5, authProfileOverride=anthropic:work (user), agentRuntimeOverride=claude-cli`.
- `openclaw update --tag file:<tgz> --no-restart --yes --json` exited 0 with `status: ok` and all steps at 0. The CLI now reports `OpenClaw 2026.9.9 (41f26e5)`. The updater's doctor, `openclaw doctor --non-interactive` and `config validate` passed (`valid: true`, no warnings). Doctor warnings matched the baseline: a plaintext gateway token in the fixture, loopback bind and no service manager. The saved session selection and `agents.defaults.models` read back identical to the pre-update values.
- Claude CLI sign-in again, with the real `openclaw models auth login --provider anthropic --method cli --set-default` under a pty. It needs a TTY. Without a `claude` binary it stops with `Claude CLI is not authenticated on this host`. With a stub `claude` on `PATH` that only answers `auth status --json` with `{"loggedIn":true,"authMethod":"claude.ai"}` and `--version`, and never runs a model, it exited 0. That was the only stubbed part; the sign-in, config write and Gateway are the shipped code. After the first sign-in, `"anthropic/*": {agentRuntime:{id:"claude-cli"}}` was present once. A second sign-in left it present once. The three existing entries and the primary were unchanged, the session selection was identical after each sign-in, and `config validate` and doctor passed.
- Candidate Gateway with the wildcard present: `models.list {sessionKey, view:"all", provider:"anthropic"}` for the session pinned to `anthropic:work` listed `claude-mythos-5` as `available: true`. `models.list {agentId:"main"}`, with no selected account, listed it as `available: false`, which is the accepted Claude CLI-first behavior.
- Not covered: no real Claude Code turn ran in the cell. Real turns are in the evidence above. The update's package swap took 23 min on a loaded host; an earlier v2026.9.9 cell on the same host took 7–11 min for the whole update. No Telegram Test Server run.

Gap: a Claude model that the published catalog adds later appears in the picker without a restart, but only as `claude-cli/<id>`, not `anthropic/<id>`. `anthropic` is a `refreshable` catalog provider, so its published rows appear only when live `/v1/models` discovery returns them, and that discovery needs an API key. The `src/agents/model-catalog.ts` guard says "Only live registry or refreshed rows may publish those provider models". `claude-cli` is `static`, so its published row appears. The sign-in wildcard gate only marks existing `anthropic` rows unavailable and never adds rows, so the `claude-cli` row has no `anthropic` twin to fold into. Both refs run through Claude Code. Showing `anthropic/<id>` would need a separate change to the refreshable-provider guard in `model-catalog.ts` or to the CLI twin collapse in `model-runtime-aliases.ts`.

## Merge danger

Medium-low. The run-time change is config written only by Claude CLI sign-in. The picker change sits in shared catalog decisions, but it applies only when an agent's `anthropic/*` entry names `claude-cli` and the row is neither configured nor listed by the Claude CLI catalog.

Co-authored-by: Ayaan Zaidi <[email protected]>
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Oct 10, 2026
…e CLI sign-in unless sign-in seeded them (openclaw#167963)

## What Problem This Solves

Fixes: after Claude CLI sign-in (`openclaw models auth login --provider anthropic --method cli`), any `anthropic/<id>` that sign-in did not seed fails with `No API key found for provider "anthropic" … missing-provider-auth`. This affects Claude models published after sign-in and IDs typed with `--model`, `/model` or `models set`, such as `anthropic/claude-haiku-4-5`.

## User Impact

User impact: Claude-CLI-only users can type or pick any Claude model and it runs through Claude Code. The model picker still lists only models the Claude CLI catalog serves, so `claude-mythos-5` (direct API only) stays hidden. Users with an Anthropic API key and no Claude CLI sign-in keep the API route. Exact model entries that name another runtime still win. A session pinned to an Anthropic API-key account keeps that account's models, including `claude-mythos-5`, in its picker.

Existing installs that signed in on an affected build get the new routing only after they rerun `openclaw models auth login --provider anthropic --method cli`. This PR adds no Doctor migration.

User-authored `provider/*` wildcards for other CLI backends behave exactly as on `main`. For example, `google/*` → `google-gemini-cli` keeps the same picker rows, and its typed IDs run as before. The picker gate is keyed on the `anthropic/*` → `claude-cli` entry that sign-in writes.

## Why This Change Was Made

Since openclaw#129052, Claude CLI sign-in persists no OpenClaw auth profile. At run time, `resolveCliRuntimeExecutionProvider` (src/agents/model-runtime-aliases.ts) found no runtime policy for unseeded IDs and no `claude-cli` profile it could alias. The turn then fell to the embedded Anthropic API path. An instrumented isolated Gateway on 35a9f60 showed `policy=undefined … viaAuthProfile=undefined` and then `useCliExecution=false`.

- Sign-in (`extensions/anthropic/cli-migration.ts`) now also writes the existing, documented provider wildcard `agents.defaults.models["anthropic/*"] = { agentRuntime: { id: "claude-cli" } }`. It does not overwrite a wildcard that already names another runtime.
- Catalog decisions (`src/agents/model-catalog-cli-wildcard.ts`, used by `model-catalog-decisions.ts`) mark a row unavailable, with no "sign in" reason, when all of these hold: native Claude CLI credentials supplied the availability (`evidence: "runtime"`), the row reaches `claude-cli` only through that sign-in wildcard, the Claude CLI catalog does not list it (bundled manifest plus published catalog), and it is not a configured row. Availability from a selected or pinned API account is never narrowed. Run-time routing is unchanged, so typed IDs still run.

Production change: 3 lines in cli-migration.ts, 15 net lines in model-catalog-decisions.ts and a new 58-line module (about 45 code lines). No config keys, schema or SDK surface change.

Provenance (f81245d, openclaw#166037): prepared catalog decisions keep saved account, model and runtime choices and their provenance. `createCliRuntimeModelAuthEvaluator` returns a pinned non-native account's own provider-auth result, and `evaluateNative` keeps host results for selected accounts. The wildcard gate now only narrows availability that came from native Claude CLI credentials, so a saved account choice keeps the models that account can use.

## Evidence

Real proofs used the machine's existing native `claude` login, OpenClaw's real sign-in flow, isolated profiles and a loopback Gateway:

- Before, on `main` 35a9f60: `models set anthropic/claude-haiku-4-5` plus one turn failed with `missing-provider-auth`, and the instrumentation showed no CLI route.
- After, on b35cc8e: the picker lists `available` rows that exactly match the 11 Claude CLI catalog IDs. `claude-mythos-5` and `claude-haiku-4-5` are not listed.
- After: a turn typed with `--model anthropic/claude-haiku-4-5` returned `OK` with `runner=cli` and `winnerProvider=claude-cli`.
- After: `models set anthropic/claude-haiku-4-5` plus a turn returned `OK` through `claude-cli`.
- API-key control: on a profile with `paste-api-key` (key piped on stdin) and no Claude CLI sign-in, an `anthropic/claude-haiku-4-5` turn returned `OK` with `runner=embedded` and `winnerProvider=anthropic`. Mythos stays listed for API users, as on `main`.
- Regressions:
  - `extensions/anthropic/cli-migration.test.ts`, including the registered non-interactive sign-in entry: 4 failures without the fix, 40/40 pass with it.
  - `src/agents/model-catalog-decisions.test.ts`: the Claude CLI wildcard test fails without the gate (`expected true to be false`). With the gate, it covers a listed row, an API-only row (unavailable, no reason), an exact pinned row, a configured typed row, an exact override to `openclaw`, and an unchanged `google/*` → `google-gemini-cli` row even when that backend lists its own rows.
  - Same test, selected-account case (added on 41f26e5): with the wildcard and a session pinned to an Anthropic API-key profile, `claude-mythos-5` is available with `selectedProfileId: "anthropic:work"` in both `evaluateEntry` and `evaluateNative`. With only native Claude CLI credentials it stays unavailable. On 651801e this fails (`expected { availability: false … } to match object { availability: true … }`). With the fix, 24/24 pass in the file, and `model-auth-availability.test.ts` plus `cli-migration.test.ts` pass.

- New-model simulation on 651801e, in a throwaway worktree with `claude-fable-5` removed from local knowledge: both bundled manifest rows (`anthropic`, `claude-cli`), the `fable-5` alias, the model-catalog-core alias and the Claude CLI context alias. `models.catalogRefresh.url` pointed at a loopback copy of `catalog.openclaw.ai/models/v2/catalog.json`, served at first without `anthropic/claude-fable-5` and `claude-cli/claude-fable-5`.
  - Before: `models.list {view:"configured", refresh:true}` (the Control UI view) returned 10 Claude rows and no Fable 5 row.
  - I added both rows back only in the served copy, with a newer `generatedAt`, then ran `openclaw models refresh` and `models.list {refresh:true}`. The Gateway PID did not change. The first response was unchanged because adoption starts after that response. The next read listed `claude-cli/claude-fable-5` as available, but not `anthropic/claude-fable-5`. A Gateway restart gave the same rows, so the refresh lifecycle is not the cause.
  - Turns: `--model anthropic/claude-fable-5` returned `OK` on the same Gateway PID with `runner=cli`, `winnerProvider=claude-cli` and `winnerModel=claude-fable-5`. `--model claude-cli/claude-fable-5`, the row the picker shows, also returned `OK` through `claude-cli`.
- Gates on 41f26e5: `node scripts/check-changed.mjs` exited 0. It ran the tsgo lanes, oxlint on core and the changed extension files, the full dead-export scan, format checks, ratchets and the import-cycle check. `pnpm exec oxlint --type-aware` on the changed files exited 0.

Upgrade cell (published v2026.9.9 → this PR, disposable Docker container from the `scripts/e2e/Dockerfile` `bare` stage, candidate packed with `scripts/package-openclaw-for-docker.mjs` from 41f26e5, build `2026.9.9-41f26e5206fc`). `api.anthropic.com` resolved to loopback in the container, so the fake key never left it. npm `latest` is still 2026.9.9.
- Existing state was written by the published CLI. It had a Claude CLI-style `agents.defaults.models` with three `anthropic/*` IDs on `claude-cli` and no wildcard, primary `anthropic/claude-opus-5-5`, and an `anthropic:work` API-key profile from `paste-api-key` with a fake key. Through the v2026.9.9 Gateway, `sessions.create` and then `sessions.patch {model:"anthropic/claude-sonnet-5@anthropic:work"}` saved this session selection: `providerOverride=anthropic, modelOverride=claude-sonnet-5, authProfileOverride=anthropic:work (user), agentRuntimeOverride=claude-cli`.
- `openclaw update --tag file:<tgz> --no-restart --yes --json` exited 0 with `status: ok` and all steps at 0. The CLI now reports `OpenClaw 2026.9.9 (41f26e5)`. The updater's doctor, `openclaw doctor --non-interactive` and `config validate` passed (`valid: true`, no warnings). Doctor warnings matched the baseline: a plaintext gateway token in the fixture, loopback bind and no service manager. The saved session selection and `agents.defaults.models` read back identical to the pre-update values.
- Claude CLI sign-in again, with the real `openclaw models auth login --provider anthropic --method cli --set-default` under a pty. It needs a TTY. Without a `claude` binary it stops with `Claude CLI is not authenticated on this host`. With a stub `claude` on `PATH` that only answers `auth status --json` with `{"loggedIn":true,"authMethod":"claude.ai"}` and `--version`, and never runs a model, it exited 0. That was the only stubbed part; the sign-in, config write and Gateway are the shipped code. After the first sign-in, `"anthropic/*": {agentRuntime:{id:"claude-cli"}}` was present once. A second sign-in left it present once. The three existing entries and the primary were unchanged, the session selection was identical after each sign-in, and `config validate` and doctor passed.
- Candidate Gateway with the wildcard present: `models.list {sessionKey, view:"all", provider:"anthropic"}` for the session pinned to `anthropic:work` listed `claude-mythos-5` as `available: true`. `models.list {agentId:"main"}`, with no selected account, listed it as `available: false`, which is the accepted Claude CLI-first behavior.
- Not covered: no real Claude Code turn ran in the cell. Real turns are in the evidence above. The update's package swap took 23 min on a loaded host; an earlier v2026.9.9 cell on the same host took 7–11 min for the whole update. No Telegram Test Server run.

Gap: a Claude model that the published catalog adds later appears in the picker without a restart, but only as `claude-cli/<id>`, not `anthropic/<id>`. `anthropic` is a `refreshable` catalog provider, so its published rows appear only when live `/v1/models` discovery returns them, and that discovery needs an API key. The `src/agents/model-catalog.ts` guard says "Only live registry or refreshed rows may publish those provider models". `claude-cli` is `static`, so its published row appears. The sign-in wildcard gate only marks existing `anthropic` rows unavailable and never adds rows, so the `claude-cli` row has no `anthropic` twin to fold into. Both refs run through Claude Code. Showing `anthropic/<id>` would need a separate change to the refreshable-provider guard in `model-catalog.ts` or to the CLI twin collapse in `model-runtime-aliases.ts`.

## Merge danger

Medium-low. The run-time change is config written only by Claude CLI sign-in. The picker change sits in shared catalog decisions, but it applies only when an agent's `anthropic/*` entry names `claude-cli` and the row is neither configured nor listed by the Claude CLI catalog.

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 channel: voice-call Channel integration: voice-call docs Improvements or additions to documentation gateway Gateway runtime P2 Normal backlog priority with limited blast radius. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. size: XL status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant