Skip to content

fix(models): list standalone models with the catalog owner's plugin registry - #166361

Merged
obviyus merged 3 commits into
mainfrom
fix/models-list-owner-registry-scope
Oct 7, 2026
Merged

obviyus merged 3 commits into
mainfrom
fix/models-list-owner-registry-scope

Conversation

@obviyus

@obviyus obviyus commented Oct 7, 2026 •

Copy link
Copy Markdown
Collaborator

Prerequisite for #166311.

What Problem This Solves

Fixes: without a running Gateway, openclaw models list --refresh lists every configured anthropic/* model that runs through Claude CLI as unavailable, even when Claude Code is logged in. Only the default row is left (unavailable); the usable models show up only as their claude-cli/* copies.

User Impact

After openclaw onboard --auth-choice anthropic-cli, openclaw models list --refresh without a Gateway now lists the configured Claude models as available on Claude CLI, the same as the Gateway picker. Gateway output doesn't change.

Why This Change Was Made

A prepared model-catalog owner carries its own plugin registry, and that registry can differ from the process's active one. The standalone openclaw models list and the embedded TUI use a temporary owner, and Gateway owners belong to a workspace generation. prepareModelsListResult already passes owner.pluginRegistry to some calls, but CLI backend bindings, Claude CLI auth evaluation and runtime choices still read the ambient registry (for example listCliRuntimeModelBackendBindings() in model-catalog-decisions.ts). The standalone command's active registry has no CLI backends. So anthropic/* rows pinned to claude-cli fail auth, and the default view drops 9 of the 10.

prepareModelsListResult now resolves the owner first (resolveModelsListOwner), then runs preparation inside withPluginRuntimeRegistryScope(owner.pluginRegistry, …), the helper the row projection already uses for worker placement. Reads stay pure projections of the prepared facts and never enter a plugin scope, keeping #162326's published-read invariant (models.prepared.test.ts); the existing per-row worker-placement scope is kept as is. The one read-time plugin fact, the CLI backend bindings behind picker runtime choices, is now resolved once from the decisions owner's pluginRegistry in createModelCatalogDecisions instead of from the ambient registry on every read. The scoped preparation covers every prepareModelsListResult caller: the Gateway handler, chat.metadata, the standalone CLI, the TUI and the preloaded projector. Not covered and unchanged: uncached runtime-choice auth evaluations (model-auth-availability.ts) and chat-metadata-session-projection.ts projecting its preloaded catalog before preparation still read the ambient registry; the tests here don't claim those paths. Owner resolution moved unchanged into models-list-result.owner.ts, because models-list-result.ts is at the repository line cap.

One existing runtime-choices case changed its fixture: picker-fixture + generic harness picker-native → picker-fixture + codex. The old case only came out unsupported-runtime because the registered fixture harness was invisible to ambient-registry lookups. A registered generic harness is compatible with any provider, while codex explicitly rejects non-OpenAI providers (session-runtime-compat.ts), so the case still asserts "registered harness, incompatible provider → unsupported-runtime".

#166311 (one picker row per Claude CLI model) depends on this. Its twin collapse has to read CLI backends from the same registry as availability.

Evidence

Live proof on the exact head c9796892845, rerun after the design changed (pure reads; decisions resolve CLI backend bindings from the owner registry). Setup is unchanged: HOME, state and config under /tmp, no Anthropic API key, config from the real openclaw onboard --non-interactive --auth-choice anthropic-cli, and Claude Code logged in through a copied credentials file in an isolated CLAUDE_CONFIG_DIR. Both checkouts were built with pnpm build, and runs alternated main/head one after the other.

Standalone openclaw models list --refresh --json, no Gateway running (stderr: "Gateway is not running. Refreshing the local model catalog."):

origin/main (8775756) this branch (c979689)
anthropic/* 10 rows, all available: false 10 rows, all available: true
claude-cli/* 11 rows, all available 11 rows, all available

5 of 5 runs on each side matched its column. All three claude auth status probes finished in 0.15-0.44 s with exit 0 in every run, so no row depended on the probe timeout described below. (Current main now lists all 10 configured anthropic/* rows, where the earlier 2c620bb showed only the default row. All 10 are still unavailable.)

Isolated Gateway on c979689 (openclaw gateway run, same state), gateway call models.list: view: "configured" and view: "default", 3 calls each. Every call returned 10 anthropic/* rows, all available: true with agentRuntime.id: "claude-cli", plus 11 claude-cli/* rows. The Gateway and standalone paths agree.

Earlier rounds on 2c620bb vs this change (before the pure-read redesign) matched too: 14 runs on origin/main and 5 on the branch, plus 23 inside #166311.

Tests, both through the real consumer:

  • list.prepared-catalog.test.ts: the real openclaw models list command, with a standalone owner whose registry alone has the Claude CLI backend. On origin/main it fails with anthropic/claude-opus-5 available: false; here it passes.
  • models-list-result.plugin-runtime.test.ts: a prepared owner reached through prepareModelsListResult, as the Gateway and chat.metadata reach it, with an empty active registry. It fails on origin/main and also fails when only buildModelsListResult is scoped; here it passes.
  • models-list-result.plugin-runtime.test.ts (runtime choice): a configured anthropic/claude-opus-5 with pickerRuntimes: ["openclaw", "claude-cli"], owner registry with the Claude CLI backend, empty active registry. Before the decisions fix the claude-cli choice reads available: false; now true.
  • models-list-result.*, models*.test.ts (incl. models.prepared.test.ts), chat-metadata*, src/commands/models/list*, model-catalog-decisions and models.test.ts passed on this change. tsgo:core:test and node scripts/check-changed.mjs passed too.

First run after a rebuild showing only anthropic/claude-opus-5-5 false

During the work on #166311, one standalone run of the fixed code came back like origin/main's logged-out output: only anthropic/claude-opus-5-5, available: false, and no claude-cli/* rows. That isn't this change, and it isn't a build artifact. It's the existing Claude login probe:

  • A standalone list runs claude auth status --json three times (extensions/anthropic/cli-auth-seam.ts, 3 s timeout). If the second probe times out, it counts as unreadable, so every Claude row is unavailable.
  • Delaying exactly that probe to 3.5 s gives the identical output on origin/main, on this branch and on fix(models): list each Claude CLI model once in the model picker #166311. Delaying the first or third probe changes nothing.
  • Observed probe times ranged from 0.14 s to 3.0 s; the slow ones came when several claude processes shared one config dir. Once in 23 runs, during a concurrent test run, the slow case happened on its own: that run took 4 s longer and logged only two completed probes.
  • "Right after a rebuild" was a coincidence. Every run-node call in that session rebuilt because the tree was dirty, and the other rebuild runs were correct.
  • On a Gateway, fix(models): recheck Claude CLI login for model lists after Gateway startup #166305's background recheck corrects a timed-out probe within a minute.

Known and unchanged: the read-only openclaw models list (no --refresh, no Gateway) reads a cached owner that has no plugin registry. It still shows the single unavailable default row.

Bounded cost

  • One AsyncLocalStorage frame around preparation and one CLI backend listing per decisions owner; none per read() (previously the bindings were listed on every runtime-choice read). No I/O, discovery or probing: with start-logging, every standalone list started three claude auth status probes on both origin/main and this branch.
  • No new state, config, protocol or messages.
  • Local test cost, pnpm test <file> --maxWorkers=1 wall time (Apple Silicon): src/commands/models/list.prepared-catalog.test.ts 33.5 s (17 tests, vitest 28.3 s) and src/gateway/server-methods/models-list-result.runtime-choices.test.ts 30.2 s (9 tests, vitest 26.9 s), both measured on 355ced4 and unchanged since; src/gateway/server-methods/models-list-result.plugin-runtime.test.ts 40.5 s (11 tests, vitest 32.8 s) on c979689. Transform dominates (75-80%); test bodies are 12-17%.
  • CI test cost, run 37555824195 on c979689, summed per-test times per file: list.prepared-catalog 2.6 s (17 tests, shard agentic-commands-models), models-list-result.runtime-choices 2.1 s (9 tests, agentic-gateway-methods-hosted-5), models-list-result.plugin-runtime 2.9 s (11 tests, agentic-gateway-methods-hosted-6). Shared-shard totals, not per-file: those vitest batches took 16.9 s (8 files), 78.0 s (7 files) and 58.6 s (9 files). Several other shards in that run were cancelled by fail-fast after an unrelated red (see CI below), so no whole-run total is available.

LOC vs origin/main: +408/-131 total; 199 production lines are owner resolution moved verbatim into models-list-result.owner.ts; tests +153/-2.

CI

On c979689, the only red test is src/gateway/server.chat.gateway-server-chat-b.test.ts > "chat.history advances past a replay boundary that cannot fit all projected siblings" (line 5681); the other failed jobs were cancelled by fail-fast. It fails 3/3 on clean origin/main 6c352f4 and passes 3/3 on this branch locally, so it's unrelated. The earlier 4eaa9da red, src/flows/doctor-health.plugin-load.test.ts (3 ENOSPC cases), also fails on clean origin/main 6c352f4.

@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 gateway Gateway runtime commands Command implementations size: M labels Oct 7, 2026
@clawsweeper clawsweeper Bot added P2 Normal backlog priority with limited blast radius. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. labels Oct 7, 2026
@clawsweeper

clawsweeper Bot commented Oct 7, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed October 6, 2026, 9:55 PM ET / October 7, 2026, 01:55 UTC (Revision 6).

ClawSweeper review

What this changes

The PR uses each prepared model catalog’s plugin registry to recognize Claude CLI model availability and runtime choices in standalone refreshed lists.

Merge readiness

✅ Ready for maintainer review

This remains a useful fix absent from current main. The updated test-cost record satisfies the previous review request, and no blocking patch finding remains.

Priority: P2
Reviewed head: c9796892845b85efed719e6b2679cd6c9517a0f6

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) A focused owner-boundary repair with relevant real CLI evidence, meaningful regressions, and the previous cost-record follow-up completed.
Proof confidence 🐚 platinum hermit (4/6) Sufficient (live_output): The captured live-output comparison exercises standalone refreshed listing through the changed catalog preparation owner with real Claude login: ten canonical Anthropic rows become available instead of one unavailable default. Tests supplement that proof. No stored-data contract changes require migration.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Verified Sufficient (live_output): The captured live-output comparison exercises standalone refreshed listing through the changed catalog preparation owner with real Claude login: ten canonical Anthropic rows become available instead of one unavailable default. Tests supplement that proof. No stored-data contract changes require migration.
Evidence reviewed 10 items Introduced preparation boundary: The pinned introduced delta resolves the existing catalog owner before entering its registry scope. The returned reader remains outside this new scope; owner acquisition and current-authority checks are preserved in the extracted module.
Prepared runtime-choice facts: CLI backend bindings are captured from the decisions owner's registry once and reused by runtime-choice reads, replacing two ambient-registry lookups.
Current-main necessity: Inspected fetched main still lacks the owner-scoped preparation and captured CLI bindings. The related merged login-refresh PR addresses subsequent login changes, while the open deduplication PR explicitly depends on this repair.
Findings None None.
Security None None.

How this fits together

OpenClaw’s model catalog combines configured models, plugin registrations, and prepared authentication facts. Its projections feed the CLI model list, Gateway model picker, and chat metadata.

flowchart TD
  A[Configured models] --> D[Prepared catalog owner]
  B[Plugin registry] --> D
  C[Authentication facts] --> D
  D --> E[Prepare model availability]
  E --> F[Published model projection]
  F --> G[CLI list and Gateway picker]
Loading

Before merge

None.

Agent review details

Security

None.

PR surface

Source +126, Tests +151. Total +277 across 6 files.

View PR surface stats
Area Files Added Removed Net
Source 3 255 129 +126
Tests 3 153 2 +151
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 6 408 131 +277

Review metrics

None.

Technical review

Best possible solution:

Keep registry-dependent facts with the prepared catalog owner while preserving inexpensive, current-generation published reads.

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

Yes: source shows standalone owners can register Claude CLI while ambient lookups miss it, and the contributor reports matching real baseline failures. This review did not execute a reproduction.

Is this the best way to solve the issue?

Yes: using the existing owner's registry repairs the shared preparation boundary without adding another registry owner, configuration option, or per-read discovery.

AGENTS.md: found and applied where relevant.

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

Labels

Label changes:

No label changes.

Label justifications:

  • P2: This fixes incorrect standalone refreshed model availability with a bounded catalog-projection change.
  • rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🐚 platinum hermit and patch quality is 🐚 platinum hermit.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Sufficient (live_output): The captured live-output comparison exercises standalone refreshed listing through the changed catalog preparation owner with real Claude login: ten canonical Anthropic rows become available instead of one unavailable default. Tests supplement that proof. No stored-data contract changes require migration.
  • proof: sufficient: Contributor real behavior proof is sufficient. The captured live-output comparison exercises standalone refreshed listing through the changed catalog preparation owner with real Claude login: ten canonical Anthropic rows become available instead of one unavailable default. Tests supplement that proof. No stored-data contract changes require migration.

Evidence

What I checked:

  • Introduced preparation boundary: The pinned introduced delta resolves the existing catalog owner before entering its registry scope. The returned reader remains outside this new scope; owner acquisition and current-authority checks are preserved in the extracted module. (src/gateway/server-methods/models-list-result.ts:83, c9796892845b)
  • Prepared runtime-choice facts: CLI backend bindings are captured from the decisions owner's registry once and reused by runtime-choice reads, replacing two ambient-registry lookups. (src/agents/model-catalog-decisions.ts:81, c9796892845b)
  • Current-main necessity: Inspected fetched main still lacks the owner-scoped preparation and captured CLI bindings. The related merged login-refresh PR addresses subsequent login changes, while the open deduplication PR explicitly depends on this repair. (src/agents/model-catalog-decisions.ts:75, fdcbcf5c2ebd)
  • Real standalone behavior: The captured PR body reports real onboarding and standalone models list --refresh --json with isolated state, a real logged-in Claude executable, no Gateway, and no Anthropic API key: baseline returned one unavailable anthropic row; the branch returned ten available anthropic rows. Five branch runs and fourteen baseline runs matched those results. This directly exercises the changed preparation owner. (c9796892845b)
  • Previous follow-up resolved: The captured body now records local wall times, per-file summed CI test times of 2.6, 2.1, and 2.9 seconds, separately labeled shared batch times, and unavailable whole-run timing due to cancellations. This satisfies the previous review's cost-record request. GitHub confirms the cited run used the reviewed head; the timing values remain contributor-reported. (c9796892845b)
  • Regression and published-read coverage: Read the complete changed test modules. Added cases protect standalone command output, shared prepared-owner availability, and alternative runtime choices with an empty ambient registry. Existing models.prepared coverage asserts repeated published reads enter no registry scope or SQLite statements. Tests were inspected, not executed. (src/gateway/server-methods/models-list-result.plugin-runtime.test.ts:422, c9796892845b)

Likely related people:

  • steipete: Suggested for follow-up; no historical authorship or introduction is verified. (role: unverified routing candidate; confidence: low)
  • obviyus: 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 (5 earlier review cycles)
  • reviewed 2026-10-07T00:27:48.298Z sha 355ced4 :: needs changes before merge. :: none
  • reviewed 2026-10-07T00:36:39.783Z sha 355ced4 :: needs changes before merge. :: none
  • reviewed 2026-10-07T01:09:50.791Z sha 4eaa9da :: needs changes before merge. :: none
  • reviewed 2026-10-07T01:29:19.056Z sha c979689 :: needs changes before merge. :: none
  • reviewed 2026-10-07T01:45:49.641Z sha c979689 :: needs changes before merge. :: none

@obviyus
obviyus marked this pull request as ready for review October 7, 2026 00:32
@obviyus

obviyus commented Oct 7, 2026

Copy link
Copy Markdown
Collaborator Author

@clawsweeper review

@clawsweeper

clawsweeper Bot commented Oct 7, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Exact review queued.

Re-review progress:

@openclaw-barnacle openclaw-barnacle Bot added agents Agent runtime and tooling size: L and removed size: M labels Oct 7, 2026
@obviyus

obviyus commented Oct 7, 2026

Copy link
Copy Markdown
Collaborator Author

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Oct 7, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Exact review queued.

Re-review progress:

hippoley commented Oct 7, 2026

Copy link
Copy Markdown

The remaining test-cost blocker looks resolvable from data already extracted by the latest ClawSweeper review.

The review records from run 37555824195:

  • successful shared test shard large-8-1: 165 s
  • cancelled shared test shard changed-1: 241 s elapsed before cancellation

Those are explicitly shared-shard CI measurements, not per-file timings. So the PR body can satisfy the current ask without inventing unavailable per-file CI data by adding something like:

CI cost: run 37555824195 recorded 165 s for the successful large-8-1 shared test shard. The changed-1 shared shard was cancelled after 241 s elapsed; no completed per-file CI duration is available from that shard. Local per-file timings remain the per-file measurement source.

That matches the current review wording: “labeling shared-shard totals separately from per-file timings and noting cancelled or unavailable measurements.”

@obviyus

obviyus commented Oct 7, 2026

Copy link
Copy Markdown
Collaborator Author

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Oct 7, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Exact review queued.

Re-review progress:

@obviyus
obviyus merged commit dd76168 into main Oct 7, 2026
255 of 275 checks passed
@obviyus
obviyus deleted the fix/models-list-owner-registry-scope branch October 7, 2026 02:11
obviyus added a commit that referenced this pull request Oct 7, 2026
…6311)

Related: #153707, #82546, #166361

## What Problem This Solves

Fixes: the Control UI model picker lists every Claude model twice, both labelled "Claude CLI · native", after `openclaw onboard` sets up Claude CLI. `openclaw models list` without a running Gateway shows the same duplicates.

## User Impact

People who chose Claude CLI during onboarding now see each Claude model once: the configured `anthropic/*` row, which keeps its alias, its Default tag and the Claude CLI route label. API rows and Claude CLI rows stay separate, and `claude-cli/*` models you haven't configured (for example Haiku 4.5) still appear. Standalone `openclaw models list --refresh` lists the same rows as the picker.

## Why This Change Was Made

Onboarding pins each `anthropic/claude-*` model to `agentRuntime: claude-cli`. That pin is deliberate: without it, gateway turns fell through to Anthropic API billing (#82546, #84374), and Doctor canonicalizes `claude-cli/*` refs to `anthropic/*` plus the pin. The bundled Claude CLI catalog still publishes `claude-cli/<same model>`, so `models.list` returned two rows for one model on one route.

The `models.list` read (shared by `models.list`, `chat.metadata` and `openclaw models list`) now drops a `<cli-runtime>/<model>` row when the canonical `<modelProvider>/<model>` row is published on that runtime **and** config pins it there (`resolveModelRuntimePolicy`).

### Twin routes come from the catalog owner's registry

Which rows are twins is plugin policy: the CLI backend `modelProvider` bindings and the provider's catalog model id (`resolveProviderModelCatalogId`). Both are resolved from the same registry that decides availability:

- `createModelCatalogDecisions` exposes the CLI backend bindings it already resolves from the owner's `pluginRegistry` as `cliRuntimeBindings`.
- `resolveCliRuntimeTwinRoute` runs during preparation, inside `prepareEntry`, which runs in the owner's registry scope. It maps a `claude-cli/*` row to its canonical provider, resolves the catalog model id, and reads the config pin with the runtime id normalized (so a padded or mixed-case ` Claude-CLI ` pin still matches).
- The read path stays a pure projection. `omitCliRuntimeAliasTwins` only compares the prepared twin routes with each row's own `agentRuntime`; it calls no plugin or registry code. This keeps the Gateway and the standalone CLI (whose ambient registry differs from the owner's, see #166361) on the same answer.

### Selection policies keep the alias

A `claude-cli/*` row stays when some selection policy allows it but not its `anthropic/*` twin. The policies checked are the agent's manual model policy and every `gateway.roles.definitions[*].modelPolicy`, prepared once with the owner's manifest metadata. So an operator role or agent policy that allows only `claude-cli/*` still sees those rows and can select them.

These are left alone too:
- canonical rows on Claude CLI only because of a session runtime override. Choosing that row (or Default) resets to the configured route, so the CLI twin is still a different choice;
- rows whose canonical twin runs on another runtime, such as the API route;
- the `all` inventory view.

No selected-row exception is needed. Session display identity already maps CLI runtime refs to their canonical provider (`resolveSessionDisplayModelIdentityRefCached`, `src/gateway/session-utils-model.ts`), so a session on `claude-cli/claude-opus-5` renders as `anthropic/claude-opus-5` and the picker checks that row.

This keeps #153707's invariant (API and Claude CLI routes stay distinguishable) and removes the second copy of the same route. The CLI wizard picker already hides CLI runtime providers (`createModelPickerVisibleProviderPredicate`); only `models.list` was missing the canonical collapse.

## Evidence

Isolated macOS run on this head (4d4b7cf) and on origin/main (2beca62), both built with `pnpm build`. State, config and `HOME` were under /tmp, the Gateway had its own port, and there was no Anthropic API key. Config came from the real `openclaw onboard --non-interactive --auth-choice anthropic-cli`, with Claude Code logged in through a copied credentials file in an isolated `CLAUDE_CONFIG_DIR`. Before and after use the same state.

Gateway `models.list`, Claude rows:

| view | origin/main | this head |
|---|---|---|
| `configured` | 10 `anthropic/*` on `claude-cli` + 11 `claude-cli/*` | 10 `anthropic/*` on `claude-cli` + `claude-cli/claude-haiku-4-5`, `claude-cli/claude-mythos-5` |
| `default` | 10 `anthropic/*` on `claude-cli` + 11 `claude-cli/*` | 10 `anthropic/*` on `claude-cli` + `claude-cli/claude-haiku-4-5`, `claude-cli/claude-mythos-5` |
| `all` | 10 `anthropic/*` + 12 `claude-cli/*` | 10 `anthropic/*` + 12 `claude-cli/*` (unchanged) |

Standalone `openclaw models list --refresh --json` (same state, `OPENCLAW_GATEWAY_PORT` unset, no Gateway running), Claude rows:

| | origin/main | this head |
|---|---|---|
| `anthropic/*` | 10 rows, all `available: true` on `claude-cli` | 10 rows, all `available: true` on `claude-cli` |
| `claude-cli/*` | 11 rows | `claude-haiku-4-5`, `claude-mythos-5` |
| runs matching | 5 of 5 | 3 of 3 |

Every `claude auth status` probe in these runs exited 0 (0.13–2.1 s).

Control UI model picker:

| | origin/main | this head |
|---|---|---|
| search "opus 5.5" | 2 rows (Default row plus a second "Claude CLI · native" copy) | 1 row (the Default row) |
| search "sonnet 5" | 4 rows for two models | 2 rows |
| unfiltered groups | Anthropic 10 / Claude CLI 11 | Anthropic 10 / Claude CLI 2 |

Search "opus 5.5":

| origin/main | this head |
|---|---|
| ![origin/main: Claude Opus 5.5 listed twice on the Claude CLI route](https://github.com/user-attachments/assets/3c6f10fd-8c3e-48f2-9247-f2fd409d59aa) | ![this head: Claude Opus 5.5 listed once](https://github.com/user-attachments/assets/8b7cf849-b292-42cd-81e0-803cd8d16c80) |

Search "sonnet 5":

| origin/main | this head |
|---|---|
| ![origin/main: Sonnet 5 and Sonnet 5.5 each listed twice](https://github.com/user-attachments/assets/339dc319-8c80-45fc-a0e7-3241506e122d) | ![this head: Sonnet 5 and Sonnet 5.5 listed once](https://github.com/user-attachments/assets/1b0001ca-61fd-43d7-8a2f-602d2e8c7aca) |

Tests:
- `list.prepared-catalog.test.ts`: the real `openclaw models list` command with a standalone owner whose registry alone has Claude CLI. It lists `anthropic/claude-opus-5` and `claude-cli/claude-haiku-4-5`, without the `claude-cli/claude-opus-5` twin.
- `models-list-result.plugin-runtime.test.ts`: Gateway `buildModelsListResult` with an empty active registry and Claude CLI only in the owner's registry. Configured and default views drop the twin; a role allowing only `claude-cli/*` and an agent `modelPolicy` allowing only `claude-cli/*` keep it.
- `model-runtime-aliases.test.ts`: twin-rule boundary table. Kept: a canonical row on Claude CLI only through a session override, an API-routed canonical row, and their CLI twins; a padded, mixed-case runtime pin (` Claude-CLI `) still collapses; a role allowing only Claude CLI rows keeps them.
- Red/green: both owner-registry tests fail when the collapse reads the ambient registry at read time, and pass on this head. The role and agent-policy cases fail without the selection-policy rule and pass now.
- On this head: `tsgo:core` and `tsgo:test:src` pass; 474 vitest tests pass across `model-runtime-aliases`, `models-list-result.*`, `models.test`, `models.prepared`, `models-list.*`, `chat-metadata-*`, `model-discovery-policy` and `commands/models/list.*`. `node scripts/check-changed.mjs` fails only the full-tree dead-export scan (7 unused exports in `src/agents/auth-profiles.runtime.ts`, untouched here), which fails the same way on origin/main 2beca62.

Known and unchanged:
- `anthropic/claude-opus-4-7`, `-4-6` and `claude-sonnet-4-6` already showed raw ids on main, because the Anthropic API catalog has no entries for them without an API key.

## Bounded cost

- Twin routes are resolved once per catalog entry during preparation, which already runs per entry: a binding lookup, a config runtime-policy lookup and a catalog-id lookup. Role model policies are prepared once per prepared result, alongside the catalog; reads reuse them.
- Each read makes two passes over the already-projected rows: one map build and one filter. Only `claude-cli/*` rows whose canonical twin is listed on the same runtime check the selection policies.
- No new state, config or protocol change, and no new warnings or messages. The `all` view skips the work.

Test wall time on this head: locally with `pnpm test <file> --maxWorkers=1` (transform is 72–92% of each), and the Vitest duration in CI run 37568557325 (shard wall time in parentheses):

| file | tests | local | CI |
|---|---|---|---|
| `src/agents/model-runtime-aliases.test.ts` | 23 | 18.9 s | 6.8 s (9.5 s) |
| `src/commands/models/list.prepared-catalog.test.ts` | 18 | 21.0 s | 15.2 s (17.1 s) |
| `src/gateway/server-methods/models-list-result.plugin-runtime.test.ts` | 15 | 23.8 s | 7.6 s (8.9 s) |

LOC: production +118/-13, docs +5/-2, tests +184/-16.
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Oct 7, 2026
…egistry (openclaw#166361)

Prerequisite for openclaw#166311.

## What Problem This Solves

Fixes: without a running Gateway, `openclaw models list --refresh` lists every configured `anthropic/*` model that runs through Claude CLI as unavailable, even when Claude Code is logged in. Only the default row is left (unavailable); the usable models show up only as their `claude-cli/*` copies.

## User Impact

After `openclaw onboard --auth-choice anthropic-cli`, `openclaw models list --refresh` without a Gateway now lists the configured Claude models as available on Claude CLI, the same as the Gateway picker. Gateway output doesn't change.

## Why This Change Was Made

A prepared model-catalog owner carries its own plugin registry, and that registry can differ from the process's active one. The standalone `openclaw models list` and the embedded TUI use a temporary owner, and Gateway owners belong to a workspace generation. `prepareModelsListResult` already passes `owner.pluginRegistry` to some calls, but CLI backend bindings, Claude CLI auth evaluation and runtime choices still read the ambient registry (for example `listCliRuntimeModelBackendBindings()` in `model-catalog-decisions.ts`). The standalone command's active registry has no CLI backends. So `anthropic/*` rows pinned to `claude-cli` fail auth, and the default view drops 9 of the 10.

`prepareModelsListResult` now resolves the owner first (`resolveModelsListOwner`), then runs preparation inside `withPluginRuntimeRegistryScope(owner.pluginRegistry, …)`, the helper the row projection already uses for worker placement. Reads stay pure projections of the prepared facts and never enter a plugin scope, keeping openclaw#162326's published-read invariant (`models.prepared.test.ts`); the existing per-row worker-placement scope is kept as is. The one read-time plugin fact, the CLI backend bindings behind picker runtime choices, is now resolved once from the decisions owner's `pluginRegistry` in `createModelCatalogDecisions` instead of from the ambient registry on every read. The scoped preparation covers every `prepareModelsListResult` caller: the Gateway handler, `chat.metadata`, the standalone CLI, the TUI and the preloaded projector. Not covered and unchanged: uncached runtime-choice auth evaluations (`model-auth-availability.ts`) and `chat-metadata-session-projection.ts` projecting its preloaded catalog before preparation still read the ambient registry; the tests here don't claim those paths. Owner resolution moved unchanged into `models-list-result.owner.ts`, because `models-list-result.ts` is at the repository line cap.

One existing runtime-choices case changed its fixture: `picker-fixture` + generic harness `picker-native` → `picker-fixture` + `codex`. The old case only came out `unsupported-runtime` because the registered fixture harness was invisible to ambient-registry lookups. A registered generic harness is compatible with any provider, while `codex` explicitly rejects non-OpenAI providers (`session-runtime-compat.ts`), so the case still asserts "registered harness, incompatible provider → `unsupported-runtime`".

openclaw#166311 (one picker row per Claude CLI model) depends on this. Its twin collapse has to read CLI backends from the same registry as availability.

## Evidence

Live proof on the exact head `c9796892845`, rerun after the design changed (pure reads; decisions resolve CLI backend bindings from the owner registry). Setup is unchanged: `HOME`, state and config under /tmp, no Anthropic API key, config from the real `openclaw onboard --non-interactive --auth-choice anthropic-cli`, and Claude Code logged in through a copied credentials file in an isolated `CLAUDE_CONFIG_DIR`. Both checkouts were built with `pnpm build`, and runs alternated main/head one after the other.

Standalone `openclaw models list --refresh --json`, no Gateway running (stderr: "Gateway is not running. Refreshing the local model catalog."):

| | origin/main (7fa4352) | this branch (c979689) |
|---|---|---|
| `anthropic/*` | 10 rows, all `available: false` | 10 rows, all `available: true` |
| `claude-cli/*` | 11 rows, all available | 11 rows, all available |

5 of 5 runs on each side matched its column. All three `claude auth status` probes finished in 0.15-0.44 s with exit 0 in every run, so no row depended on the probe timeout described below. (Current main now lists all 10 configured `anthropic/*` rows, where the earlier b7dc0bc showed only the default row. All 10 are still unavailable.)

Isolated Gateway on c979689 (`openclaw gateway run`, same state), `gateway call models.list`: `view: "configured"` and `view: "default"`, 3 calls each. Every call returned 10 `anthropic/*` rows, all `available: true` with `agentRuntime.id: "claude-cli"`, plus 11 `claude-cli/*` rows. The Gateway and standalone paths agree.

Earlier rounds on b7dc0bc vs this change (before the pure-read redesign) matched too: 14 runs on origin/main and 5 on the branch, plus 23 inside openclaw#166311.

Tests, both through the real consumer:
- `list.prepared-catalog.test.ts`: the real `openclaw models list` command, with a standalone owner whose registry alone has the Claude CLI backend. On origin/main it fails with `anthropic/claude-opus-5` `available: false`; here it passes.
- `models-list-result.plugin-runtime.test.ts`: a prepared owner reached through `prepareModelsListResult`, as the Gateway and `chat.metadata` reach it, with an empty active registry. It fails on origin/main and also fails when only `buildModelsListResult` is scoped; here it passes.
- `models-list-result.plugin-runtime.test.ts` (runtime choice): a configured `anthropic/claude-opus-5` with `pickerRuntimes: ["openclaw", "claude-cli"]`, owner registry with the Claude CLI backend, empty active registry. Before the decisions fix the `claude-cli` choice reads `available: false`; now `true`.
- `models-list-result.*`, `models*.test.ts` (incl. `models.prepared.test.ts`), `chat-metadata*`, `src/commands/models/list*`, `model-catalog-decisions` and `models.test.ts` passed on this change. `tsgo:core:test` and `node scripts/check-changed.mjs` passed too.

### First run after a rebuild showing only `anthropic/claude-opus-5-5 false`

During the work on openclaw#166311, one standalone run of the fixed code came back like origin/main's logged-out output: only `anthropic/claude-opus-5-5`, `available: false`, and no `claude-cli/*` rows. That isn't this change, and it isn't a build artifact. It's the existing Claude login probe:
- A standalone list runs `claude auth status --json` three times (`extensions/anthropic/cli-auth-seam.ts`, 3 s timeout). If the second probe times out, it counts as unreadable, so every Claude row is unavailable.
- Delaying exactly that probe to 3.5 s gives the identical output on origin/main, on this branch and on openclaw#166311. Delaying the first or third probe changes nothing.
- Observed probe times ranged from 0.14 s to 3.0 s; the slow ones came when several `claude` processes shared one config dir. Once in 23 runs, during a concurrent test run, the slow case happened on its own: that run took 4 s longer and logged only two completed probes.
- "Right after a rebuild" was a coincidence. Every `run-node` call in that session rebuilt because the tree was dirty, and the other rebuild runs were correct.
- On a Gateway, openclaw#166305's background recheck corrects a timed-out probe within a minute.

Known and unchanged: the read-only `openclaw models list` (no `--refresh`, no Gateway) reads a cached owner that has no plugin registry. It still shows the single unavailable default row.

## Bounded cost

- One AsyncLocalStorage frame around preparation and one CLI backend listing per decisions owner; none per `read()` (previously the bindings were listed on every runtime-choice read). No I/O, discovery or probing: with start-logging, every standalone list started three `claude auth status` probes on both origin/main and this branch.
- No new state, config, protocol or messages.
- Local test cost, `pnpm test <file> --maxWorkers=1` wall time (Apple Silicon): `src/commands/models/list.prepared-catalog.test.ts` 33.5 s (17 tests, vitest 28.3 s) and `src/gateway/server-methods/models-list-result.runtime-choices.test.ts` 30.2 s (9 tests, vitest 26.9 s), both measured on 355ced4 and unchanged since; `src/gateway/server-methods/models-list-result.plugin-runtime.test.ts` 40.5 s (11 tests, vitest 32.8 s) on c979689. Transform dominates (75-80%); test bodies are 12-17%.
- CI test cost, run [37555824195](https://github.com/openclaw/openclaw/actions/runs/37555824195) on c979689, summed per-test times per file: `list.prepared-catalog` 2.6 s (17 tests, shard `agentic-commands-models`), `models-list-result.runtime-choices` 2.1 s (9 tests, `agentic-gateway-methods-hosted-5`), `models-list-result.plugin-runtime` 2.9 s (11 tests, `agentic-gateway-methods-hosted-6`). Shared-shard totals, not per-file: those vitest batches took 16.9 s (8 files), 78.0 s (7 files) and 58.6 s (9 files). Several other shards in that run were cancelled by fail-fast after an unrelated red (see CI below), so no whole-run total is available.

LOC vs origin/main: +408/-131 total; 199 production lines are owner resolution moved verbatim into `models-list-result.owner.ts`; tests +153/-2.



## CI

On c979689, the only red test is `src/gateway/server.chat.gateway-server-chat-b.test.ts` > "chat.history advances past a replay boundary that cannot fit all projected siblings" (line 5681); the other failed jobs were cancelled by fail-fast. It fails 3/3 on clean origin/main 877a911 and passes 3/3 on this branch locally, so it's unrelated. The earlier 4eaa9da red, `src/flows/doctor-health.plugin-load.test.ts` (3 ENOSPC cases), also fails on clean origin/main 877a911.
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Oct 7, 2026
…nclaw#166311)

Related: openclaw#153707, openclaw#82546, openclaw#166361

## What Problem This Solves

Fixes: the Control UI model picker lists every Claude model twice, both labelled "Claude CLI · native", after `openclaw onboard` sets up Claude CLI. `openclaw models list` without a running Gateway shows the same duplicates.

## User Impact

People who chose Claude CLI during onboarding now see each Claude model once: the configured `anthropic/*` row, which keeps its alias, its Default tag and the Claude CLI route label. API rows and Claude CLI rows stay separate, and `claude-cli/*` models you haven't configured (for example Haiku 4.5) still appear. Standalone `openclaw models list --refresh` lists the same rows as the picker.

## Why This Change Was Made

Onboarding pins each `anthropic/claude-*` model to `agentRuntime: claude-cli`. That pin is deliberate: without it, gateway turns fell through to Anthropic API billing (openclaw#82546, openclaw#84374), and Doctor canonicalizes `claude-cli/*` refs to `anthropic/*` plus the pin. The bundled Claude CLI catalog still publishes `claude-cli/<same model>`, so `models.list` returned two rows for one model on one route.

The `models.list` read (shared by `models.list`, `chat.metadata` and `openclaw models list`) now drops a `<cli-runtime>/<model>` row when the canonical `<modelProvider>/<model>` row is published on that runtime **and** config pins it there (`resolveModelRuntimePolicy`).

### Twin routes come from the catalog owner's registry

Which rows are twins is plugin policy: the CLI backend `modelProvider` bindings and the provider's catalog model id (`resolveProviderModelCatalogId`). Both are resolved from the same registry that decides availability:

- `createModelCatalogDecisions` exposes the CLI backend bindings it already resolves from the owner's `pluginRegistry` as `cliRuntimeBindings`.
- `resolveCliRuntimeTwinRoute` runs during preparation, inside `prepareEntry`, which runs in the owner's registry scope. It maps a `claude-cli/*` row to its canonical provider, resolves the catalog model id, and reads the config pin with the runtime id normalized (so a padded or mixed-case ` Claude-CLI ` pin still matches).
- The read path stays a pure projection. `omitCliRuntimeAliasTwins` only compares the prepared twin routes with each row's own `agentRuntime`; it calls no plugin or registry code. This keeps the Gateway and the standalone CLI (whose ambient registry differs from the owner's, see openclaw#166361) on the same answer.

### Selection policies keep the alias

A `claude-cli/*` row stays when some selection policy allows it but not its `anthropic/*` twin. The policies checked are the agent's manual model policy and every `gateway.roles.definitions[*].modelPolicy`, prepared once with the owner's manifest metadata. So an operator role or agent policy that allows only `claude-cli/*` still sees those rows and can select them.

These are left alone too:
- canonical rows on Claude CLI only because of a session runtime override. Choosing that row (or Default) resets to the configured route, so the CLI twin is still a different choice;
- rows whose canonical twin runs on another runtime, such as the API route;
- the `all` inventory view.

No selected-row exception is needed. Session display identity already maps CLI runtime refs to their canonical provider (`resolveSessionDisplayModelIdentityRefCached`, `src/gateway/session-utils-model.ts`), so a session on `claude-cli/claude-opus-5` renders as `anthropic/claude-opus-5` and the picker checks that row.

This keeps openclaw#153707's invariant (API and Claude CLI routes stay distinguishable) and removes the second copy of the same route. The CLI wizard picker already hides CLI runtime providers (`createModelPickerVisibleProviderPredicate`); only `models.list` was missing the canonical collapse.

## Evidence

Isolated macOS run on this head (4d4b7cf) and on origin/main (5cc5969), both built with `pnpm build`. State, config and `HOME` were under /tmp, the Gateway had its own port, and there was no Anthropic API key. Config came from the real `openclaw onboard --non-interactive --auth-choice anthropic-cli`, with Claude Code logged in through a copied credentials file in an isolated `CLAUDE_CONFIG_DIR`. Before and after use the same state.

Gateway `models.list`, Claude rows:

| view | origin/main | this head |
|---|---|---|
| `configured` | 10 `anthropic/*` on `claude-cli` + 11 `claude-cli/*` | 10 `anthropic/*` on `claude-cli` + `claude-cli/claude-haiku-4-5`, `claude-cli/claude-mythos-5` |
| `default` | 10 `anthropic/*` on `claude-cli` + 11 `claude-cli/*` | 10 `anthropic/*` on `claude-cli` + `claude-cli/claude-haiku-4-5`, `claude-cli/claude-mythos-5` |
| `all` | 10 `anthropic/*` + 12 `claude-cli/*` | 10 `anthropic/*` + 12 `claude-cli/*` (unchanged) |

Standalone `openclaw models list --refresh --json` (same state, `OPENCLAW_GATEWAY_PORT` unset, no Gateway running), Claude rows:

| | origin/main | this head |
|---|---|---|
| `anthropic/*` | 10 rows, all `available: true` on `claude-cli` | 10 rows, all `available: true` on `claude-cli` |
| `claude-cli/*` | 11 rows | `claude-haiku-4-5`, `claude-mythos-5` |
| runs matching | 5 of 5 | 3 of 3 |

Every `claude auth status` probe in these runs exited 0 (0.13–2.1 s).

Control UI model picker:

| | origin/main | this head |
|---|---|---|
| search "opus 5.5" | 2 rows (Default row plus a second "Claude CLI · native" copy) | 1 row (the Default row) |
| search "sonnet 5" | 4 rows for two models | 2 rows |
| unfiltered groups | Anthropic 10 / Claude CLI 11 | Anthropic 10 / Claude CLI 2 |

Search "opus 5.5":

| origin/main | this head |
|---|---|
| ![origin/main: Claude Opus 5.5 listed twice on the Claude CLI route](https://github.com/user-attachments/assets/3c6f10fd-8c3e-48f2-9247-f2fd409d59aa) | ![this head: Claude Opus 5.5 listed once](https://github.com/user-attachments/assets/8b7cf849-b292-42cd-81e0-803cd8d16c80) |

Search "sonnet 5":

| origin/main | this head |
|---|---|
| ![origin/main: Sonnet 5 and Sonnet 5.5 each listed twice](https://github.com/user-attachments/assets/339dc319-8c80-45fc-a0e7-3241506e122d) | ![this head: Sonnet 5 and Sonnet 5.5 listed once](https://github.com/user-attachments/assets/1b0001ca-61fd-43d7-8a2f-602d2e8c7aca) |

Tests:
- `list.prepared-catalog.test.ts`: the real `openclaw models list` command with a standalone owner whose registry alone has Claude CLI. It lists `anthropic/claude-opus-5` and `claude-cli/claude-haiku-4-5`, without the `claude-cli/claude-opus-5` twin.
- `models-list-result.plugin-runtime.test.ts`: Gateway `buildModelsListResult` with an empty active registry and Claude CLI only in the owner's registry. Configured and default views drop the twin; a role allowing only `claude-cli/*` and an agent `modelPolicy` allowing only `claude-cli/*` keep it.
- `model-runtime-aliases.test.ts`: twin-rule boundary table. Kept: a canonical row on Claude CLI only through a session override, an API-routed canonical row, and their CLI twins; a padded, mixed-case runtime pin (` Claude-CLI `) still collapses; a role allowing only Claude CLI rows keeps them.
- Red/green: both owner-registry tests fail when the collapse reads the ambient registry at read time, and pass on this head. The role and agent-policy cases fail without the selection-policy rule and pass now.
- On this head: `tsgo:core` and `tsgo:test:src` pass; 474 vitest tests pass across `model-runtime-aliases`, `models-list-result.*`, `models.test`, `models.prepared`, `models-list.*`, `chat-metadata-*`, `model-discovery-policy` and `commands/models/list.*`. `node scripts/check-changed.mjs` fails only the full-tree dead-export scan (7 unused exports in `src/agents/auth-profiles.runtime.ts`, untouched here), which fails the same way on origin/main 5cc5969.

Known and unchanged:
- `anthropic/claude-opus-4-7`, `-4-6` and `claude-sonnet-4-6` already showed raw ids on main, because the Anthropic API catalog has no entries for them without an API key.

## Bounded cost

- Twin routes are resolved once per catalog entry during preparation, which already runs per entry: a binding lookup, a config runtime-policy lookup and a catalog-id lookup. Role model policies are prepared once per prepared result, alongside the catalog; reads reuse them.
- Each read makes two passes over the already-projected rows: one map build and one filter. Only `claude-cli/*` rows whose canonical twin is listed on the same runtime check the selection policies.
- No new state, config or protocol change, and no new warnings or messages. The `all` view skips the work.

Test wall time on this head: locally with `pnpm test <file> --maxWorkers=1` (transform is 72–92% of each), and the Vitest duration in CI run 37568557325 (shard wall time in parentheses):

| file | tests | local | CI |
|---|---|---|---|
| `src/agents/model-runtime-aliases.test.ts` | 23 | 18.9 s | 6.8 s (9.5 s) |
| `src/commands/models/list.prepared-catalog.test.ts` | 18 | 21.0 s | 15.2 s (17.1 s) |
| `src/gateway/server-methods/models-list-result.plugin-runtime.test.ts` | 15 | 23.8 s | 7.6 s (8.9 s) |

LOC: production +118/-13, docs +5/-2, tests +184/-16.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agents Agent runtime and tooling commands Command implementations gateway Gateway runtime P2 Normal backlog priority with limited blast radius. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. size: 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.

2 participants