Skip to content

fix(gateway): read-only persisted fast path for models.list catalog - #76406

Merged
vincentkoc merged 4 commits into
openclaw:mainfrom
Marvinthebored:fix/models-list-read-only-fast-path
May 3, 2026
Merged

vincentkoc merged 4 commits into
openclaw:mainfrom
Marvinthebored:fix/models-list-read-only-fast-path

Conversation

@Marvinthebored

Copy link
Copy Markdown
Contributor

Summary

  • Gateway catalog refresh now passes readOnly: true to loadModelCatalog()
  • In read-only mode, skip augmentModelCatalogWithProviderPlugins() — live provider discovery is admin/background work
  • Add a persisted models.json fast path: read the existing file directly instead of instantiating the full PI SDK registry, auth storage, and model suppression pipeline
  • Falls back to the full catalog path if persisted models.json is missing or unreadable

Problem

models.list in the Control UI triggers loadGatewayModelCatalog(), which calls loadModelCatalog() without readOnly. This runs the full catalog pipeline:

  1. ensureOpenClawModelsJson() — regenerates models.json from provider configs (measured at 62s on a production install)
  2. PI SDK import + auth storage discovery (~4s)
  3. Full registry instantiation + model enumeration
  4. augmentModelCatalogWithProviderPlugins() — live provider/plugin model discovery (~5s)
  5. Model suppression, configured models merge, sort

Total observed: 60-70s blocking the event loop for a read-only UI list call. The existing 750ms timeout on sessions.list's model catalog dependency couldn't help because the synchronous/CPU work starts before timers can fire.

Fix

Gateway read-only flag: startGatewayModelCatalogRefresh() now passes readOnly: true. This was the original intent of the readOnly parameter but was never wired up in the gateway path.

Skip plugin augmentation in read-only mode: augmentModelCatalogWithProviderPlugins() discovers live provider models — useful for explicit admin refresh, not for polling UI lists. Skipped when readOnly is true.

Persisted models.json fast path: When readOnly is true, loadModelCatalog() first tries loadReadOnlyPersistedModelCatalog():

  • Reads agents/main/agent/models.json directly via readFile
  • Converts providers.<provider>.models[] to ModelCatalogEntry rows
  • Adds explicitly configured models via buildConfiguredModelCatalog()
  • Sorts/deduplicates normally
  • Falls back to the full PI registry path on any error

Entry count note: The fast path returns persisted + configured models only (e.g. 89 entries), not the full generated registry catalog (e.g. 967 entries). This is the correct shape for a Control UI list. If view=all semantics need to include generated registry models, that should be a separate explicit API path.

Measurements (production install)

Metric Before After
loadGatewayModelCatalog() 967 entries, 4651ms 89 entries, 8ms
Live models.list at startup ~18s ~2s

Test plan

  • models.list returns persisted + configured models in read-only mode
  • Missing models.json falls back to full catalog path without error
  • Explicit admin catalog refresh still runs full discovery pipeline
  • markGatewayModelCatalogStaleForReload() triggers fresh read on next call

🤖 Generated with Claude Code

@openclaw-barnacle openclaw-barnacle Bot added gateway Gateway runtime agents Agent runtime and tooling size: S labels May 3, 2026
@clawsweeper

clawsweeper Bot commented May 3, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge.

Summary
The branch updates Gateway model catalog loading so default/configured models.list calls use a read-only cache and persisted models.json fast path, while view: "all" keeps the full catalog path, with tests and a changelog entry.

Reproducibility: yes. for the source-level hot path: current main calls loadGatewayModelCatalog() without readOnly, and that path can prepare models.json, instantiate the PI registry, and augment provider plugins before the timeout helps. I did not live-reproduce the reported production timing.

Next step before merge
No repair lane is needed: the patch has no actionable review finding, the latest head checks are green, and the remaining step is ordinary maintainer review/merge of this open implementation PR.

Security
Cleared: The diff adds local read-only catalog parsing, cache selection, tests, and changelog text without new dependencies, permissions, downloads, lifecycle hooks, secret writes, or external code execution paths.

Review details

Best possible solution:

Land this PR after maintainer approval, keeping normal model pickers on the read-only fast path and reserving the full catalog for explicit diagnostic/discovery calls.

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

Yes for the source-level hot path: current main calls loadGatewayModelCatalog() without readOnly, and that path can prepare models.json, instantiate the PI registry, and augment provider plugins before the timeout helps. I did not live-reproduce the reported production timing.

Is this the best way to solve the issue?

Yes: the PR is the narrow maintainable fix because it uses the existing read-only contract for picker-sized calls, adds a persisted local fast path with registry fallback, and keeps view: "all" on a separate full-catalog cache.

What I checked:

  • Current main calls the gateway catalog without read-only: Default/configured models.list creates catalogPromise = context.loadGatewayModelCatalog() with no read-only parameter, so picker calls enter the default full gateway catalog cache path. (src/gateway/server-methods/models.ts:33, 411df5991608)
  • Current main gateway cache loads the full catalog by default: startGatewayModelCatalogRefresh() invokes loadModelCatalog({ config }), so the gateway wrapper does not request the existing read-only mode. (src/gateway/server-model-catalog.ts:46, 411df5991608)
  • Current main full path can perform expensive discovery work: The non-read-only path calls ensureOpenClawModelsJson(), imports the PI SDK, instantiates the registry, then runs augmentModelCatalogWithProviderPlugins(). (src/agents/model-catalog.ts:198, 411df5991608)
  • PR head preserves full and picker catalog semantics: The patch passes { readOnly: false } for view: "all" and { readOnly: true } for default/configured model-list calls. (src/gateway/server-methods/models.ts:29, 26ec2018be63)
  • PR head adds persisted read-only parsing with fallback: The patch adds loadReadOnlyPersistedModelCatalog() before the full registry path and falls through when the persisted file is missing, unreadable, or has no usable rows. (src/agents/model-catalog.ts:203, 26ec2018be63)
  • PR head separates read-only and full gateway caches: The patch introduces separate read-only and full catalog cache objects so picker-sized results are not reused for explicit full-catalog requests. (src/gateway/server-model-catalog.ts:14, 26ec2018be63)

Likely related people:

  • steipete: Peter Steinberger introduced models.list, added the model catalog dropdown/loading path, added catalog caching, and has extensive later model-config/provider-discovery maintenance in this area. (role: original and ongoing maintainer; confidence: high; commits: 817abd8b5f4e, 1916e688a692, b3415125645b; files: src/gateway/server-methods/models.ts, src/gateway/server-model-catalog.ts, src/agents/model-catalog.ts)
  • vincentkoc: Vincent Koc is tied to the current-main versions of the central gateway/model-catalog files and recent adjacent gateway responsiveness work, and also force-pushed the PR follow-up commits that preserve full-catalog semantics. (role: recent maintainer and follow-up owner; confidence: high; commits: a89b0dda2f05, 23e0be355ac3, 995b72c851d4; files: src/gateway/server-methods/models.ts, src/gateway/server-model-catalog.ts, src/agents/model-catalog.ts)
  • Marvinthebored: Marvinthebored authored this PR's initial fast-path proposal and has recent merged main-branch work on Gateway event-loop starvation and lightweight list paths, so routing context is relevant beyond only opening this PR. (role: source proposer and adjacent contributor; confidence: medium; commits: 7fe4ba013ff0, 4c9a557533a7, 683650fce07b; files: src/gateway, src/agents/model-catalog.ts, src/gateway/server-model-catalog.ts)

Remaining risk / open question:

  • The production 60-70s timing was not live-reproduced in this read-only pass; the review evidence is source-level plus PR tests and green CI.

Codex review notes: model gpt-5.5, reasoning high; reviewed against 411df5991608.

Peetiegonzalez and others added 4 commits May 2, 2026 22:34
The gateway model catalog refresh calls loadModelCatalog without
readOnly, triggering ensureOpenClawModelsJson (60-70s), full PI SDK
registry instantiation, auth storage discovery, and live provider
plugin augmentation on every Control UI list/refresh. None of this
is needed for a read-only UI listing.

Three changes:

1. Gateway catalog refresh now passes readOnly: true to loadModelCatalog.
2. In readOnly mode, skip augmentModelCatalogWithProviderPlugins — live
   provider discovery is explicit admin/background work, not a UI list
   operation.
3. Add a persisted models.json fast path: when readOnly is true, first
   try reading the existing models.json directly and converting
   providers.<provider>.models[] to catalog rows. Falls back to the
   full PI registry path if the file is missing or unreadable.

Observed improvement on a production install:
  loadGatewayModelCatalog: 967 entries / 4651ms → 89 entries / 8ms
  Live models.list during startup: ~18s → ~2s

Co-Authored-By: Claude Opus 4.6 <[email protected]>
@vincentkoc vincentkoc self-assigned this May 3, 2026
@vincentkoc
vincentkoc merged commit 73a95d3 into openclaw:main May 3, 2026
101 checks passed
lxe pushed a commit to lxe/openclaw that referenced this pull request May 6, 2026
…penclaw#76406)

* fix(gateway): read-only fast path for models.list catalog loading

The gateway model catalog refresh calls loadModelCatalog without
readOnly, triggering ensureOpenClawModelsJson (60-70s), full PI SDK
registry instantiation, auth storage discovery, and live provider
plugin augmentation on every Control UI list/refresh. None of this
is needed for a read-only UI listing.

Three changes:

1. Gateway catalog refresh now passes readOnly: true to loadModelCatalog.
2. In readOnly mode, skip augmentModelCatalogWithProviderPlugins — live
   provider discovery is explicit admin/background work, not a UI list
   operation.
3. Add a persisted models.json fast path: when readOnly is true, first
   try reading the existing models.json directly and converting
   providers.<provider>.models[] to catalog rows. Falls back to the
   full PI registry path if the file is missing or unreadable.

Observed improvement on a production install:
  loadGatewayModelCatalog: 967 entries / 4651ms → 89 entries / 8ms
  Live models.list during startup: ~18s → ~2s

Co-Authored-By: Claude Opus 4.6 <[email protected]>

* fix(gateway): preserve full model catalog view

* fix(agents): preserve read-only catalog defaults

* fix(agents): preserve provider catalog defaults

---------

Co-authored-by: Marvinthebored <[email protected]>
Co-authored-by: Claude Opus 4.6 <[email protected]>
Co-authored-by: Vincent Koc <[email protected]>
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request May 24, 2026
…penclaw#76406)

* fix(gateway): read-only fast path for models.list catalog loading

The gateway model catalog refresh calls loadModelCatalog without
readOnly, triggering ensureOpenClawModelsJson (60-70s), full PI SDK
registry instantiation, auth storage discovery, and live provider
plugin augmentation on every Control UI list/refresh. None of this
is needed for a read-only UI listing.

Three changes:

1. Gateway catalog refresh now passes readOnly: true to loadModelCatalog.
2. In readOnly mode, skip augmentModelCatalogWithProviderPlugins — live
   provider discovery is explicit admin/background work, not a UI list
   operation.
3. Add a persisted models.json fast path: when readOnly is true, first
   try reading the existing models.json directly and converting
   providers.<provider>.models[] to catalog rows. Falls back to the
   full PI registry path if the file is missing or unreadable.

Observed improvement on a production install:
  loadGatewayModelCatalog: 967 entries / 4651ms → 89 entries / 8ms
  Live models.list during startup: ~18s → ~2s

Co-Authored-By: Claude Opus 4.6 <[email protected]>

* fix(gateway): preserve full model catalog view

* fix(agents): preserve read-only catalog defaults

* fix(agents): preserve provider catalog defaults

---------

Co-authored-by: Marvinthebored <[email protected]>
Co-authored-by: Claude Opus 4.6 <[email protected]>
Co-authored-by: Vincent Koc <[email protected]>
jameslcowan pushed a commit to jameslcowan/openclaw that referenced this pull request Jun 2, 2026
…penclaw#76406)

* fix(gateway): read-only fast path for models.list catalog loading

The gateway model catalog refresh calls loadModelCatalog without
readOnly, triggering ensureOpenClawModelsJson (60-70s), full PI SDK
registry instantiation, auth storage discovery, and live provider
plugin augmentation on every Control UI list/refresh. None of this
is needed for a read-only UI listing.

Three changes:

1. Gateway catalog refresh now passes readOnly: true to loadModelCatalog.
2. In readOnly mode, skip augmentModelCatalogWithProviderPlugins — live
   provider discovery is explicit admin/background work, not a UI list
   operation.
3. Add a persisted models.json fast path: when readOnly is true, first
   try reading the existing models.json directly and converting
   providers.<provider>.models[] to catalog rows. Falls back to the
   full PI registry path if the file is missing or unreadable.

Observed improvement on a production install:
  loadGatewayModelCatalog: 967 entries / 4651ms → 89 entries / 8ms
  Live models.list during startup: ~18s → ~2s

Co-Authored-By: Claude Opus 4.6 <[email protected]>

* fix(gateway): preserve full model catalog view

* fix(agents): preserve read-only catalog defaults

* fix(agents): preserve provider catalog defaults

---------

Co-authored-by: Marvinthebored <[email protected]>
Co-authored-by: Claude Opus 4.6 <[email protected]>
Co-authored-by: Vincent Koc <[email protected]>
sablehead pushed a commit to sablehead/openclaw that referenced this pull request Jun 10, 2026
…penclaw#76406)

* fix(gateway): read-only fast path for models.list catalog loading

The gateway model catalog refresh calls loadModelCatalog without
readOnly, triggering ensureOpenClawModelsJson (60-70s), full PI SDK
registry instantiation, auth storage discovery, and live provider
plugin augmentation on every Control UI list/refresh. None of this
is needed for a read-only UI listing.

Three changes:

1. Gateway catalog refresh now passes readOnly: true to loadModelCatalog.
2. In readOnly mode, skip augmentModelCatalogWithProviderPlugins — live
   provider discovery is explicit admin/background work, not a UI list
   operation.
3. Add a persisted models.json fast path: when readOnly is true, first
   try reading the existing models.json directly and converting
   providers.<provider>.models[] to catalog rows. Falls back to the
   full PI registry path if the file is missing or unreadable.

Observed improvement on a production install:
  loadGatewayModelCatalog: 967 entries / 4651ms → 89 entries / 8ms
  Live models.list during startup: ~18s → ~2s

Co-Authored-By: Claude Opus 4.6 <[email protected]>

* fix(gateway): preserve full model catalog view

* fix(agents): preserve read-only catalog defaults

* fix(agents): preserve provider catalog defaults

---------

Co-authored-by: Marvinthebored <[email protected]>
Co-authored-by: Claude Opus 4.6 <[email protected]>
Co-authored-by: Vincent Koc <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agents Agent runtime and tooling gateway Gateway runtime size: M

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants