Skip to content

fix(models): keep dynamic model lists consistent across CLI and Gateway - #114393

Merged
steipete merged 2 commits into
mainfrom
codex/unify-prepared-model-catalog
Jul 27, 2026
Merged

steipete merged 2 commits into
mainfrom
codex/unify-prepared-model-catalog

Conversation

@steipete

@steipete steipete commented Jul 27, 2026 •

Copy link
Copy Markdown
Contributor

What Problem This Solves

Fixes an issue where users browsing dynamically discovered models through the CLI, Gateway, or model picker could see stale, missing, or inconsistent models, provider aliases, authentication status, and OpenAI account routes after provider refresh or upgrade.

Why This Change Was Made

The lifecycle-owned prepared model catalog is now the single source of truth for CLI rows, Gateway model lists, static provider entries, aliases, and physical authentication routes. Generated provider catalogs move into the existing per-agent SQLite cache with an additive, verified migration that preserves released credentials, handles unreadable or concurrently superseded sidecars, atomically claims migrated source inodes, and keeps unrelated providers available; doctor --fix owns explicit repair. The change removes the duplicate discovery planners, provider previews, obsolete fallbacks, and an oversized-file baseline entry. It adds no SQLite schema-version change, protocol bump, or configuration surface.

User Impact

The CLI, Gateway, and model picker show the same current models; static entries, canonical aliases, and account-specific routes remain selectable. Existing provider credentials and healthy configured models remain available during upgrades, concurrent refreshes, unreadable sidecars, or an isolated corrupt provider catalog.

Evidence

  • 1,170 passing regression tests across 37 target roots and 11 shards, including 21 real CLI end-to-end cases, 211 Gateway tests, 83 OpenAI provider-contract tests, Anthropic, model-picker, auth-routing, and SQLite coverage.
  • 240 passing focused follow-up tests proving canonical aliases, static-only catalogs, multi-agent SQLite migrations, retained and late-arriving sidecars, atomic exact-inode claims during concurrent refresh, interrupted claim recovery, fail-safe conflict detection, transaction-verified and crash-reconciled retirement of old API keys, protected recovery under unreadable plugin directories, superseded migration credentials, invalid generated markers, isolated corrupt databases, and doctor --fix.
  • Linux Testbox: final pnpm check:changed, production pnpm build, and real 32-request Gateway stress all pass on the pushed commit.
  • Real built development Gateway: all four live WebSocket models.list projections agree with CLI results; 32 concurrent authenticated WebSocket requests succeed with identical catalogs.
  • Fresh independent autoreview: no accepted or actionable findings.
  • Direct upstream Codex contract checked: codex-rs/app-server/src/models.rs, codex-rs/app-server/src/models_refresh_worker.rs, codex-rs/app-server/src/request_processors/catalog_processor.rs, and codex-rs/app-server/tests/suite/v2/model_list.rs at 95637f7056835fea66bdd0044414af480fc0fd74; remote catalog generations are authoritative and atomically replaced.
  • Follow-up cleanup 33032174cf82: removed the obsolete provider-preview planner, supplemental manifest fallback, and unused exported catalog APIs; 44 insertions and 218 deletions (174 net fewer lines).
  • Exact hosted dependency gate reproduced on Linux: pnpm deadcode:full, pnpm deadcode:exports, and pnpm deadcode:unused-files all pass; production, full-tree, and script audits report zero unused exports or unused files.
  • Follow-up Linux regression proof: 213 passing tests across 10 target files / 5 Vitest shards, including catalog migration, agent model generation, session registry, Doctor health, manifest filtering, normalized provider index, and provider installation.
  • Fresh post-cleanup independent autoreview: no accepted or actionable findings.

@openclaw-barnacle openclaw-barnacle Bot added commands Command implementations agents Agent runtime and tooling size: XL maintainer Maintainer-authored PR labels Jul 27, 2026
@clawsweeper clawsweeper Bot added proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. P2 Normal backlog priority with limited blast radius. merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. merge-risk: 🚨 auth-provider 🚨 May break OAuth, tokens, provider routing, model choice, or credentials. labels Jul 27, 2026
@clawsweeper

