Skip to content

fix(models): preserve authored rows during generated catalog refresh - #142302

Merged
obviyus merged 2 commits into
mainfrom
feat/generated-catalog-membership
Sep 8, 2026
Merged

obviyus merged 2 commits into
mainfrom
feat/generated-catalog-membership

Conversation

@obviyus

@obviyus obviyus commented Sep 8, 2026 •

Copy link
Copy Markdown
Collaborator

Related: #136257.

What Problem This Solves

Fixes an issue where generated catalog refresh hid an authored root model when a plugin owned the same provider. Deferred plugins could also restore cached models without current authentication.

Why This Change Was Made

Keep authored root providers separate during planning. Admit deferred generated inventory only after current ownership, endpoint eligibility and authentication checks. Consolidate generated-marker detection in one implementation.

User Impact

Merge mode retains manual models and authentication-only records. Explicit replacement, empty replacement, recovery and managed secrets retain their contracts. No schema or migration change.

Consumers: generated-catalog planning and deferred cache admission distinguish authored rows from generated inventory.

Evidence

Compiled refresh lost the authored model before the fix and retained all four models afterward. Deferred cache returned no models without credentials, while valid environment/configured keys retained the model. Focused membership, registry, planning and credential tests passed. Proof used compiled commands and synthetic services, not a standalone installation or live provider.

@obviyus obviyus self-assigned this Sep 8, 2026
@clawsweeper

clawsweeper Bot commented Sep 8, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

Pull request received. I will update this pull request when review starts.

ClawSweeper review complete

ClawSweeper finished reviewing this revision. The review result is being finalized.

View the workflow run.

@openclaw-barnacle openclaw-barnacle Bot added docs Improvements or additions to documentation agents Agent runtime and tooling size: M maintainer Maintainer-authored PR labels Sep 8, 2026
@obviyus
obviyus marked this pull request as ready for review September 8, 2026 15:58
@obviyus
obviyus requested a review from a team as a code owner September 8, 2026 15:58
@clawsweeper clawsweeper Bot added P2 Normal backlog priority with limited blast radius. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. labels Sep 8, 2026
@clawsweeper

clawsweeper Bot commented Sep 8, 2026

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed September 8, 2026, 12:36 PM ET / 16:36 UTC.

ClawSweeper review

What this changes

Preserves manually authored model entries during generated catalog refresh and requires current authentication before deferred plugins contribute cached models.

Merge readiness

✅ Ready for maintainer review

This focused repair remains useful: current main still combines authored and generated providers before planning. No blocking introduced defect was established, and the related staging PR does not supersede this work.

Priority: P2
Reviewed head: 856a646937955076eacd0175fa16b0b430a36482

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) A focused owner-level repair with meaningful regression coverage and no established blocking defect.
Proof confidence 🌊 off-meta tidepool Not applicable: The authoritative repository context identifies a MEMBER author, so the external-contributor proof gate does not apply. Supplemental body evidence reports compiled planner and CLI checks preserving authored rows and excluding unauthenticated deferred inventory; production code is unchanged since that tested revision.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Not applicable Not applicable: The authoritative repository context identifies a MEMBER author, so the external-contributor proof gate does not apply. Supplemental body evidence reports compiled planner and CLI checks preserving authored rows and excluding unauthenticated deferred inventory; production code is unchanged since that tested revision.
Evidence reviewed 8 items Current main still contains the reported overwrite: The current-main helper copies root providers, then assigns generated providers under the same IDs before planning, replacing the authored provider object.
Separate planning preserves authorship: Generated recovery uses plugin catalogs separately; the root merge retains existing root declarations and reapplies normalization and managed-secret enforcement. Explicit replace still bypasses preservation.
Membership filtering stays inside the catalog boundary: Ownership and endpoint filtering precede the deferred-plugin authentication check. ModelRegistry supplies existing AuthStorage and configured-key predicates; this changes inventory membership without adding request authority or a Codex dependency.
Findings None None.
Security None None.

How this fits together

OpenClaw combines manually declared models with plugin-generated inventory to populate model lists and agent registries. Catalog planning maintains those sources, while registry loading decides which generated entries are currently eligible.

flowchart TD
  A[Manual model declarations] --> C[Catalog planning]
  B[Generated plugin inventory] --> C
  C --> D[Separate root and generated catalogs]
  D --> E[Registry loading]
  F[Current ownership endpoints and authentication] --> E
  E --> G[Model lists and agent registry]
Loading

Before merge

None.

Agent review details

Security

None.

PR surface

Source +10, Tests +262, Docs +6, Other 0. Total +278 across 11 files.

View PR surface stats
Area Files Added Removed Net
Source 5 91 81 +10
Tests 3 263 1 +262
Docs 2 6 0 +6
Config 0 0 0 0
Generated 0 0 0 0
Other 1 1 1 0
Total 11 361 83 +278

Review metrics

None.

Technical review

Best possible solution:

Keep authored declarations independent from generated inventory while preserving existing replacement, secret-management, and request-authorization contracts.

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

Yes, from source: a generated catalog sharing a provider ID overwrites its manual root declaration before current-main planning. The PR reports compiled before/after reproduction; this review did not execute it.

Is this the best way to solve the issue?

Yes. Separating the two sources at the planning owner directly repairs the overwrite, and registry admission reuses existing ownership, endpoint, and authentication predicates.

AGENTS.md: found and applied where relevant.

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

Labels

Label changes:

  • add P2: This repairs bounded model-catalog preservation and membership behavior without evidence of an urgent system-wide outage.
  • add rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🌊 off-meta tidepool and patch quality is 🐚 platinum hermit.
  • add status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Not applicable: The authoritative repository context identifies a MEMBER author, so the external-contributor proof gate does not apply. Supplemental body evidence reports compiled planner and CLI checks preserving authored rows and excluding unauthenticated deferred inventory; production code is unchanged since that tested revision.

Label justifications:

  • P2: This repairs bounded model-catalog preservation and membership behavior without evidence of an urgent system-wide outage.
  • rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🌊 off-meta tidepool and patch quality is 🐚 platinum hermit.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Not applicable: The authoritative repository context identifies a MEMBER author, so the external-contributor proof gate does not apply. Supplemental body evidence reports compiled planner and CLI checks preserving authored rows and excluding unauthenticated deferred inventory; production code is unchanged since that tested revision.

Evidence

What I checked:

Likely related people:

  • obviyus: Suggested for follow-up; no historical authorship or introduction is verified. (role: unverified routing candidate; confidence: low)
  • Peter Steinberger: Suggested for follow-up; no historical authorship or introduction is verified. (role: unverified routing candidate; confidence: low)

Rating scale

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

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

Workflow

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

@obviyus

obviyus commented Sep 8, 2026

Copy link
Copy Markdown
Collaborator Author

landpr-approve-admin-merge
pr: 142302
head: 856a646
scope: owner-review

@obviyus
obviyus merged commit f7d2fa7 into main Sep 8, 2026
311 of 313 checks passed
@obviyus
obviyus deleted the feat/generated-catalog-membership branch September 8, 2026 16:55
@obviyus

obviyus commented Sep 8, 2026

Copy link
Copy Markdown
Collaborator Author

Thanks @obviyus!

Proof: Compiled models-list checks and independent acceptance verify that refresh keeps manual models and that deferred generated inventory requires current authentication.

  • Bug: Refresh hid a manual DeepSeek model; a deferred LM Studio cache could list an implicit model without current credentials.
  • Fix: Preserve authored roots separately from generated catalogs, with shared ownership, endpoint, and current-authentication checks.
Before After
DeepSeek refresh reduced four models to three All four remain, including the authored name and context
Deferred cache listed a model without current authentication Implicit rows stay absent; authenticated and authored controls still work

Exact-head local review is clean at B with proof A. Required CI run 34249831444 passed on attempt 2. Attempt 1's Gateway-fixture startup timeout remains in the evidence; the failed jobs recovered through the existing GitHub-runner retry path, with no test, timeout, source, or workflow change. The assertion-count failure from the preceding revision was corrected separately. No unrelated-CI exception was used.

The procedural owner-review hold for the root-authorship test was resolved by the recorded exact-head approval. Code, security, proof, and CI gates remained enforced. Compiled runtime evidence retains its original build/source identity; standalone installation and live-provider behavior are outside this proof.

github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Sep 9, 2026
…penclaw#142302)

Preserve manual root models during generated catalog refresh and require current authentication for deferred generated inventory. Keep root authorship separate from disposable cache membership, reuse the shared owner/endpoint filter, and consolidate generated-marker detection.

Compiled CLI regressions and controls, focused source checks, and independent acceptance verify the behavior.

Co-authored-by: Ayaan Zaidi <[email protected]>
obviyus added a commit that referenced this pull request Oct 16, 2026
…ies (#174641)

## What Problem This Solves

Fixes: usage reports show Claude CLI models at $0.00 when an older OpenClaw version copied plugin catalog rows into an agent's root `models.json`. Those rows also outrank the live catalog forever. On one affected install this hid $220 of `claude-opus-4-8` usage behind a frozen zero price.

## User Impact

- New writes never put discovered plugin rows in the root `models.json`.
- `openclaw doctor --fix`, which update also runs, removes old copies. It removes a provider block only when it is an exact copy of a block in that plugin's generated catalog.
- Doctor saves the previous file as `models.json.bak-<timestamp>` and lists every removed provider.
- Edited blocks, blocks with credentials or overrides, and ids that config declares are never touched.
- Afterwards, prices come from the current catalog, and `models status` shows Claude CLI native auth instead of `missing`.

## Why This Change Was Made

Discovery copies a plugin's provider under its hook aliases, so `claude-cli` received the `anthropic` catalog. When owner lookup failed, the writer sent that copy to the author-owned root file instead of the plugin catalog. Owner lookup fails for a scoped plugin snapshot, or for an alias no manifest claims (on main today: `google-antigravity`, `google-interactions`, `azure-openai`, `modelstudio-native`). Since #142302 the root file merge keeps every existing provider, so the copy never left. The cost resolver reads the root file first, so its zero placeholders for unpriced models won over catalog prices.

- **Writer:** records which plugin produced each discovered provider id. When owner lookup fails, it stores the row with that producer unless config declares the id.
- **Doctor:** the catalog owner (`doctor-plugin-model-catalog.ts`) gets the legacy repair. A detector compares root blocks with the generated catalogs and requires exact equality, so no pricing or shape heuristics are involved. The file is rewritten, never deleted, because registry reads require it.

## Evidence

- **Census:** in 8 releases (2026.5.28 → 2026.10.4) run in isolated state, plain Claude CLI use never wrote the root file. The leak needs a scoped or partial owner snapshot. A real affected file, from 2026-09-06, is a byte-for-byte deep copy of the `anthropic` block in that install's generated catalog.
- **Upgrade harness:** I seeded 2026.9.2 state with that real file plus a hand-authored `my-proxy` provider, then ran the candidate's `openclaw doctor --fix --non-interactive`.
  - `claude-cli` was removed and `my-proxy` kept. The backup is byte-identical to the seeded file.
  - A second Doctor run found nothing.
  - Two later `models.json` writes left the file hash unchanged (`3bcc218b…`).
  - Control (same migrated state with the original file restored):
    - unchanged: default model, resolved model, allowlist, fallbacks, and the agent turn (`provider=claude-cli model=claude-opus-5`);
    - the model list drops only the 7 duplicate `claude-cli/*` rows;
    - Claude CLI runtime auth goes from `missing` to `claude-cli:runtime-synthetic`, the same in repeated runs.
- **Upgrade from the latest stable (2026.10.4):**
  - Seeding: 2026.10.4 created the state, with a config provider carrying a fake key, an `openai` API-key auth profile and one real Claude CLI session. I then added the real leaked `claude-cli` root block, its generated `anthropic` catalog row and an authored root provider with a fake key. The candidate's `doctor --fix --non-interactive` then ran.
  - Removed: `claude-cli` only. The backup is byte-identical to the seeded file, and a second Doctor run changed nothing.
  - Kept: the authored root provider with its key, the config provider with its key, the auth profile, and the session (same key and id).
  - The Claude CLI turn works before and after.
  - Every other config or auth change also happens with 2026.10.4's own Doctor on the same seed: the legacy `claude-cli/*` default canonicalized to `anthropic/*`, and plaintext keys copied into auth profiles. The one exception is main's existing `"anthropic/*"` runtime entry. That Doctor leaves the `claude-cli` copy in place.
- **Copy of a real install** (credentials, leases and other plugins' catalogs stripped; isolated Gateway): Doctor found and removed the copy. `sessions.usage` for June–October, with a fresh cache and only the root file differing:

  | claude-cli model | turns | stale root | repaired |
  |---|---|---|---|
  | claude-opus-4-8 | 2105 | $0.00 | $220.04 |
  | claude-haiku-4-5 | 12 | $0.00 | $0.20 |
  | other Claude models | 609 | $95.35 | $95.35 |

  Token totals are identical (4,307,266,930). The $220.04 equals the transcript token sums at the catalog's Opus 4.8 rates.
- **Comparison with the CLI's own cost:** Claude Code recorded `costUSD` for 35 sessions on that install. Catalog rates reproduce all of them exactly ($2.5640 vs $2.5640) once cache writes are priced at the 1h rate. Historical OpenClaw transcripts did not store that split, so they estimate those turns about 31% low. #173792 records the split for new turns.
- **Tests:**
  - Doctor: exact copy removed once with a byte-exact backup; edited copy kept; config-declared id kept.
  - Writer: an unowned hook alias goes to the producing plugin's catalog, not the root file. It fails without the fix.
  - The `models-config`, plugin catalog and Doctor catalog suites pass (208 tests).

**Merge risk:**
- **Writer change:** a two-way door; revert restores the old routing.
- **Doctor repair:** rewrites user files, but only exact generated copies, always with a full backup, so a removal is recoverable by restoring the backup.
- **Blast radius:** agents whose root `models.json` holds generated plugin copies, mainly Claude CLI installs from 2026-05 to 2026-10. Unowned alias copies no longer appear as separate models; they carried the producer's baseUrl under another id.

Co-authored-by: Ayaan Zaidi <[email protected]>
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Oct 17, 2026
…ies (openclaw#174641)

## What Problem This Solves

Fixes: usage reports show Claude CLI models at $0.00 when an older OpenClaw version copied plugin catalog rows into an agent's root `models.json`. Those rows also outrank the live catalog forever. On one affected install this hid $220 of `claude-opus-4-8` usage behind a frozen zero price.

## User Impact

- New writes never put discovered plugin rows in the root `models.json`.
- `openclaw doctor --fix`, which update also runs, removes old copies. It removes a provider block only when it is an exact copy of a block in that plugin's generated catalog.
- Doctor saves the previous file as `models.json.bak-<timestamp>` and lists every removed provider.
- Edited blocks, blocks with credentials or overrides, and ids that config declares are never touched.
- Afterwards, prices come from the current catalog, and `models status` shows Claude CLI native auth instead of `missing`.

## Why This Change Was Made

Discovery copies a plugin's provider under its hook aliases, so `claude-cli` received the `anthropic` catalog. When owner lookup failed, the writer sent that copy to the author-owned root file instead of the plugin catalog. Owner lookup fails for a scoped plugin snapshot, or for an alias no manifest claims (on main today: `google-antigravity`, `google-interactions`, `azure-openai`, `modelstudio-native`). Since openclaw#142302 the root file merge keeps every existing provider, so the copy never left. The cost resolver reads the root file first, so its zero placeholders for unpriced models won over catalog prices.

- **Writer:** records which plugin produced each discovered provider id. When owner lookup fails, it stores the row with that producer unless config declares the id.
- **Doctor:** the catalog owner (`doctor-plugin-model-catalog.ts`) gets the legacy repair. A detector compares root blocks with the generated catalogs and requires exact equality, so no pricing or shape heuristics are involved. The file is rewritten, never deleted, because registry reads require it.

## Evidence

- **Census:** in 8 releases (2026.5.28 → 2026.10.4) run in isolated state, plain Claude CLI use never wrote the root file. The leak needs a scoped or partial owner snapshot. A real affected file, from 2026-09-06, is a byte-for-byte deep copy of the `anthropic` block in that install's generated catalog.
- **Upgrade harness:** I seeded 2026.9.2 state with that real file plus a hand-authored `my-proxy` provider, then ran the candidate's `openclaw doctor --fix --non-interactive`.
  - `claude-cli` was removed and `my-proxy` kept. The backup is byte-identical to the seeded file.
  - A second Doctor run found nothing.
  - Two later `models.json` writes left the file hash unchanged (`3bcc218b…`).
  - Control (same migrated state with the original file restored):
    - unchanged: default model, resolved model, allowlist, fallbacks, and the agent turn (`provider=claude-cli model=claude-opus-5`);
    - the model list drops only the 7 duplicate `claude-cli/*` rows;
    - Claude CLI runtime auth goes from `missing` to `claude-cli:runtime-synthetic`, the same in repeated runs.
- **Upgrade from the latest stable (2026.10.4):**
  - Seeding: 2026.10.4 created the state, with a config provider carrying a fake key, an `openai` API-key auth profile and one real Claude CLI session. I then added the real leaked `claude-cli` root block, its generated `anthropic` catalog row and an authored root provider with a fake key. The candidate's `doctor --fix --non-interactive` then ran.
  - Removed: `claude-cli` only. The backup is byte-identical to the seeded file, and a second Doctor run changed nothing.
  - Kept: the authored root provider with its key, the config provider with its key, the auth profile, and the session (same key and id).
  - The Claude CLI turn works before and after.
  - Every other config or auth change also happens with 2026.10.4's own Doctor on the same seed: the legacy `claude-cli/*` default canonicalized to `anthropic/*`, and plaintext keys copied into auth profiles. The one exception is main's existing `"anthropic/*"` runtime entry. That Doctor leaves the `claude-cli` copy in place.
- **Copy of a real install** (credentials, leases and other plugins' catalogs stripped; isolated Gateway): Doctor found and removed the copy. `sessions.usage` for June–October, with a fresh cache and only the root file differing:

  | claude-cli model | turns | stale root | repaired |
  |---|---|---|---|
  | claude-opus-4-8 | 2105 | $0.00 | $220.04 |
  | claude-haiku-4-5 | 12 | $0.00 | $0.20 |
  | other Claude models | 609 | $95.35 | $95.35 |

  Token totals are identical (4,307,266,930). The $220.04 equals the transcript token sums at the catalog's Opus 4.8 rates.
- **Comparison with the CLI's own cost:** Claude Code recorded `costUSD` for 35 sessions on that install. Catalog rates reproduce all of them exactly ($2.5640 vs $2.5640) once cache writes are priced at the 1h rate. Historical OpenClaw transcripts did not store that split, so they estimate those turns about 31% low. openclaw#173792 records the split for new turns.
- **Tests:**
  - Doctor: exact copy removed once with a byte-exact backup; edited copy kept; config-declared id kept.
  - Writer: an unowned hook alias goes to the producing plugin's catalog, not the root file. It fails without the fix.
  - The `models-config`, plugin catalog and Doctor catalog suites pass (208 tests).

**Merge risk:**
- **Writer change:** a two-way door; revert restores the old routing.
- **Doctor repair:** rewrites user files, but only exact generated copies, always with a full backup, so a removal is recoverable by restoring the backup.
- **Blast radius:** agents whose root `models.json` holds generated plugin copies, mainly Claude CLI installs from 2026-05 to 2026-10. Unowned alias copies no longer appear as separate models; they carried the producer's baseUrl under another id.

Co-authored-by: Ayaan Zaidi <[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 docs Improvements or additions to documentation maintainer Maintainer-authored PR P2 Normal backlog priority with limited blast radius. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. size: M 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