Repository navigation
perf(models): keep inventory reads on published catalogs - #167008
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 8, 2026, 2:55 AM ET / 06:55 UTC. ClawSweeper reviewWhat this changesOrdinary model-list requests reuse published inventory while full catalog builds share one normalized snapshot between displayed and executable models. Example: The user opens the model picker after provider-cache expiry.
Review scores
ProductKind: Performance · Worth it: Yes · Fix scope: Complete Merge readiness✅ Ready for maintainer review This PR provides useful, owner-directed work absent from pinned main, with no actionable code or security findings. The supplied comparison supports avoided discovery work, without establishing a general latency improvement. Priority: P2 Before mergeNone. FindingsNone. Tests
Agent review detailsHow this fits togetherThe Gateway publishes a shared model inventory for model pickers and agent execution. Provider discovery and native-login observations supply facts that the catalog owner publishes to readers. flowchart TD
A[Model picker request] --> B{Explicit Refresh?}
B -->|No| C[Published catalog]
B -->|Yes| D[Catalog acquisition owner]
E[Configuration and credential updates] --> D
D --> F[One normalized model snapshot]
F --> C
C --> G[Displayed and executable models]
Technical reviewBest possible solution: Keep acquisition with the lifecycle owner and explicit Refresh, preserve SDK renewal and native-login checks, and publish one consistent normalized inventory. Do we have a high-confidence way to reproduce the issue? Yes: pinned-main ordinary models.list calls the expiry-renewing owner, and registry getAll normalizes on each call. The supplied negative controls report the intended failures; this read-only review did not execute them. Is this the best way to solve the issue? Yes: the patch reuses existing publication and refresh owners, preserves the SDK contract, and removes duplicate normalization without introducing another cache or setting. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against 2f1f73ccb222. Provenance checked
TestingProof path: in-process harness. Added test files: 9. SecurityNone. EvidenceWhat I checked:
Likely related people:
PR surfaceSource +1, Tests +13, Docs +2. Total +16 across 16 files. View PR surface stats
LabelsLabel changes:
Label justifications:
Rating scale6/6 🦀 challenger crab · 5/6 🦞 diamond lobster · 4/6 🐚 platinum hermit · 3/6 🦐 gold shrimp · 2/6 🦪 silver shellfish · 1/6 🧂 unranked krab. Overall follows the weaker of proof and patch quality; ✨ marks media proof (a screenshot, video, or linked artifact) that directly shows the changed behavior. WorkflowClawSweeper edits this one comment on every review. Comment |
Reuse lifecycle-published inventory for ordinary models.list requests instead of rebuilding after provider response-cache expiry. Keep native login checks independent, and preserve explicit refresh and the shipped SDK renewal contract. Carry one normalized registry snapshot into both displayed and executable catalog rows, removing the duplicate normalization and nested generation scope.
dba8e9a to
df53572
Compare
) After #167008, the native-login check and the later prepared inventory read both use the published owner getter. These were already separate owner lookups before that change, across the request preparation boundary. Expect both reads and assert one native-login recheck while preserving the successful response and the guarantee that no catalog load starts.
…anual refresh (#167230) ## What Problem This Solves Fixes: when a provider's model discovery fails once (for example an OpenRouter timeout), the Gateway falls back to that provider's few built-in rows (OpenRouter 466 → 3) and keeps them until someone runs an explicit `models refresh`. ## User Impact A transient provider outage no longer hides most of that provider's models for the life of the Gateway. The failed provider retries discovery in the background and its full model list comes back on its own once the provider is reachable. ## Why This Change Was Made Failed discovery recorded no renewal deadline, and ordinary `models.list` reads intentionally no longer renew inventory (#167008), so nothing ever retried it. A failed provider now gets a backed-off retry deadline (30 s, doubling to a 30 min cap) on its retained inventory facts. The catalog owner keeps one timer for the earliest deadline, re-armed after each acquisition settles and cancelled when the catalog generation retires. Reads stay passive; a successful retry publishes the full rows and returns the provider to its normal cache deadline. A compatible reload keeps the failure facts and resumes the retry. ## Evidence - Regression tests in `prepared-model-runtime.catalog-owner.test.ts`: discovery fails, then recovers with backoff and no read or refresh (fails on `main`: the worker is never called again); and a new failure episode is measured from its own failure. - Live isolated Gateway with real OpenRouter discovery and a DNS-delay preload: OpenRouter discovery failed at startup and showed 3 built-in rows with `refreshFailed`. Background retries ran at the expected backoff (lookups at 12:17:38, 12:18:13, 12:19:19, 12:21:24, 12:25:29 UTC). After the network recovered at 12:29:40, passive `models.list` polling (no refresh) showed OpenRouter go from 3 to 466 rows at 12:33:35, on the next scheduled retry. OpenRouter's outcome is now `ready`. - Focused prepared-catalog and models-list suites pass. Two `models-auth-*.catalog.integration` tests also fail on an unmodified `main` checkout locally. - Test cost: `pnpm exec vitest run src/agents/prepared-model-runtime.catalog-owner.test.ts` takes 8.2 s wall time locally (19 tests; Vitest duration 4.2 s). The two new cases use fake timers and add about 0.4 s of CI test time. Co-authored-by: Ayaan Zaidi <[email protected]>
…discovers (#167458) ## What Problem This Solves Fixes: after a Gateway restart, `models.list` stays without some models until someone runs an explicit refresh. These are hosted-catalog models for providers that have no credentials (for example Kimi, x-ai and some Anthropic models) and native CLI models such as Claude CLI. On two production Gateways a restart left 18 and 14 models missing. They came back only after a manual `models list --all --refresh`. ## User Impact After a restart, the model list and pickers show the same models an explicit refresh would, with no manual refresh. ## Why This Change Was Made At startup the Gateway only discovers models for providers that have credentials. It then treats that partial result as the complete catalog. The full discovery that finds hosted rows for providers without credentials runs only on an explicit refresh or when a new hosted catalog arrives. Ordinary reads no longer trigger discovery since #167008, so nothing ran it after a restart. When an agent has no saved provider inventory, its startup pass now runs the full discovery an explicit refresh would run. That is always the case after a restart. A later configuration or credential reload that keeps its inventory still rediscovers only the providers that changed. Startup discovery still runs in the background after the Gateway publishes its catalog, so readiness does not wait for it. Known cost: on a cold start the Gateway now calls the discovery endpoints of configured providers that have no credentials, the same calls an explicit refresh makes. Each agent's startup discovery is now a full one, run one at a time through the existing catalog-build limit. Discovery responses are shared, so a second agent did not repeat any network call in the measurement below. Existing discovery timeouts bound each call. An explicit refresh issued while startup discovery is still running now joins it instead of starting a second run. ## Evidence - Regression test in `prepared-model-runtime.scoped-refresh.test.ts`. At cold start the worker is asked for the full catalog, and a row that only full discovery finds is published. After a credential reload that keeps inventory, discovery is scoped to the changed provider and the row stays. On `main` the test fails because startup discovery is scoped (`["demo"]`) and the row is missing. - Isolated Gateway (real OpenAI and OpenRouter discovery, hosted catalog bundle already stored, restarted with no refresh), polling `models.list` for 45–90 s after readiness: - `main`: 501 rows (openai 33, openrouter 468). No Claude CLI or Kimi rows in any of 7 restarts. - This change: 516 rows (adds claude-cli 11 and kimi 4) a few seconds after readiness, in all 7 restarts. Before this change the same 516 appeared only after an explicit `models.list {refresh: true}`. - Readiness is not delayed. Time from process start to `/readyz` 200, with `main` and this change alternating on the same machine: `main` 14.8 / 14.5 / 10.9 / 12.3 s, this change 12.3 / 10.7 / 12.0 / 16.1 s. Three earlier sequential runs: `main` 12.0 / 11.0 / 19.4 s, this change 9.4 / 19.7 / 15.1 s. Mean over 7 runs: 13.6 s for both. - Two agents, outbound discovery calls counted per host in all threads during the first 60 s: `main` and this change both made one request each to `openrouter.ai/api/v1/models` and `api.openai.com/v1/models`. Both agents listed the full 516 rows with this change. - Updated tests that assumed startup did no provider discovery: - catalog-publication, remote-publication and the worker-pool deadline test now let startup discovery finish first. - The chat-metadata fixture's worker returns the same catalog as its static builder. - The native-lifecycle Gateway test now expects the startup request to the provider endpoint without credentials. - Focused prepared-catalog, chat-metadata and models-list suites pass. Five worker and auth catalog integration tests (`scope`, `metadata`, worker OAuth rotation, `models-auth-login`, `models-auth-refresh`) fail locally on the same unmodified `main` commit, and they also fail with this change. - Test cost: `pnpm test src/agents/prepared-model-runtime.scoped-refresh.test.ts --maxWorkers=1` took 51 s wall time locally (20 tests; Vitest duration 23 s). The new case takes about 0.2 s. No overlap with Pash/Sarah changes. Merge danger: two-way door. No stored state, config or contract changes; a revert restores scoped startup discovery. Blast radius: Gateway startup catalog discovery for every install. If it is wrong, the risk is extra startup discovery calls in the background, not missing models. Co-authored-by: Ayaan Zaidi <[email protected]>
…167463) ## What Problem This Solves Fixes: a model pulled with `ollama pull` after OpenClaw's Ollama setup never shows up in the model pickers, even after **Refresh**, until the user edits config. ## User Impact User impact: after setting up a local or self-hosted Ollama server, newly pulled chat models appear in the Control UI picker and `openclaw models list --provider ollama` on the next model-list refresh, with no config edit or Gateway restart. Setup-saved models keep their settings. Embedding-only models stay out. Behavior change to note: a nonempty `models.providers.ollama.models` list on a self-hosted endpoint no longer acts as a picker allowlist. Users who want only their listed models use `models.mode: "replace"`, `plugins.entries.ollama.config.discovery.enabled: false`, or the existing model allowlist. Hosted `https://ollama.com` still uses only the configured rows. ## Why This Change Was Made Setup saves every model it finds into `models.providers.ollama.models`, and Ollama discovery returned only those saved rows whenever that list was nonempty, without listing `/api/tags`. That pinned the inventory to setup time. Discovery now lists `/api/tags` for self-hosted endpoints even when models are configured; listed models the config already has are dropped from the discovered set, so configured rows keep all their settings (for example the documented `compat.supportsTools: false` workaround, even when `/api/show` advertises `tools`), and the existing config merge adds the other installed chat models. Discovery opt-out, hosted Ollama Cloud, endpoint/credential rules and failure handling are unchanged: if `/api/tags` fails, the configured rows stay. The stale WIP also added a 30 s fallback expiry in core inventory capture. It is not part of this PR: since #167008, ordinary `models.list` reads no longer renew expired provider inventory, so a deadline would not make a plain picker open re-list. Explicit **Refresh** (Models page, `models list --refresh`), startup and config/credential changes own discovery, and that path now picks up new pulls. ## Evidence Real run on a disposable `ollama/ollama` Docker container (no host mounts, removed afterwards) with isolated profiles, running real `openclaw onboard --non-interactive --auth-choice ollama --custom-base-url http://127.0.0.1:11471 --custom-model-id qwen2.5:0.5b`. Setup saved `models.providers.ollama.models = ["qwen2.5:0.5b"]` (`mode: "merge"`). The config file hash was identical before and after every step below, and the Gateway was not restarted between pull and listing. | Step | `origin/main` (6070074) | This branch | | --- | --- | --- | | `models list --provider ollama` after setup | `qwen2.5:0.5b` | `qwen2.5:0.5b` | | `ollama pull qwen3:0.6b`, then `models list --provider ollama --refresh` | `qwen2.5:0.5b` only (also 45 s later) | `qwen2.5:0.5b`, `qwen3:0.6b` | | Control UI chat picker | Ollama (1) | — | | `ollama pull smollm2:135m` + `all-minilm` (embedding), Settings → Models → **Refresh**, reopen chat picker | — | Ollama (3): `qwen2.5:0.5b`, `qwen3:0.6b`, `smollm2:135m`; `all-minilm` absent | | `infer model run --gateway --model ollama/qwen3:0.6b --prompt "Reply with exactly: PULLED_OK"` | — | `ok: true`, provider `ollama`, model `qwen3:0.6b`, output `PULLED_OK` (7 s) | The host was heavily loaded (load average ~70 on 32 cores). Ollama's default 32 llama.cpp threads stalled while loading the model, so before the chat turn the pulled model's Ollama-side default was set to `num_thread 6` (`ollama create qwen3:0.6b` with `FROM qwen3:0.6b`). OpenClaw config was not touched. An earlier full-agent Control UI turn to the same model was stopped after its 8.8k-token prompt ran at about 8 tokens/s under that load. Without **Refresh**, a plain `models list` / picker open keeps showing the published catalog on both builds; that is the existing #167008 read policy, not changed here. Tests: - New `src/agents/models-config.ollama-secretref.test.ts` case runs the registered Ollama plugin through the real models-config planner. Configured `qwen2.5:0.5b` (`compat.supportsTools: false`) plus `/api/tags` listing `qwen3:0.6b` and `nomic-embed-text`, with `/api/show` advertising `tools`, results in `[qwen2.5:0.5b (supportsTools: false), qwen3:0.6b (supportsTools: true)]`. A later `/api/tags` 503 keeps `[qwen2.5:0.5b (supportsTools: false)]`. Before 392ff91 the compat assertion failed with the setup row's compat replaced by the discovered `{ supportsTools: true, supportsUsageInStreaming: true, supportsJsonSchemaResponseFormat: true }`. Against main's `discovery-shared.ts` it fails with `expected [ 'qwen2.5:0.5b' ] to deeply equal [ 'qwen2.5:0.5b', 'qwen3:0.6b' ]`. - Existing tests that asserted "no discovery with configured models" now assert the discovery request's credentials instead. Local synthetic auth sends no `Authorization`; ambient `OLLAMA_API_KEY` stays away from local hosts; a configured remote key or SecretRef is sent. - `extensions/ollama/src/discovery-shared.test.ts`, `extensions/ollama/provider-discovery.test.ts`, `extensions/ollama/index.test.ts`: 135 passed. `models-config.ollama-secretref.test.ts`: 7 passed. After 392ff91: `node scripts/run-vitest.mjs run` on `models-config.ollama-secretref`, `provider-discovery`, `discovery-shared`, `models-config.merge`, `model-compat-catalog` tests: 3 shards passed. `oxlint --type-aware` on changed files: clean. - `node scripts/check-changed.mjs`: every step passed except the dead export scan, which flags `src/talk/client-voice-session-store.ts: ClientVoiceToolEffect`. This PR does not touch that file; the export comes from main (#166795). Rerun at 392ff91: same single unrelated failure; every other step (including core/extension typechecks) passed. ### Configured model settings survive discovery (392ff91) Real run, isolated profile, disposable `ollama/ollama` container on `127.0.0.1:21434` (removed afterwards), Gateway on loopback. Config: `models.providers.ollama.models = [{ id: "qwen2.5:0.5b", compat: { supportsTools: false } }]`; `/api/show` for `qwen2.5:0.5b` returns `capabilities: ["completion", "tools"]`. | Step | Effective rows (`gateway call models.list`, provider `ollama`) | | --- | --- | | After Gateway start | `qwen2.5:0.5b` `supportsTools: false` | | `ollama pull qwen3:0.6b`, then `models list --provider ollama --refresh` | `qwen2.5:0.5b` `supportsTools: false`; `qwen3:0.6b` `supportsTools: true` (ctx 40960) | | `openclaw agent --agent main -m "Reply with exactly the word: pong"` on `ollama/qwen2.5:0.5b` | `status: ok`, reply `pong`; run report tools `entries: []`, `schemaChars: 0` (no tool schemas sent) | The container ran with `OLLAMA_CONTEXT_LENGTH=16384`; at Ollama's default 4096 the 6k-token system prompt overflowed (an Ollama server setting, unrelated to this change). ### Startup with an unreachable or slow configured endpoint #28827 skipped discovery for configured models to avoid startup delays. Measured Gateway start (spawn of `pnpm openclaw --profile … gateway run` to `/readyz` 200) with the same configured model, `origin/main` (6070074) vs this branch (392ff91), alternating, 3 runs each. Endpoints: unreachable = closed loopback port; hang = loopback server that accepts and never answers; slow = every response after 2 s. Host load average was 28–46 on 32 cores, so absolute numbers are noisy. | Endpoint | main `/readyz` ms (r1, r2, r3) | branch `/readyz` ms (r1, r2, r3) | | --- | --- | --- | | unreachable | 8988, 18618, 58035 | 9401, 21341, 32035 | | hang | 9507, 32831, 25592 | 8351, 9313, 27288 | | slow (2 s) | 18887, 10279, 11986 | 9144, 20723, 15589 | No systematic difference. On the branch, every `/api/tags` request reached the hang and slow servers 2.0–3.5 s **after** the Gateway logged `ready` (none before it), so discovery is not on the startup path. `models list --provider ollama --json` right after ready returned the configured row in 2.8–10.6 s on both builds (main 2.8–7.9 s, branch 2.9–10.6 s); in hang runs 1 and 3 it returned before the hanging `/api/tags` request hit its 5 s timeout. Main also sends one post-ready `/api/show` for the configured model. No overlap with Pash/Sarah changes Merge danger: two-way door (one conditional in the Ollama plugin plus docs; no schema, stored-data, config-option or protocol change). Blast radius: users with a self-hosted Ollama endpoint and a nonempty configured model list. Their picker gains the other installed chat models, and startup and refresh now send `/api/tags` and `/api/show` requests to that server. If the server is offline, Ollama now reports an unavailable refresh, keeps the configured rows, and retries with backoff. Hosted Ollama Cloud, discovery opt-out and replace mode are unaffected. ### Screenshots Before (`origin/main`), chat picker after `ollama pull qwen3:0.6b` and `--refresh`: Ollama (1).  After (this branch), chat picker after Settings → Models → **Refresh**: Ollama (3), embedding model absent.  Co-authored-by: Ayaan Zaidi <[email protected]>
…7008) * perf(models): keep inventory reads on published catalogs Reuse lifecycle-published inventory for ordinary models.list requests instead of rebuilding after provider response-cache expiry. Keep native login checks independent, and preserve explicit refresh and the shipped SDK renewal contract. Carry one normalized registry snapshot into both displayed and executable catalog rows, removing the duplicate normalization and nested generation scope. * test(models): trigger worker recovery through the renewal owner
…claw#167165) After openclaw#167008, the native-login check and the later prepared inventory read both use the published owner getter. These were already separate owner lookups before that change, across the request preparation boundary. Expect both reads and assert one native-login recheck while preserving the successful response and the guarantee that no catalog load starts.
…anual refresh (openclaw#167230) ## What Problem This Solves Fixes: when a provider's model discovery fails once (for example an OpenRouter timeout), the Gateway falls back to that provider's few built-in rows (OpenRouter 466 → 3) and keeps them until someone runs an explicit `models refresh`. ## User Impact A transient provider outage no longer hides most of that provider's models for the life of the Gateway. The failed provider retries discovery in the background and its full model list comes back on its own once the provider is reachable. ## Why This Change Was Made Failed discovery recorded no renewal deadline, and ordinary `models.list` reads intentionally no longer renew inventory (openclaw#167008), so nothing ever retried it. A failed provider now gets a backed-off retry deadline (30 s, doubling to a 30 min cap) on its retained inventory facts. The catalog owner keeps one timer for the earliest deadline, re-armed after each acquisition settles and cancelled when the catalog generation retires. Reads stay passive; a successful retry publishes the full rows and returns the provider to its normal cache deadline. A compatible reload keeps the failure facts and resumes the retry. ## Evidence - Regression tests in `prepared-model-runtime.catalog-owner.test.ts`: discovery fails, then recovers with backoff and no read or refresh (fails on `main`: the worker is never called again); and a new failure episode is measured from its own failure. - Live isolated Gateway with real OpenRouter discovery and a DNS-delay preload: OpenRouter discovery failed at startup and showed 3 built-in rows with `refreshFailed`. Background retries ran at the expected backoff (lookups at 12:17:38, 12:18:13, 12:19:19, 12:21:24, 12:25:29 UTC). After the network recovered at 12:29:40, passive `models.list` polling (no refresh) showed OpenRouter go from 3 to 466 rows at 12:33:35, on the next scheduled retry. OpenRouter's outcome is now `ready`. - Focused prepared-catalog and models-list suites pass. Two `models-auth-*.catalog.integration` tests also fail on an unmodified `main` checkout locally. - Test cost: `pnpm exec vitest run src/agents/prepared-model-runtime.catalog-owner.test.ts` takes 8.2 s wall time locally (19 tests; Vitest duration 4.2 s). The two new cases use fake timers and add about 0.4 s of CI test time. Co-authored-by: Ayaan Zaidi <[email protected]>
…discovers (openclaw#167458) ## What Problem This Solves Fixes: after a Gateway restart, `models.list` stays without some models until someone runs an explicit refresh. These are hosted-catalog models for providers that have no credentials (for example Kimi, x-ai and some Anthropic models) and native CLI models such as Claude CLI. On two production Gateways a restart left 18 and 14 models missing. They came back only after a manual `models list --all --refresh`. ## User Impact After a restart, the model list and pickers show the same models an explicit refresh would, with no manual refresh. ## Why This Change Was Made At startup the Gateway only discovers models for providers that have credentials. It then treats that partial result as the complete catalog. The full discovery that finds hosted rows for providers without credentials runs only on an explicit refresh or when a new hosted catalog arrives. Ordinary reads no longer trigger discovery since openclaw#167008, so nothing ran it after a restart. When an agent has no saved provider inventory, its startup pass now runs the full discovery an explicit refresh would run. That is always the case after a restart. A later configuration or credential reload that keeps its inventory still rediscovers only the providers that changed. Startup discovery still runs in the background after the Gateway publishes its catalog, so readiness does not wait for it. Known cost: on a cold start the Gateway now calls the discovery endpoints of configured providers that have no credentials, the same calls an explicit refresh makes. Each agent's startup discovery is now a full one, run one at a time through the existing catalog-build limit. Discovery responses are shared, so a second agent did not repeat any network call in the measurement below. Existing discovery timeouts bound each call. An explicit refresh issued while startup discovery is still running now joins it instead of starting a second run. ## Evidence - Regression test in `prepared-model-runtime.scoped-refresh.test.ts`. At cold start the worker is asked for the full catalog, and a row that only full discovery finds is published. After a credential reload that keeps inventory, discovery is scoped to the changed provider and the row stays. On `main` the test fails because startup discovery is scoped (`["demo"]`) and the row is missing. - Isolated Gateway (real OpenAI and OpenRouter discovery, hosted catalog bundle already stored, restarted with no refresh), polling `models.list` for 45–90 s after readiness: - `main`: 501 rows (openai 33, openrouter 468). No Claude CLI or Kimi rows in any of 7 restarts. - This change: 516 rows (adds claude-cli 11 and kimi 4) a few seconds after readiness, in all 7 restarts. Before this change the same 516 appeared only after an explicit `models.list {refresh: true}`. - Readiness is not delayed. Time from process start to `/readyz` 200, with `main` and this change alternating on the same machine: `main` 14.8 / 14.5 / 10.9 / 12.3 s, this change 12.3 / 10.7 / 12.0 / 16.1 s. Three earlier sequential runs: `main` 12.0 / 11.0 / 19.4 s, this change 9.4 / 19.7 / 15.1 s. Mean over 7 runs: 13.6 s for both. - Two agents, outbound discovery calls counted per host in all threads during the first 60 s: `main` and this change both made one request each to `openrouter.ai/api/v1/models` and `api.openai.com/v1/models`. Both agents listed the full 516 rows with this change. - Updated tests that assumed startup did no provider discovery: - catalog-publication, remote-publication and the worker-pool deadline test now let startup discovery finish first. - The chat-metadata fixture's worker returns the same catalog as its static builder. - The native-lifecycle Gateway test now expects the startup request to the provider endpoint without credentials. - Focused prepared-catalog, chat-metadata and models-list suites pass. Five worker and auth catalog integration tests (`scope`, `metadata`, worker OAuth rotation, `models-auth-login`, `models-auth-refresh`) fail locally on the same unmodified `main` commit, and they also fail with this change. - Test cost: `pnpm test src/agents/prepared-model-runtime.scoped-refresh.test.ts --maxWorkers=1` took 51 s wall time locally (20 tests; Vitest duration 23 s). The new case takes about 0.2 s. No overlap with Pash/Sarah changes. Merge danger: two-way door. No stored state, config or contract changes; a revert restores scoped startup discovery. Blast radius: Gateway startup catalog discovery for every install. If it is wrong, the risk is extra startup discovery calls in the background, not missing models. Co-authored-by: Ayaan Zaidi <[email protected]>
…penclaw#167463) ## What Problem This Solves Fixes: a model pulled with `ollama pull` after OpenClaw's Ollama setup never shows up in the model pickers, even after **Refresh**, until the user edits config. ## User Impact User impact: after setting up a local or self-hosted Ollama server, newly pulled chat models appear in the Control UI picker and `openclaw models list --provider ollama` on the next model-list refresh, with no config edit or Gateway restart. Setup-saved models keep their settings. Embedding-only models stay out. Behavior change to note: a nonempty `models.providers.ollama.models` list on a self-hosted endpoint no longer acts as a picker allowlist. Users who want only their listed models use `models.mode: "replace"`, `plugins.entries.ollama.config.discovery.enabled: false`, or the existing model allowlist. Hosted `https://ollama.com` still uses only the configured rows. ## Why This Change Was Made Setup saves every model it finds into `models.providers.ollama.models`, and Ollama discovery returned only those saved rows whenever that list was nonempty, without listing `/api/tags`. That pinned the inventory to setup time. Discovery now lists `/api/tags` for self-hosted endpoints even when models are configured; listed models the config already has are dropped from the discovered set, so configured rows keep all their settings (for example the documented `compat.supportsTools: false` workaround, even when `/api/show` advertises `tools`), and the existing config merge adds the other installed chat models. Discovery opt-out, hosted Ollama Cloud, endpoint/credential rules and failure handling are unchanged: if `/api/tags` fails, the configured rows stay. The stale WIP also added a 30 s fallback expiry in core inventory capture. It is not part of this PR: since openclaw#167008, ordinary `models.list` reads no longer renew expired provider inventory, so a deadline would not make a plain picker open re-list. Explicit **Refresh** (Models page, `models list --refresh`), startup and config/credential changes own discovery, and that path now picks up new pulls. ## Evidence Real run on a disposable `ollama/ollama` Docker container (no host mounts, removed afterwards) with isolated profiles, running real `openclaw onboard --non-interactive --auth-choice ollama --custom-base-url http://127.0.0.1:11471 --custom-model-id qwen2.5:0.5b`. Setup saved `models.providers.ollama.models = ["qwen2.5:0.5b"]` (`mode: "merge"`). The config file hash was identical before and after every step below, and the Gateway was not restarted between pull and listing. | Step | `origin/main` (618f4d2) | This branch | | --- | --- | --- | | `models list --provider ollama` after setup | `qwen2.5:0.5b` | `qwen2.5:0.5b` | | `ollama pull qwen3:0.6b`, then `models list --provider ollama --refresh` | `qwen2.5:0.5b` only (also 45 s later) | `qwen2.5:0.5b`, `qwen3:0.6b` | | Control UI chat picker | Ollama (1) | — | | `ollama pull smollm2:135m` + `all-minilm` (embedding), Settings → Models → **Refresh**, reopen chat picker | — | Ollama (3): `qwen2.5:0.5b`, `qwen3:0.6b`, `smollm2:135m`; `all-minilm` absent | | `infer model run --gateway --model ollama/qwen3:0.6b --prompt "Reply with exactly: PULLED_OK"` | — | `ok: true`, provider `ollama`, model `qwen3:0.6b`, output `PULLED_OK` (7 s) | The host was heavily loaded (load average ~70 on 32 cores). Ollama's default 32 llama.cpp threads stalled while loading the model, so before the chat turn the pulled model's Ollama-side default was set to `num_thread 6` (`ollama create qwen3:0.6b` with `FROM qwen3:0.6b`). OpenClaw config was not touched. An earlier full-agent Control UI turn to the same model was stopped after its 8.8k-token prompt ran at about 8 tokens/s under that load. Without **Refresh**, a plain `models list` / picker open keeps showing the published catalog on both builds; that is the existing openclaw#167008 read policy, not changed here. Tests: - New `src/agents/models-config.ollama-secretref.test.ts` case runs the registered Ollama plugin through the real models-config planner. Configured `qwen2.5:0.5b` (`compat.supportsTools: false`) plus `/api/tags` listing `qwen3:0.6b` and `nomic-embed-text`, with `/api/show` advertising `tools`, results in `[qwen2.5:0.5b (supportsTools: false), qwen3:0.6b (supportsTools: true)]`. A later `/api/tags` 503 keeps `[qwen2.5:0.5b (supportsTools: false)]`. Before 392ff91 the compat assertion failed with the setup row's compat replaced by the discovered `{ supportsTools: true, supportsUsageInStreaming: true, supportsJsonSchemaResponseFormat: true }`. Against main's `discovery-shared.ts` it fails with `expected [ 'qwen2.5:0.5b' ] to deeply equal [ 'qwen2.5:0.5b', 'qwen3:0.6b' ]`. - Existing tests that asserted "no discovery with configured models" now assert the discovery request's credentials instead. Local synthetic auth sends no `Authorization`; ambient `OLLAMA_API_KEY` stays away from local hosts; a configured remote key or SecretRef is sent. - `extensions/ollama/src/discovery-shared.test.ts`, `extensions/ollama/provider-discovery.test.ts`, `extensions/ollama/index.test.ts`: 135 passed. `models-config.ollama-secretref.test.ts`: 7 passed. After 392ff91: `node scripts/run-vitest.mjs run` on `models-config.ollama-secretref`, `provider-discovery`, `discovery-shared`, `models-config.merge`, `model-compat-catalog` tests: 3 shards passed. `oxlint --type-aware` on changed files: clean. - `node scripts/check-changed.mjs`: every step passed except the dead export scan, which flags `src/talk/client-voice-session-store.ts: ClientVoiceToolEffect`. This PR does not touch that file; the export comes from main (openclaw#166795). Rerun at 392ff91: same single unrelated failure; every other step (including core/extension typechecks) passed. ### Configured model settings survive discovery (392ff91) Real run, isolated profile, disposable `ollama/ollama` container on `127.0.0.1:21434` (removed afterwards), Gateway on loopback. Config: `models.providers.ollama.models = [{ id: "qwen2.5:0.5b", compat: { supportsTools: false } }]`; `/api/show` for `qwen2.5:0.5b` returns `capabilities: ["completion", "tools"]`. | Step | Effective rows (`gateway call models.list`, provider `ollama`) | | --- | --- | | After Gateway start | `qwen2.5:0.5b` `supportsTools: false` | | `ollama pull qwen3:0.6b`, then `models list --provider ollama --refresh` | `qwen2.5:0.5b` `supportsTools: false`; `qwen3:0.6b` `supportsTools: true` (ctx 40960) | | `openclaw agent --agent main -m "Reply with exactly the word: pong"` on `ollama/qwen2.5:0.5b` | `status: ok`, reply `pong`; run report tools `entries: []`, `schemaChars: 0` (no tool schemas sent) | The container ran with `OLLAMA_CONTEXT_LENGTH=16384`; at Ollama's default 4096 the 6k-token system prompt overflowed (an Ollama server setting, unrelated to this change). ### Startup with an unreachable or slow configured endpoint openclaw#28827 skipped discovery for configured models to avoid startup delays. Measured Gateway start (spawn of `pnpm openclaw --profile … gateway run` to `/readyz` 200) with the same configured model, `origin/main` (618f4d2) vs this branch (392ff91), alternating, 3 runs each. Endpoints: unreachable = closed loopback port; hang = loopback server that accepts and never answers; slow = every response after 2 s. Host load average was 28–46 on 32 cores, so absolute numbers are noisy. | Endpoint | main `/readyz` ms (r1, r2, r3) | branch `/readyz` ms (r1, r2, r3) | | --- | --- | --- | | unreachable | 8988, 18618, 58035 | 9401, 21341, 32035 | | hang | 9507, 32831, 25592 | 8351, 9313, 27288 | | slow (2 s) | 18887, 10279, 11986 | 9144, 20723, 15589 | No systematic difference. On the branch, every `/api/tags` request reached the hang and slow servers 2.0–3.5 s **after** the Gateway logged `ready` (none before it), so discovery is not on the startup path. `models list --provider ollama --json` right after ready returned the configured row in 2.8–10.6 s on both builds (main 2.8–7.9 s, branch 2.9–10.6 s); in hang runs 1 and 3 it returned before the hanging `/api/tags` request hit its 5 s timeout. Main also sends one post-ready `/api/show` for the configured model. No overlap with Pash/Sarah changes Merge danger: two-way door (one conditional in the Ollama plugin plus docs; no schema, stored-data, config-option or protocol change). Blast radius: users with a self-hosted Ollama endpoint and a nonempty configured model list. Their picker gains the other installed chat models, and startup and refresh now send `/api/tags` and `/api/show` requests to that server. If the server is offline, Ollama now reports an unavailable refresh, keeps the configured rows, and retries with backoff. Hosted Ollama Cloud, discovery opt-out and replace mode are unaffected. ### Screenshots Before (`origin/main`), chat picker after `ollama pull qwen3:0.6b` and `--refresh`: Ollama (1).  After (this branch), chat picker after Settings → Models → **Refresh**: Ollama (3), embedding model absent.  Co-authored-by: Ayaan Zaidi <[email protected]>
…ker reads A saved live model listing never aged after #167008, so a newly launched provider model stayed out of the picker until a restart, config change, hosted catalog revision or explicit Refresh. - A successful live listing expires at the later of its response-cache deadline and 15 minutes after acquisition. The floor keeps short TTLs from renewing on almost every read (#167008); a longer TTL still wins (#168050), so the relist always reaches the provider. - models.list asks the catalog owner to relist expired providers in the background; the read still returns published rows at once. - Expiry and failure-retry relists no longer mark providers pending, so pickers and chat /models show no loading state for them.
…ker reads (#200988) ## What Problem This Solves A model that a provider launches does not appear in the Gateway model picker until the Gateway restarts, its config or credentials change, the next 6-hourly hosted catalog revision is adopted, or the user presses **Refresh**. Example: OpenAI launched `gpt-6.2-astra` and `gpt-6.2-sol` on 2026-11-17. Typed `openai/gpt-6.2-sol` turns worked on every release, but the picker kept the OpenAI listing saved before the launch. Cause: #167008 stopped ordinary `models.list` reads from renewing an expired provider listing, because that expiry was the provider's 60-second HTTP response-cache TTL and almost every picker open rebuilt the catalog. Nothing replaced it, so a saved live listing never ages on its own. ## Why This Change Was Made - A successful live listing now expires at the later of its response-cache deadline and 15 minutes after acquisition (`discoveryDeadline`). The floor keeps short TTLs from renewing on almost every read (#167008). A longer TTL still wins (#168050, ClawRouter's one hour), so the expiry relist, which honors each feed's cache, always reaches the provider instead of re-stamping a cached response as fresh. - `models.list` calls the catalog owner's existing `refreshExpiredModelCatalog`, which relists only expired providers in the background. The read returns the published rows at once; open pickers update through the existing catalog publication push. - Expiry and failed-discovery retry relists no longer mark providers pending. They revalidate rows the user already sees, so pickers show no loading state and chat `/models` adds no `checking models…` line for them. First sign-in, changed credentials and explicit **Refresh** still report progress. - The listing still decides which models a signed-in provider shows (#114356). This change only keeps that listing fresh. Accepted cost: at most one background relist per live-listed provider per 15 minutes (or per its cache TTL, when longer), and only while someone opens a picker. Providers whose listing is not retained in the live response cache (`ttlMs: 0`, self-hosted discovery) keep the previous behavior. ## User Impact A newly launched provider model appears in the picker within about 15 minutes of the provider listing it, on the first picker open, with no restart, no **Refresh**, no loading indicator and no OpenClaw release. ## Evidence - **Regression (vitest-source):** `models-list.freshness.integration.test.ts` keeps the real live response cache (500 ms TTL, no cache clearing). It asserts that the listing ages out on the 15-minute floor rather than the short TTL, and that an ordinary `models.list` read on an aged listing serves saved rows with no `pendingProviders`, relists once in the background, then publishes the new model. Fails on merge base `e235b2b983b6` (3/3, deadline equals the cache TTL); the no-pending assertion also fails on this PR's previous head `41ee4d30` (3/3, provider listed as pending); passes on this head (3/3). - **Renewal contract (vitest-source):** `server-chat-metadata-lifecycle.catalog-renewal.test.ts` now asserts that an expiry renewal never publishes a pending provider and that settling it sends only the real catalog change, with no refresh-status broadcast. An explicit refresh in the same file still reports refresh status. - **E2E, CLI reads (fix: source tier; base: `e235b2b983b6` dist-nodts):** two isolated Gateways, each with a fake LiteLLM proxy as its live listing and hosted catalog refresh disabled. At 04:03:46Z each proxy starts listing `fake-2`; an ordinary `gateway call models.list` (no refresh) runs once a minute. | Time (UTC) | Fix Gateway picker | Base Gateway picker | |---|---|---| | 04:03:41 (before) | `fake-1` | `fake-1` | | 04:04 to 04:17 | `fake-1` | `fake-1` | | 04:18:58 | `fake-1`, `fake-2` | `fake-1` | | 04:23:58 | `fake-1`, `fake-2` | `fake-1` | Proxy request logs: the fix Gateway listed at startup and once more at 04:17:58, the first read after the listing aged; no other requests. The base Gateway never listed again. - **E2E, Control UI (dist-nodts, real browser):** this head and the previous head `41ee4d30`, each with a fake LiteLLM listing whose `/models` response is held for 25 s after a new model is added. The picker is opened once the listing aged (proxy logs show the relist request at that moment), then again after release. During the relist both pickers render the saved models immediately with no loading state; the new model appears after the relist publishes. The visible difference from the previous head is the pending flag (`pendingProviders`, and chat `/models` `checking models…`), which the tests above pin as absent. Screenshots: #200988 (comment) - **Affected suites (vitest-source, exact head):** freshness, renewal, worker recovery, publication events, auth-login catalog, prepared-runtime sources, native picker failures and configured catalog index: 52 tests across 5 shards pass. - **Review and CI:** local ClawSweeper review (`gpt-6.1-sol`) on `3fd0cae6` found no issues; required CI is green on the same head. Co-authored-by: Ayaan Zaidi <[email protected]>
…ker reads (openclaw#200988) ## What Problem This Solves A model that a provider launches does not appear in the Gateway model picker until the Gateway restarts, its config or credentials change, the next 6-hourly hosted catalog revision is adopted, or the user presses **Refresh**. Example: OpenAI launched `gpt-6.2-astra` and `gpt-6.2-sol` on 2026-11-17. Typed `openai/gpt-6.2-sol` turns worked on every release, but the picker kept the OpenAI listing saved before the launch. Cause: openclaw#167008 stopped ordinary `models.list` reads from renewing an expired provider listing, because that expiry was the provider's 60-second HTTP response-cache TTL and almost every picker open rebuilt the catalog. Nothing replaced it, so a saved live listing never ages on its own. ## Why This Change Was Made - A successful live listing now expires at the later of its response-cache deadline and 15 minutes after acquisition (`discoveryDeadline`). The floor keeps short TTLs from renewing on almost every read (openclaw#167008). A longer TTL still wins (openclaw#168050, ClawRouter's one hour), so the expiry relist, which honors each feed's cache, always reaches the provider instead of re-stamping a cached response as fresh. - `models.list` calls the catalog owner's existing `refreshExpiredModelCatalog`, which relists only expired providers in the background. The read returns the published rows at once; open pickers update through the existing catalog publication push. - Expiry and failed-discovery retry relists no longer mark providers pending. They revalidate rows the user already sees, so pickers show no loading state and chat `/models` adds no `checking models…` line for them. First sign-in, changed credentials and explicit **Refresh** still report progress. - The listing still decides which models a signed-in provider shows (openclaw#114356). This change only keeps that listing fresh. Accepted cost: at most one background relist per live-listed provider per 15 minutes (or per its cache TTL, when longer), and only while someone opens a picker. Providers whose listing is not retained in the live response cache (`ttlMs: 0`, self-hosted discovery) keep the previous behavior. ## User Impact A newly launched provider model appears in the picker within about 15 minutes of the provider listing it, on the first picker open, with no restart, no **Refresh**, no loading indicator and no OpenClaw release. ## Evidence - **Regression (vitest-source):** `models-list.freshness.integration.test.ts` keeps the real live response cache (500 ms TTL, no cache clearing). It asserts that the listing ages out on the 15-minute floor rather than the short TTL, and that an ordinary `models.list` read on an aged listing serves saved rows with no `pendingProviders`, relists once in the background, then publishes the new model. Fails on merge base `9decc8090873` (3/3, deadline equals the cache TTL); the no-pending assertion also fails on this PR's previous head `41ee4d30` (3/3, provider listed as pending); passes on this head (3/3). - **Renewal contract (vitest-source):** `server-chat-metadata-lifecycle.catalog-renewal.test.ts` now asserts that an expiry renewal never publishes a pending provider and that settling it sends only the real catalog change, with no refresh-status broadcast. An explicit refresh in the same file still reports refresh status. - **E2E, CLI reads (fix: source tier; base: `9decc8090873` dist-nodts):** two isolated Gateways, each with a fake LiteLLM proxy as its live listing and hosted catalog refresh disabled. At 04:03:46Z each proxy starts listing `fake-2`; an ordinary `gateway call models.list` (no refresh) runs once a minute. | Time (UTC) | Fix Gateway picker | Base Gateway picker | |---|---|---| | 04:03:41 (before) | `fake-1` | `fake-1` | | 04:04 to 04:17 | `fake-1` | `fake-1` | | 04:18:58 | `fake-1`, `fake-2` | `fake-1` | | 04:23:58 | `fake-1`, `fake-2` | `fake-1` | Proxy request logs: the fix Gateway listed at startup and once more at 04:17:58, the first read after the listing aged; no other requests. The base Gateway never listed again. - **E2E, Control UI (dist-nodts, real browser):** this head and the previous head `41ee4d30`, each with a fake LiteLLM listing whose `/models` response is held for 25 s after a new model is added. The picker is opened once the listing aged (proxy logs show the relist request at that moment), then again after release. During the relist both pickers render the saved models immediately with no loading state; the new model appears after the relist publishes. The visible difference from the previous head is the pending flag (`pendingProviders`, and chat `/models` `checking models…`), which the tests above pin as absent. Screenshots: openclaw#200988 (comment) - **Affected suites (vitest-source, exact head):** freshness, renewal, worker recovery, publication events, auth-login catalog, prepared-runtime sources, native picker failures and configured catalog index: 52 tests across 5 shards pass. - **Review and CI:** local ClawSweeper review (`gpt-6.1-sol`) on `3fd0cae6` found no issues; required CI is green on the same head. Co-authored-by: Ayaan Zaidi <[email protected]>
What Problem This Solves
Fixes repeated background catalog rebuilds when ordinary
models.listreads encounter an expired provider response cache, even though the Gateway's catalog inputs have not changed.User Impact
Model picker reads reuse the lifecycle-published catalog. Startup, changed configuration or credentials, plugin and hosted metadata updates, and explicit Refresh continue to acquire inventory. Use Refresh to discover newly advertised upstream models. Native CLI login checks remain active; the shipped SDK's renewal getters retain their existing behavior.
Why This Change Was Made
The discovery HTTP cache TTL had also become the Gateway inventory invalidation policy. Remove that request-driven rebuild from
models.listand consume the existing owner publication. Unavoidable full builds now normalize registry rows once and carry those same rows into both display and executable catalogs, within one plugin generation scope.Production delta is +1 line: deleting duplicate normalization/scoping offsets the new native-login callback, which is required to preserve CLI sign-in availability independently of provider-inventory renewal. No second catalog cache, configuration option, schema change, or migration is introduced.
Evidence
Validation used an isolated Ubuntu Linux rig after Blacksmith Testbox lease
tbx_01m4cxscwntj33p6pp06srkef9stayed queued. That lease was stopped; AWS and Hetzner each refused allocation at the shared fleet limit and allocated no lease. No heavy validation ran on the development Mac.Completed validation:
An earlier rig measurement gave 100.69 ms candidate p99 and zero discovery. Its original-code timing run was refused by the build memory guard before testing; no guard was bypassed. The isolated comparison above replaces that missing pair.
The complete changed gate passed on Blacksmith Testbox
tbx_01m4d1cg4y2tpr65kw8rqdsbx4in 25m17.948s, after validating all 16 candidate file hashes. Command:node scripts/check-changed.mjs --staged --base 0681dda57638f51655523319ec9a63ea4693ca31. Core typechecking, all 27 affected test graphs, lint, dead exports, runtime import cycles, and repository guards passed. The earlier rig attempt was killed with exit 137 during core typechecking; the isolated Testbox result completes that gate.The first CI run on
dba8e9a2fcd291025172f34f547351ac75075ee2found one stale recovery fixture still relying on the removed read-triggered renewal. The fixture now explicitly invokes the SDK-owned renewal entry point with the published config before exercising passive RPC reads and worker recovery. Its assertions and timeout are preserved. On Blacksmith Testboxtbx_01m4d4zmcbf8dcx4vcvrankyc8, the fixed file passed in 22.34 s wall time / 12.11 s test time; the five other catalog integration siblings passed all 11 tests. A fresh P0–P2 review found no actionable findings.Final candidate:
df53572a2bc24b890ac2f3b135ab53437bcb5365, rebased onto main939380f4920cf22bd5fefc03bf4d2976ee893f06to incorporate the existing placement-authority unused-export fix. The production patch is unchanged. Upstream selected-account refresh changes were checked with 32 passing tests in five files (140.85 s command wall time), including account decisions, service tiers, ordinary reads, worker recovery, and native renewal. Blacksmith Testboxtbx_01m4d6ntk0brn8xy5z89q7446bverified all 17 changed-file hashes and the complete candidate Git tree941bf21c2d68fc99091191de3f839b76330d2b8e. The final-base run passed core types, all 27 test graphs, dead exports, lint, schema and legacy-store guards, then its transport was canceled during the last import-cycle stage after 33m29.843s. The remaining import-cycle, webhook-body, pairing-store, and pairing-account guards all passed on the isolated Linux rig at exact commitdf53572a2bc24b890ac2f3b135ab53437bcb5365/ tree941bf21c2d68fc99091191de3f839b76330d2b8e. Thus every planned check completed; the final Testbox aggregate was interrupted and is not reported as a successful aggregate. Final-head CI passed: https://github.com/openclaw/openclaw/actions/runs/37749804300 (48 successful jobs, 458 s workflow wall time). The PR merged ascd8b5d37d591fa27ac33e592d0dad65123e8f79e; the landed patch ID matches the reviewed two-commit candidate.Production post-deployment
models.listp99 and byte equality of consecutive production catalogs remain unmeasured: this change does not deploy or modify the running Gateway.Remote commands and test cost
The rig ran these commands serially under
nice -n 10 ionice -c3, with task-local state andTMPDIR:The changed integration files took 47.19 s (
prepared-model-catalog-worker.reuse.integration.test.ts) and 114.17 s (models-list.freshness.integration.test.ts) of test execution in the single-worker run. Their existing real-worker/real-Gateway fixtures verify serialized catalog publication, scoped credentials, resource retirement, and actual RPC-triggered acquisition; a helper-only test cannot prove those boundaries. Other changed files took 0.02–25.22 s each. The complete focused command took 609.84 s including shared cold preparation; individual cold command wall times were not independently measured. Final CI took 458 s wall time; its Node test jobs consumed 3576 aggregate job-seconds.Recovery after the final Testbox interruption followed the authorized provider order. AWS and the subsequent Hetzner allocation were capacity-limited; one intermediate Hetzner lease,
cbx_bc326e2005cb, stalled during raw source sync and ran no check commands before being released. The final four guards used the rig's pinned PR checkout, with no source upload or guard override. Every allocated cloud lease has been stopped.The original-code negative controls ran the changed Gateway integration file and worker reuse file against original production sources. Both failed for the intended regression. The disposable 512-row probe ran through the same Gateway RPC fixture; it is not committed as an extra test.