clawsweeper Bot commented Jul 27, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed July 27, 2026, 3:28 AM ET / 07:28 UTC.

ClawSweeper review

What this changes

This PR makes the lifecycle-prepared model catalog the shared source for CLI, Gateway, and picker model views, while migrating generated plugin catalogs from agent sidecar files into the existing per-agent SQLite cache with Doctor-owned recovery.

Merge readiness

⚠️ Ready for maintainer review - 4 items remain

The patch appears to provide a coherent single prepared-catalog path and includes credible real Gateway proof, so no line-level correctness defect is established. It should remain open for the protected maintainer review because generated catalogs can retain provider credentials and the storage/retention approval needs a verified maintainer merge decision. Likely related people: steipete (medium confidence, current catalog and storage-decision work).

Priority: P2
Reviewed head: 33032174cf82e856fa1d31ade673742a6cda442d
Owner decision: Required. See Decision needed.

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) Strong supplied runtime and regression evidence supports a substantial but merge-sensitive catalog and persistence refactor; the remaining blocker is explicit owner confirmation of the credential-bearing storage boundary.
Proof confidence 🦞 diamond lobster (5/6) Sufficient (live_output): The PR body reports after-fix evidence from a built development Gateway: four live WebSocket models.list projections matched CLI output and 32 authenticated concurrent requests returned identical catalogs; redact any credentials or private endpoints in future posted artifacts.
Patch quality 🐚 platinum hermit (4/6) Security review found an item that needs attention.

Verification

Check Result Evidence
Real behavior Verified Sufficient (live_output): The PR body reports after-fix evidence from a built development Gateway: four live WebSocket models.list projections matched CLI output and 32 authenticated concurrent requests returned identical catalogs; redact any credentials or private endpoints in future posted artifacts.
Evidence reviewed 5 items Shared catalog projection: The PR changes src/commands/models/list.row-sources.ts and src/commands/models/list.rows.ts to project prepared catalog entries, while removing the provider-catalog and source-plan paths that previously planned alternate CLI list sources.
Persistent-state migration boundary: The PR changes generated plugin model catalogs from sidecar files to the existing per-agent SQLite cache in src/agents/plugin-model-catalog.ts, with a Doctor migration in src/commands/doctor-plugin-model-catalog.ts; the supplied tests cover migration, interrupted recovery, unreadable sources, and credential preservation.
Current review discussion: The author supplied real built-Gateway evidence: CLI and four live WebSocket models.list projections agreed, and 32 authenticated concurrent requests returned identical catalogs. The PR has the repository proof: sufficient label and a successful Real behavior proof check in the provided context.
Findings None None.
Security Needs attention Confirm credential retention in the agent cache: Generated provider catalogs can contain API keys and account-specific routes; this patch persists them through the per-agent SQLite cache_entries contract, so the long-term access, retention, and Doctor recovery policy must be explicitly confirmed before merge.

How this fits together

Provider discovery and authentication information feed a prepared model catalog that is projected into CLI commands, Gateway models.list responses, and model selection. The PR changes where generated provider-catalog payloads persist and removes parallel list-planning paths so those projections use the same prepared generation.

flowchart LR
  Providers[Provider discovery and auth] --> Prepared[Prepared model catalog]
  Sidecars[Released catalog sidecars] --> Doctor[Doctor migration]
  Doctor --> AgentDb[Per-agent SQLite cache]
  AgentDb --> Prepared
  Prepared --> CLI[CLI model list]
  Prepared --> Gateway[Gateway models list]
  Prepared --> Picker[Model picker]
Loading

Decision needed

Question Recommendation
Does a verified maintainer approve retaining generated provider catalog payloads, including any existing API-key or account-route data, in the per-agent SQLite cache_entries contract across upgrade and Doctor recovery? Confirm SQLite ownership: Record that the existing private per-agent database and cache_entries lifecycle are the approved owner for generated provider catalog payloads and merge after the current-head checks finish.

Why: The implementation moves credential-bearing state across a persistence boundary. The supplied follow-up says this was approved, but the PR is externally associated and protected by the maintainer label, so merge authorization should explicitly confirm the durable security and retention contract.

Before merge

  • Resolve security concern: Confirm credential retention in the agent cache - Generated provider catalogs can contain API keys and account-specific routes; this patch persists them through the per-agent SQLite cache_entries contract, so the long-term access, retention, and Doctor recovery policy must be explicitly confirmed before merge.
  • Resolve merge risk (P1) - Generated catalog payloads can include API keys and account-specific routes; merging changes their retention location from private sidecars to SQLite cache_entries, so a verified maintainer must confirm the intended access, retention, and recovery contract.
  • Resolve merge risk (P1) - Existing installations with legacy generated sidecars need the Doctor migration to succeed before the canonical SQLite-backed catalog is safely prepared; upgrade handling remains compatibility- and auth-provider-sensitive.

Findings

  • [medium] Confirm credential retention in the agent cache — src/agents/plugin-model-catalog.ts:1
Agent review details

Security

Needs attention: No concrete insecure file-permission defect is established, but moving potentially credential-bearing catalog JSON into SQLite is a merge-critical storage and retention boundary that requires verified maintainer approval.

PR surface

Source -82, Tests +677, Other -1. Total +594 across 32 files.

View PR surface stats
Area Files Added Removed Net
Source 15 939 1021 -82
Tests 16 1665 988 +677
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 1 0 1 -1
Total 32 2604 2010 +594

Review metrics

Metric Value Why it matters
Persistent catalog owner 1 storage owner changed: sidecar files to per-agent SQLite cache This changes upgrade, retention, recovery, and private credential-handling behavior even without a schema-version or configuration change.

Stored data model

Persistent data-model change detected: migration/backfill/repair: src/agents/models-config.ts, migration/backfill/repair: src/agents/plugin-model-catalog.ts, migration/backfill/repair: src/commands/doctor-plugin-model-catalog.test.ts, migration/backfill/repair: src/commands/doctor-plugin-model-catalog.ts, migration/backfill/repair: src/flows/doctor-health-contributions.test.ts, migration/backfill/repair: src/flows/doctor-health-contributions.ts, and 17 more. Migration or upgrade compatibility proof is recorded; maintainers should verify it before merge.

Merge-risk options

Maintainer options:

  1. Confirm the storage contract before merge (recommended)
    Accept the migration only after a verified maintainer explicitly confirms that private per-agent SQLite cache retention is appropriate for generated provider catalogs that may carry credentials.
  2. Pause for a narrower secret boundary
    Do not merge if catalog payloads must not retain credential material in cache_entries; redesign the persisted representation before continuing.

Technical review

Best possible solution:

Land only after a verified maintainer confirms that per-agent cache_entries is the intended long-term credential-bearing catalog owner and accepts the Doctor-owned migration and recovery contract; retain the single prepared-catalog projection rather than reintroducing preview or fallback planners.

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

Yes, at source level: the prior CLI source-plan and provider-preview paths could project a different catalog from the prepared Gateway/registry generation. The supplied PR evidence also describes a real built-Gateway comparison, but this review did not independently rerun it.

Is this the best way to solve the issue?

Yes, provisionally: projecting CLI and Gateway from one lifecycle-prepared catalog removes the competing discovery planners rather than adding another synchronization layer. The SQLite migration is only the best complete solution if a maintainer confirms the credential-retention contract.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning high; reviewed against 00175666189e.

Labels

Label changes:

  • add merge-risk: 🚨 security-boundary: The migration relocates potentially credential-bearing generated catalog payloads into the per-agent SQLite cache, requiring explicit owner approval of retention and access semantics.
  • add rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🦞 diamond lobster and patch quality is 🐚 platinum hermit.
  • add status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Sufficient (live_output): The PR body reports after-fix evidence from a built development Gateway: four live WebSocket models.list projections matched CLI output and 32 authenticated concurrent requests returned identical catalogs; redact any credentials or private endpoints in future posted artifacts.
  • remove rating: 🦐 gold shrimp: Current PR rating is rating: 🐚 platinum hermit, so this older rating label is no longer current.
  • remove status: ⏳ waiting on author: Current PR status label is status: 👀 ready for maintainer look.

Label justifications:

  • P2: The change affects model discovery and provider routes across CLI and Gateway, but the supplied regression and live-proof evidence does not indicate an active emergency.
  • merge-risk: 🚨 compatibility: Released generated catalog sidecars must migrate into the new canonical SQLite-backed catalog representation during upgrade.
  • merge-risk: 🚨 auth-provider: The persisted data influences provider aliases, authentication status, account-specific routes, and provider credentials.
  • merge-risk: 🚨 security-boundary: The migration relocates potentially credential-bearing generated catalog payloads into the per-agent SQLite cache, requiring explicit owner approval of retention and access semantics.
  • rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🦞 diamond lobster and patch quality is 🐚 platinum hermit.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Sufficient (live_output): The PR body reports after-fix evidence from a built development Gateway: four live WebSocket models.list projections matched CLI output and 32 authenticated concurrent requests returned identical catalogs; redact any credentials or private endpoints in future posted artifacts.
  • proof: sufficient: Contributor real behavior proof is sufficient. The PR body reports after-fix evidence from a built development Gateway: four live WebSocket models.list projections matched CLI output and 32 authenticated concurrent requests returned identical catalogs; redact any credentials or private endpoints in future posted artifacts.

Evidence

Security concerns:

  • [medium] Confirm credential retention in the agent cache — src/agents/plugin-model-catalog.ts:1
    Generated provider catalogs can contain API keys and account-specific routes; this patch persists them through the per-agent SQLite cache_entries contract, so the long-term access, retention, and Doctor recovery policy must be explicitly confirmed before merge.
    Confidence: 0.86

What I checked:

Likely related people:

  • steipete: Authored both commits and the follow-up that records the claimed per-agent SQLite storage-owner decision and the catalog-path cleanup. (role: current catalog and storage-decision contributor; confidence: medium; commits: 83b40f3d2a61, 33032174cf82; files: src/agents/plugin-model-catalog.ts, src/agents/models-config.ts, src/commands/doctor-plugin-model-catalog.ts)

Rank-up moves

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

  • Have a verified maintainer record the per-agent SQLite credential-retention decision before merge.

Rating scale

Score Internal tier Crab rank Meaning
6/6 S 🦀 challenger crab Exceptional readiness
5/6 A 🦞 diamond lobster Very strong readiness
4/6 B 🐚 platinum hermit Good normal PR; ordinary maintainer review
3/6 C 🦐 gold shrimp Useful, but confidence is limited
2/6 D 🦪 silver shellfish Proof or implementation needs work
1/6 F 🧂 unranked krab Not merge-ready
N/A NA 🌊 off-meta tidepool Rating does not apply

Overall follows the weaker of proof and patch quality.
Shiny media proof means a screenshot, video, or linked artifact directly shows the changed behavior. Runtime, network, CSP, and security claims still need visible diagnostics.

Workflow

  • ClawSweeper keeps one durable marker-backed review comment per issue or PR.
  • Re-runs edit this comment so the latest verdict, findings, and automation markers stay together instead of adding duplicate bot comments.
  • A fresh review can be triggered by eligible @clawsweeper re-review comments, exact-item GitHub events, scheduled/background review runs, or manual workflow dispatch.
  • PR/issue authors and users with repository write access can comment @clawsweeper re-review or @clawsweeper re-run on an open PR or issue to request a fresh review only.
  • Maintainers can also comment @clawsweeper review to request a fresh review only.
  • Fresh-review commands do not start repair, autofix, rebase, CI repair, or automerge.
  • Maintainer-only repair and merge flows require explicit commands such as @clawsweeper autofix, @clawsweeper automerge, @clawsweeper fix ci, or @clawsweeper address review.
  • Maintainers can comment @clawsweeper explain to ask for more context, or @clawsweeper stop to stop active automation.

History

Review history (2 earlier review cycles)
  • reviewed 2026-07-27T07:01:46.086Z sha 83b40f3 :: needs maintainer review before merge. :: none
  • reviewed 2026-07-27T07:18:39.189Z sha 83b40f3 :: needs maintainer review before merge. :: none

@steipete

Copy link
Copy Markdown
Contributor Author

Addressing the ClawSweeper rank-up moves and maintainer decision before landing:

  • Storage owner: approved. Generated provider catalogs belong in the existing per-agent agents/<agentId>/agent/openclaw-agent.sqlite and its existing cache_entries contract; this follows the repository's database-first policy. src/state/openclaw-agent-db-permissions.ts enforces private 0700 agent-state directories and 0600 permissions on SQLite, WAL, SHM, and journal files. src/state/openclaw-agent-db.ts verifies normalized agent ownership, supported schema, integrity, and lifecycle. This change adds no schema version, protocol version, config field, or parallel steady-state file.
  • Credential and upgrade proof. Migration claims the exact source before committing, verifies cross-process handoff, retains readable-but-unwritable sources, blocks unreadable/conflicting claims, recovers interrupted claims through Doctor, and removes temporary credential payloads only after transactionally verifying canonical state. The final independent autoreview is clean. The focused Linux Testbox matrix passes 240 tests; the broader 1,170-test matrix covers real CLI E2E, Gateway, provider, auth, OpenAI, and picker paths.
  • Actual Gateway proof. The pushed commit passes pnpm check:changed, pnpm build, all four live built-Gateway models.list projections, and 32 concurrent authenticated WebSocket requests.
  • Current-main proof. Landing uses scripts/pr review-init, validated structured maintainer review artifacts, OPENCLAW_TESTBOX=1 scripts/pr prepare-run, and scripts/pr merge-run; the guarded prepare validates the actual merge candidate against current main. No moving-main gate is bypassed.

@steipete

Copy link
Copy Markdown
Contributor Author

Maintainer/storage-owner confirmation for the updated head 33032174cf82e856fa1d31ade673742a6cda442d: the existing private per-agent SQLite database is the approved owner for generated provider catalog payloads, including any existing provider credential. This uses the pre-existing agent database lifecycle and cache_entries, with private 0700 agent directories, 0600 database/WAL/SHM/journal permissions, and no schema-version change, new configuration, sidecar, or fallback store. Doctor owns tagged-sidecar migration, verifies the exact claimed inode and committed payload, preserves unreadable/conflicting/interrupted sources, and retires temporary recovery data only after verification. The follow-up also removes the obsolete preview/supplemental catalog paths (174 net fewer lines). Exact Linux dependency, unused-export, and unused-file gates are green, as are 213 follow-up regressions; guarded current-main candidate validation and merge will run before landing. This records the requested storage-owner decision and addresses both listed rank-up moves.

@clawsweeper clawsweeper Bot added rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. merge-risk: 🚨 security-boundary 🚨 May affect sandboxing, authorization, credentials, or sensitive data. and removed rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. labels Jul 27, 2026
@steipete
steipete merged commit 498a2ca into main Jul 27, 2026
150 of 156 checks passed
@steipete
steipete deleted the codex/unify-prepared-model-catalog branch July 27, 2026 07:46
@steipete

Copy link
Copy Markdown
Contributor Author

Merged via squash.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agents Agent runtime and tooling commands Command implementations maintainer Maintainer-authored PR merge-risk: 🚨 auth-provider 🚨 May break OAuth, tokens, provider routing, model choice, or credentials. merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. merge-risk: 🚨 security-boundary 🚨 May affect sandboxing, authorization, credentials, or sensitive data. P2 Normal backlog priority with limited blast radius. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. size: XL status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant