Repository navigation
fix(models): recheck Claude CLI login for model lists after Gateway startup - #166305
Conversation
|
🦞👀 Pull request received. I will update this pull request when review starts. ClawSweeper review completeClawSweeper finished reviewing this revision. The review result is being finalized. |
|
Codex review: needs maintainer review before merge. Reviewed October 6, 2026, 6:41 PM ET / 22:41 UTC (Revision 5). ClawSweeper reviewWhat this changesThe PR refreshes Claude CLI login availability during model-list reads, publishes changed availability, and adds documentation and login/logout regression coverage. Merge readiness✅ Ready for maintainer review The PR remains useful: current main still retains startup login availability during ordinary model-list reads. No actionable patch defect remains, the earlier polling finding is resolved, and the inspected live evidence supports the fix. Priority: P2 Review scores
Verification
How this fits togetherThe prepared model catalog combines configured models with provider authentication facts. Gateway model-list requests consume that catalog to determine which models the picker can offer. flowchart TD
A[Model list request] --> B[Prepared catalog owner]
B --> C[One minute recheck window]
C --> D[Scoped auth worker]
D --> E[Claude login status]
E --> F[Changed availability]
F --> G[Catalog publication]
G --> H[Model picker]
Before mergeNone. Agent review detailsSecurityNone. PR surfaceSource +79, Tests +48, Docs +2, Other -2. Total +127 across 8 files. View PR surface stats
Review metrics
Technical reviewBest possible solution: Keep login availability fresh through the existing catalog owner while preserving bounded probes, native credential ownership, and unchanged model-routing preferences. Do we have a high-confidence way to reproduce the issue? Yes: start the Gateway logged out, log Claude in afterward, and reread the model picker without explicit refresh. Current-main source and the contributor's paired live observations establish the stale availability path; this review did not execute it. Is this the best way to solve the issue? Yes: extending the existing catalog renewal owner avoids a separate refresh loop and retains scoped auth loading, lifecycle checks, and publication semantics. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against dd619529b24a. LabelsLabel changes: No label changes. Label justifications:
EvidenceWhat I checked:
Likely related people:
Rating scale
Overall follows the weaker of proof and patch quality. Workflow
HistoryReview history (4 earlier review cycles)
|
205a1b7 to
95b44d6
Compare
|
@clawsweeper review |
|
🦞👀 Re-review progress:
|
|
|
@clawsweeper re-review |
|
🦞👀 Re-review progress:
|
|
@clawsweeper re-review |
|
🦞👀 Re-review progress:
|
…ason (#166338) ## What Problem This Solves Claude Code is installed but logged out, and onboarding has pinned the `anthropic/*` models to the `claude-cli` runtime. In that state the Control UI chat picker shows only the default model. It is disabled, has no reason, and the header says "No models available". The other 9 pinned models disappear, so a non-technical user cannot tell what is wrong or how to fix it. ## Root cause and provenance There are two causes. Both were reproduced live on an isolated Gateway, with debug logging that has since been removed. 1. **The login reason is held back until the full catalog finishes.** `evaluateCliRuntimeModelAuthAvailability` only reports `missing-auth` once `preparedSyntheticAuthComplete` is true. That gate came from #134463 (84e8133), and it exists for a good reason. The full-catalog worker finds direct CLI routes *after* startup, so their login has not been checked yet. In the words of #134463: "the full-catalog worker prepared synthetic auth only for providers present in the configured startup scope". The gate is too broad for runtimes the config already names. Preparation already checks their login at startup: `collectPreparedModelRuntimeProviderIds` adds every configured harness runtime to the startup provider scope, and `prepared-model-runtime.facts.ts` checks the synthetic auth of that scope. Meanwhile the picker never asks for a full refresh ("Opening the picker reuses prepared catalog facts; explicit Refresh owns discovery", per docs/concepts/models.md). Live logging showed the catalog stayed incomplete, with `anthropic` and `claude-cli` missing from inventory, until someone ran an explicit `refresh`. So the startup check had already returned "logged out", but the picker never displayed it. 2. **Configured rows are hidden when they are not signed in.** With an allow-any policy, the configured view lists only inline provider rows, rows that are signed in, and the default and fallbacks. Each `agents.defaults.models` key is in `configuredKeys` and is tagged `configured`, but it was only listed while signed in. This is a side effect of #110888 (09a64f7). That change made the `models` map metadata only. Before it, any entry turned the map into a closed allowlist, and allowlisted rows always showed. #113594 also promised that "nobody's pinned model disappears". Earlier decisions are kept: - The per-model `claude-cli` pins (#82546, #84374) are kept, and so is Doctor's canonicalization. - #134463 still applies to routes found later and to runtimes that are not configured: their availability stays unknown until the full catalog arrives. - #166305's 60-second login recheck is unchanged. After `claude auth login`, the rows still turn available without a restart. ## Fix - `src/agents/model-auth-availability.cli-runtime.ts`: a configured runtime with no prepared runtime auth mode now gets `missing-auth` even before the full catalog arrives. "Configured" is decided by the same `collectPreparedModelRuntimeProviderIds` set that startup checks, computed once per resolver and only on this path. The CLI-runtime evaluator moved here from `model-auth-availability.ts` unchanged, because the line-cap ratchet does not allow that file to grow (-108 lines there). - `src/agents/model-catalog-visibility.ts`: configured refs now stay in the default and configured views, shown as unavailable, until their login or key comes back. This uses the same `configuredKeys` that already keeps deprecated configured rows visible. - Control UI: if the picker has no usable model and a Claude CLI row reports `missing-auth`, the empty-state label becomes "Claude Code isn't ready. If signed out, run claude auth login." instead of "No models available". "Manage models" stays next to it. The copy is conditional on purpose. `missing-auth` on a Claude CLI row also covers a disabled or denied anthropic plugin and a missing personal-account pin, so an already signed-in user can see it. The reason enum (`missing-auth` | `auth-failed` | `cooldown`) is closed and shared with the Swift and Kotlin clients, and no existing value fits a disabled plugin, so this PR keeps the protocol unchanged and words the hint to stay true in every `missing-auth` case. `claude auth login` is the command OpenClaw's own hints already use (`oauth-refresh-failure.ts`, `doctor-claude-cli.ts`, `extensions/anthropic/auth.runtime.ts`). `claude setup-token` makes an API token for the Anthropic provider; it does not log in the CLI runtime. - Channel `/models` (`commands-models-menu.ts`): for Claude CLI rows reporting `missing-auth`, the recovery line now uses the same wording as the picker hint ("If Claude Code is signed out, run claude auth login on the Gateway host, or choose another model.") instead of `/login anthropic`. Other routes are unchanged. - `docs/concepts/models.md`: documents that configured models stay listed as unavailable, and adds the Claude Code login line. No new config keys and no protocol changes: the existing `missing-auth` value is reused. ## Evidence Isolated Gateway on this Mac with state, config and `CLAUDE_CONFIG_DIR` under /tmp. The config is the one written by the real `openclaw onboard --non-interactive --auth-choice anthropic-cli`. The logged-out state is a fresh, empty `CLAUDE_CONFIG_DIR` (`claude auth status` → `loggedIn: false`). The logged-in run uses a wrapper that answers only `claude auth status` with `loggedIn: true`. No real Claude login was touched. Screenshots retaken on the final head (36b263f) and on origin/main (2c620bb), each from its own isolated Gateway: | | Logged out | Logged in | |---|---|---| | origin/main |  |  | | this branch |  |  | Picker contents (search "Claude"): - **origin/main, logged out:** "No models available"; one `anthropic/*` row (the default), no reason. - **This branch, logged out:** "Claude Code isn't ready. If signed out, run claude auth login."; all 10 pinned `anthropic/*` rows listed with "Sign-in needed". - **Logged in:** no empty-state label, and the same 23 picker rows in the same order on both heads. ### Telegram Test Server (`/models anthropic`) Ran the repository's Telegram userbot runner on the Telegram Test Server with a Convex-leased bot and QA user (`run-mock-sut-user-e2e.mjs --dm --scenario`). The runner starts a fresh Gateway from each checkout's build. The config patch adds two configured `anthropic/*` models pinned to `claude-cli` and enables the anthropic plugin. `CLAUDE_CONFIG_DIR` points at an empty directory, so Claude Code is logged out. The QA user sends `/models anthropic` at 1 s and again at 40 s, after startup discovery. `/models` is a native command, so no model turn runs; the only mock-provider rows are two `/` readiness probes. | | 1 s | 40 s | |---|---|---| | origin/main `2c620bbfe84c` | "anthropic: checking models…" | "Unknown provider: anthropic … Available providers: • openai". The configured Claude CLI models are gone. | | this branch `45dce1142171` | "Models (anthropic) — 0 of 2 available … anthropic: Sign-in needed. If Claude Code is signed out, run claude auth login on the Gateway host, or choose another model." Buttons: `…needed — Claude CLI · claude-opus-4-7`, `…eded — Claude CLI · claude-sonnet-4-6`, `<< Back`. | Same reply and buttons. | The `…` at the start of the button labels comes from Telegram's existing button-length truncation; this PR does not touch it. `models.list {view: "configured"}`, logged out, no refresh: - **origin/main:** 1 `anthropic/*` row (the default), `available: false`, no reason. - **This branch:** all 10 pinned `anthropic/*` rows, `available: false`, `unavailableReason: "missing-auth"`. - **Logged in:** the configured-view rows, runtimes and availability on this branch are identical to the origin/main capture of the same config. The duplicate `claude-cli/*` rows in the screenshots are the existing twins; #166311 removes them. ## Tests - `models-list-result.cli-runtime-availability.test.ts`, new case: an onboarding-shaped config, Claude logged out, catalog incomplete, configured view, run through the real `buildModelsListResult`. Every pinned row is listed with `missing-auth`, and the unpinned API row stays hidden. It fails on origin/main for both causes (rows missing, no reason). - `models.test.ts`: the existing table row for "logged out, catalog incomplete" now expects `missing-auth`, because the runtime is configured. It fails on origin/main. - `chat-model-catalog-state.test.ts`: the real `renderChatModelPicker`, given a `missing-auth` Claude CLI row, renders exactly the conditional Claude Code hint (the same row a signed-in user gets when the anthropic plugin is disabled, which `models-list-result.cli-runtime-availability.test.ts` already covers on the producer side). Other providers keep "No models available". It fails on origin/main (`expected 'No models available'`). - `commands-models.catalog-recovery.test.ts` and `commands-models.test.ts` go through the real `/models` handler, which reads the same projection as the picker. A CLI-bound configured model is now listed in every auth state. It is marked "Sign-in needed" unless its prepared native login is present and its plugin is enabled. Its recovery line reads "If Claude Code is signed out, run claude auth login on the Gateway host, or choose another model." instead of `/login anthropic`, which can't fix a Claude Code login or a disabled plugin. A logged-out configured Claude CLI default now gets that recovery line instead of "Connection not confirmed". The #139848 rule still holds: with only an API key, the bound row shows "Sign-in needed" and is not available. - Wall time with `pnpm test <file> --maxWorkers=1`: 35 s, 37 s and 3 s. The new gateway case takes 325 ms. No timers and no new fixtures. - Also run: affected suites (`model-catalog*`, `model-auth-availability*`, `model-selection*`, `server-methods/models*`, `commands/models`, the chat picker UI and new-session), all passing. `node scripts/check-changed.mjs` exits 0 (tsgo core and UI, lint, import cycles, line-cap ratchet, i18n). ## Bounded cost - No new processes, probes, network calls or catalog work. The existing startup `claude auth status` check and #166305's 60-second recheck are unchanged. - The configured-runtime set is built at most once per auth resolver, which is one per `models.list` read. It is built only when a CLI-runtime row has no prepared login, and it is a pure walk over the config's model refs. - Visibility adds one `Set.has` per catalog row. The UI adds one `.some()` over picker options per render. - Picker size is bounded by configured refs: at most the number of models the user authored, and they were already listed while signed in. ## User impact A logged-out Claude Code user sees every configured Claude model, greyed with "Sign-in needed", and a header that names the command to run. Once `claude auth login` succeeds, the rows turn available on the next read after #166305's recheck. Configured models for other providers that have lost their key now also stay listed as unavailable instead of disappearing. The channel `/models` command shows the same rows marked "Sign-in needed", and Claude CLI rows get the conditional `claude auth login` recovery line. The logged-in picker is unchanged. ## LOC vs origin/main Production +182/-118. The moved evaluator accounts for +147/-112 and is unchanged apart from the configured-runtime check, so the behaviour change itself is about +35. Tests +82/-12. Docs +3/-1. Co-authored-by: Ayaan Zaidi <[email protected]>
…egistry (#166361) 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 #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, #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 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.
…tartup (openclaw#166305) ## What Problem This Solves Fixes: Claude CLI models stay hidden or disabled in the Control UI model picker and `openclaw models list` when Claude Code was logged out at Gateway start and the user logs in afterwards; only a Gateway restart or `models.list {refresh: true}` fixed it. A logout after startup was never reflected either. ## User Impact User impact: after `claude auth login` (or a logout), the picker shows the right Claude CLI models within about a minute, without restarting the Gateway or reloading the page. How a logged-out Claude is displayed is unchanged. ## Why This Change Was Made - The picker's availability filter already counts Claude Code's own login: `evaluateCliRuntimeModelAuthAvailability` reads the `claude-cli` auth mode from the `claude auth status --json` probe in `extensions/anthropic/provider-discovery.ts`. - openclaw#129346 (f4ade71) made that probe run once per config generation so that "repeated model-list requests do not repeatedly launch the Claude CLI". openclaw#139757 (13a4405) shared it across agent workspaces after 632-agent rosters timed out at startup, and documented that "explicit catalog/auth captures recheck availability". - Nothing on the ordinary-read path rechecked it: `refreshExpiredModelCatalog` only renews providers with an inventory `expiresAt`, and the static `claude-cli` provider never gets one. So the startup result stayed for the whole generation. The existing ordinary-read renewal hook now also rechecks CLI-backend native logins (CLI backends whose manifest declares `syntheticAuthRefs`, which today means `claude-cli`). The recheck runs in the background, deduplicates through the worker's existing `loadAuth`, and publishes a new catalog through the existing native-publication path only when the login state changed. The explicit `loadAuth` refresh and the recheck share one scoped-auth merge in `prepared-model-runtime.catalog-auth.ts`; `loadAuth` still returns only `{ authStore, authModes }`. Startup still probes once per shared generation, so both earlier PRs' cost limits hold. ## Bounded cost - At most one `claude auth status --json` (existing 3 s timeout, process-tree kill) per prepared catalog owner per 60 s, and only while model lists are being read. An idle Gateway spawns nothing. - Picker opens inside the window spawn nothing; concurrent reads share one in-flight probe. - Nothing is published, and no catalog event is emitted, when the login state is unchanged. - Measured on an isolated Gateway (below): 40 picker opens in 59 s started 1 probe; 14 opens during a 60 s login wait started 1 probe; probes were always at least 60 s apart. ## Evidence **Regression test.** `src/gateway/server.chat-cli-auth.test.ts` adds "publishes Claude login changes after Gateway startup". It runs the real in-process Gateway, the real Anthropic plugin and `models.list`; only the `claude` executable is a fixture, and it records each `auth status` probe. It checks that the model is unavailable at startup, that a login inside the recheck window spawns no probe, that the model becomes available after the window with exactly one more probe, and that a logout makes it unavailable again with exactly one more probe. Each transition awaits the catalog publication rather than polling. With origin/main's catalog code the login publication never arrives and the test times out at 90 s; on this branch it passes in about 5 s. The full file (7 tests), the prepared-runtime suites that share its test harness, and `node scripts/check-changed.mjs` pass on this branch. **Live Control UI, before and after.** Two isolated Gateways on one Mac, origin/main and this branch. State, config, `HOME` and `CLAUDE_CONFIG_DIR` were under /tmp, there was no Anthropic API key, and the config was shaped like our setup. Each used the real `claude` binary behind a wrapper that only counts `auth status` calls. Both started logged out. The login happened afterwards, by placing a Claude credentials file in each isolated `CLAUDE_CONFIG_DIR`. The picker was reopened in place and the page was never reloaded. | | origin/main | this branch | |---|---|---| | Before login |  |  | | After login |  |  | - origin/main: 6 minutes and 27 picker opens after login, `claude auth status` in the same `CLAUDE_CONFIG_DIR` reported `loggedIn: true`, but the picker still showed 2 Anthropic rows and all 11 Claude rows disabled. One probe in total, at startup. - This branch: all 15 Claude rows (6 configured `anthropic/*` and 9 `claude-cli/*`) were enabled on the first open after the window. After a logout they were disabled again on the next window. A re-login right after a recheck showed up after 60 s, with 14 picker opens and exactly 1 probe. LOC vs origin/main: production +104/-25, tests +51/-3, docs +3/-1. Co-authored-by: Ayaan Zaidi <[email protected]>
…ason (openclaw#166338) ## What Problem This Solves Claude Code is installed but logged out, and onboarding has pinned the `anthropic/*` models to the `claude-cli` runtime. In that state the Control UI chat picker shows only the default model. It is disabled, has no reason, and the header says "No models available". The other 9 pinned models disappear, so a non-technical user cannot tell what is wrong or how to fix it. ## Root cause and provenance There are two causes. Both were reproduced live on an isolated Gateway, with debug logging that has since been removed. 1. **The login reason is held back until the full catalog finishes.** `evaluateCliRuntimeModelAuthAvailability` only reports `missing-auth` once `preparedSyntheticAuthComplete` is true. That gate came from openclaw#134463 (47f0122), and it exists for a good reason. The full-catalog worker finds direct CLI routes *after* startup, so their login has not been checked yet. In the words of openclaw#134463: "the full-catalog worker prepared synthetic auth only for providers present in the configured startup scope". The gate is too broad for runtimes the config already names. Preparation already checks their login at startup: `collectPreparedModelRuntimeProviderIds` adds every configured harness runtime to the startup provider scope, and `prepared-model-runtime.facts.ts` checks the synthetic auth of that scope. Meanwhile the picker never asks for a full refresh ("Opening the picker reuses prepared catalog facts; explicit Refresh owns discovery", per docs/concepts/models.md). Live logging showed the catalog stayed incomplete, with `anthropic` and `claude-cli` missing from inventory, until someone ran an explicit `refresh`. So the startup check had already returned "logged out", but the picker never displayed it. 2. **Configured rows are hidden when they are not signed in.** With an allow-any policy, the configured view lists only inline provider rows, rows that are signed in, and the default and fallbacks. Each `agents.defaults.models` key is in `configuredKeys` and is tagged `configured`, but it was only listed while signed in. This is a side effect of openclaw#110888 (69e799e). That change made the `models` map metadata only. Before it, any entry turned the map into a closed allowlist, and allowlisted rows always showed. openclaw#113594 also promised that "nobody's pinned model disappears". Earlier decisions are kept: - The per-model `claude-cli` pins (openclaw#82546, openclaw#84374) are kept, and so is Doctor's canonicalization. - openclaw#134463 still applies to routes found later and to runtimes that are not configured: their availability stays unknown until the full catalog arrives. - openclaw#166305's 60-second login recheck is unchanged. After `claude auth login`, the rows still turn available without a restart. ## Fix - `src/agents/model-auth-availability.cli-runtime.ts`: a configured runtime with no prepared runtime auth mode now gets `missing-auth` even before the full catalog arrives. "Configured" is decided by the same `collectPreparedModelRuntimeProviderIds` set that startup checks, computed once per resolver and only on this path. The CLI-runtime evaluator moved here from `model-auth-availability.ts` unchanged, because the line-cap ratchet does not allow that file to grow (-108 lines there). - `src/agents/model-catalog-visibility.ts`: configured refs now stay in the default and configured views, shown as unavailable, until their login or key comes back. This uses the same `configuredKeys` that already keeps deprecated configured rows visible. - Control UI: if the picker has no usable model and a Claude CLI row reports `missing-auth`, the empty-state label becomes "Claude Code isn't ready. If signed out, run claude auth login." instead of "No models available". "Manage models" stays next to it. The copy is conditional on purpose. `missing-auth` on a Claude CLI row also covers a disabled or denied anthropic plugin and a missing personal-account pin, so an already signed-in user can see it. The reason enum (`missing-auth` | `auth-failed` | `cooldown`) is closed and shared with the Swift and Kotlin clients, and no existing value fits a disabled plugin, so this PR keeps the protocol unchanged and words the hint to stay true in every `missing-auth` case. `claude auth login` is the command OpenClaw's own hints already use (`oauth-refresh-failure.ts`, `doctor-claude-cli.ts`, `extensions/anthropic/auth.runtime.ts`). `claude setup-token` makes an API token for the Anthropic provider; it does not log in the CLI runtime. - Channel `/models` (`commands-models-menu.ts`): for Claude CLI rows reporting `missing-auth`, the recovery line now uses the same wording as the picker hint ("If Claude Code is signed out, run claude auth login on the Gateway host, or choose another model.") instead of `/login anthropic`. Other routes are unchanged. - `docs/concepts/models.md`: documents that configured models stay listed as unavailable, and adds the Claude Code login line. No new config keys and no protocol changes: the existing `missing-auth` value is reused. ## Evidence Isolated Gateway on this Mac with state, config and `CLAUDE_CONFIG_DIR` under /tmp. The config is the one written by the real `openclaw onboard --non-interactive --auth-choice anthropic-cli`. The logged-out state is a fresh, empty `CLAUDE_CONFIG_DIR` (`claude auth status` → `loggedIn: false`). The logged-in run uses a wrapper that answers only `claude auth status` with `loggedIn: true`. No real Claude login was touched. Screenshots retaken on the final head (36b263f) and on origin/main (b7dc0bc), each from its own isolated Gateway: | | Logged out | Logged in | |---|---|---| | origin/main |  |  | | this branch |  |  | Picker contents (search "Claude"): - **origin/main, logged out:** "No models available"; one `anthropic/*` row (the default), no reason. - **This branch, logged out:** "Claude Code isn't ready. If signed out, run claude auth login."; all 10 pinned `anthropic/*` rows listed with "Sign-in needed". - **Logged in:** no empty-state label, and the same 23 picker rows in the same order on both heads. ### Telegram Test Server (`/models anthropic`) Ran the repository's Telegram userbot runner on the Telegram Test Server with a Convex-leased bot and QA user (`run-mock-sut-user-e2e.mjs --dm --scenario`). The runner starts a fresh Gateway from each checkout's build. The config patch adds two configured `anthropic/*` models pinned to `claude-cli` and enables the anthropic plugin. `CLAUDE_CONFIG_DIR` points at an empty directory, so Claude Code is logged out. The QA user sends `/models anthropic` at 1 s and again at 40 s, after startup discovery. `/models` is a native command, so no model turn runs; the only mock-provider rows are two `/` readiness probes. | | 1 s | 40 s | |---|---|---| | origin/main `b7dc0bc0fda3` | "anthropic: checking models…" | "Unknown provider: anthropic … Available providers: • openai". The configured Claude CLI models are gone. | | this branch `45dce1142171` | "Models (anthropic) — 0 of 2 available … anthropic: Sign-in needed. If Claude Code is signed out, run claude auth login on the Gateway host, or choose another model." Buttons: `…needed — Claude CLI · claude-opus-4-7`, `…eded — Claude CLI · claude-sonnet-4-6`, `<< Back`. | Same reply and buttons. | The `…` at the start of the button labels comes from Telegram's existing button-length truncation; this PR does not touch it. `models.list {view: "configured"}`, logged out, no refresh: - **origin/main:** 1 `anthropic/*` row (the default), `available: false`, no reason. - **This branch:** all 10 pinned `anthropic/*` rows, `available: false`, `unavailableReason: "missing-auth"`. - **Logged in:** the configured-view rows, runtimes and availability on this branch are identical to the origin/main capture of the same config. The duplicate `claude-cli/*` rows in the screenshots are the existing twins; openclaw#166311 removes them. ## Tests - `models-list-result.cli-runtime-availability.test.ts`, new case: an onboarding-shaped config, Claude logged out, catalog incomplete, configured view, run through the real `buildModelsListResult`. Every pinned row is listed with `missing-auth`, and the unpinned API row stays hidden. It fails on origin/main for both causes (rows missing, no reason). - `models.test.ts`: the existing table row for "logged out, catalog incomplete" now expects `missing-auth`, because the runtime is configured. It fails on origin/main. - `chat-model-catalog-state.test.ts`: the real `renderChatModelPicker`, given a `missing-auth` Claude CLI row, renders exactly the conditional Claude Code hint (the same row a signed-in user gets when the anthropic plugin is disabled, which `models-list-result.cli-runtime-availability.test.ts` already covers on the producer side). Other providers keep "No models available". It fails on origin/main (`expected 'No models available'`). - `commands-models.catalog-recovery.test.ts` and `commands-models.test.ts` go through the real `/models` handler, which reads the same projection as the picker. A CLI-bound configured model is now listed in every auth state. It is marked "Sign-in needed" unless its prepared native login is present and its plugin is enabled. Its recovery line reads "If Claude Code is signed out, run claude auth login on the Gateway host, or choose another model." instead of `/login anthropic`, which can't fix a Claude Code login or a disabled plugin. A logged-out configured Claude CLI default now gets that recovery line instead of "Connection not confirmed". The openclaw#139848 rule still holds: with only an API key, the bound row shows "Sign-in needed" and is not available. - Wall time with `pnpm test <file> --maxWorkers=1`: 35 s, 37 s and 3 s. The new gateway case takes 325 ms. No timers and no new fixtures. - Also run: affected suites (`model-catalog*`, `model-auth-availability*`, `model-selection*`, `server-methods/models*`, `commands/models`, the chat picker UI and new-session), all passing. `node scripts/check-changed.mjs` exits 0 (tsgo core and UI, lint, import cycles, line-cap ratchet, i18n). ## Bounded cost - No new processes, probes, network calls or catalog work. The existing startup `claude auth status` check and openclaw#166305's 60-second recheck are unchanged. - The configured-runtime set is built at most once per auth resolver, which is one per `models.list` read. It is built only when a CLI-runtime row has no prepared login, and it is a pure walk over the config's model refs. - Visibility adds one `Set.has` per catalog row. The UI adds one `.some()` over picker options per render. - Picker size is bounded by configured refs: at most the number of models the user authored, and they were already listed while signed in. ## User impact A logged-out Claude Code user sees every configured Claude model, greyed with "Sign-in needed", and a header that names the command to run. Once `claude auth login` succeeds, the rows turn available on the next read after openclaw#166305's recheck. Configured models for other providers that have lost their key now also stay listed as unavailable instead of disappearing. The channel `/models` command shows the same rows marked "Sign-in needed", and Claude CLI rows get the conditional `claude auth login` recovery line. The logged-in picker is unchanged. ## LOC vs origin/main Production +182/-118. The moved evaluator accounts for +147/-112 and is unchanged apart from the configured-runtime check, so the behaviour change itself is about +35. Tests +82/-12. Docs +3/-1. Co-authored-by: Ayaan Zaidi <[email protected]>
…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.
What Problem This Solves
Fixes: Claude CLI models stay hidden or disabled in the Control UI model picker and
openclaw models listwhen Claude Code was logged out at Gateway start and the user logs in afterwards; only a Gateway restart ormodels.list {refresh: true}fixed it. A logout after startup was never reflected either.User Impact
User impact: after
claude auth login(or a logout), the picker shows the right Claude CLI models within about a minute, without restarting the Gateway or reloading the page. How a logged-out Claude is displayed is unchanged.Why This Change Was Made
evaluateCliRuntimeModelAuthAvailabilityreads theclaude-cliauth mode from theclaude auth status --jsonprobe inextensions/anthropic/provider-discovery.ts.refreshExpiredModelCatalogonly renews providers with an inventoryexpiresAt, and the staticclaude-cliprovider never gets one. So the startup result stayed for the whole generation.The existing ordinary-read renewal hook now also rechecks CLI-backend native logins (CLI backends whose manifest declares
syntheticAuthRefs, which today meansclaude-cli). The recheck runs in the background, deduplicates through the worker's existingloadAuth, and publishes a new catalog through the existing native-publication path only when the login state changed. The explicitloadAuthrefresh and the recheck share one scoped-auth merge inprepared-model-runtime.catalog-auth.ts;loadAuthstill returns only{ authStore, authModes }. Startup still probes once per shared generation, so both earlier PRs' cost limits hold.Bounded cost
claude auth status --json(existing 3 s timeout, process-tree kill) per prepared catalog owner per 60 s, and only while model lists are being read. An idle Gateway spawns nothing.Evidence
Regression test.
src/gateway/server.chat-cli-auth.test.tsadds "publishes Claude login changes after Gateway startup". It runs the real in-process Gateway, the real Anthropic plugin andmodels.list; only theclaudeexecutable is a fixture, and it records eachauth statusprobe. It checks that the model is unavailable at startup, that a login inside the recheck window spawns no probe, that the model becomes available after the window with exactly one more probe, and that a logout makes it unavailable again with exactly one more probe. Each transition awaits the catalog publication rather than polling. With origin/main's catalog code the login publication never arrives and the test times out at 90 s; on this branch it passes in about 5 s. The full file (7 tests), the prepared-runtime suites that share its test harness, andnode scripts/check-changed.mjspass on this branch.Live Control UI, before and after. Two isolated Gateways on one Mac, origin/main and this branch. State, config,
HOMEandCLAUDE_CONFIG_DIRwere under /tmp, there was no Anthropic API key, and the config was shaped like our setup. Each used the realclaudebinary behind a wrapper that only countsauth statuscalls. Both started logged out. The login happened afterwards, by placing a Claude credentials file in each isolatedCLAUDE_CONFIG_DIR. The picker was reopened in place and the page was never reloaded.claude auth statusin the sameCLAUDE_CONFIG_DIRreportedloggedIn: true, but the picker still showed 2 Anthropic rows and all 11 Claude rows disabled. One probe in total, at startup.anthropic/*and 9claude-cli/*) were enabled on the first open after the window. After a logout they were disabled again on the next window. A re-login right after a recheck showed up after 60 s, with 14 picker opens and exactly 1 probe.LOC vs origin/main: production +104/-25, tests +51/-3, docs +3/-1.