Skip to content

fix(models): migrate catalog credentials into SQLite - #87166

Merged
steipete merged 2 commits into
mainfrom
codex/pr-83294-models-json-api-key-marker
Aug 10, 2026
Merged

steipete merged 2 commits into
mainfrom
codex/pr-83294-models-json-api-key-marker

Conversation

@steipete

@steipete steipete commented May 27, 2026 •

Copy link
Copy Markdown
Contributor

What Problem This Solves

Generated root and plugin model catalogs can contain working plaintext provider credentials. Removing that catalog authentication path safely requires every existing key to exist in the canonical auth-profile SQLite store first; otherwise an upgrade can silently lose a working custom-provider key.

This PR is the first half of the maintainer-decided split. It prepares the database migration only. The ordered follow-up will change catalog serialization and ModelRegistry request authentication after this migration is available.

Why This Change Was Made

A combined migration-plus-runtime rewrite was too large to review and could not be staged naively. Current ModelRegistry treats an unknown catalog apiKey string as literal outbound authentication. If Doctor rewrote a key to a profile ID before the runtime change, that profile ID could be sent as the bearer token, or an occupied default profile could silently select the wrong key.

The safe first stage therefore does exactly this:

  • Doctor scans configured providers, root models.json files, and SQLite plugin catalogs for every discovered, configured-default, and active override agent directory.
  • It copies credentials into the canonical per-agent auth-profile SQLite store under the existing write lock and reloads the committed store to verify the exact credential.
  • Global config credentials are stored once in shared-main and use an ID that no child-local store can shadow.
  • Occupied profiles, unreadable canonical stores, profile ordering, config bytes, root catalog bytes, and plugin catalog bytes are left unchanged.
  • Root catalog scanning shares ModelRegistry's existing comment/trailing-comma parser, so Doctor and runtime accept the same syntax.

No SQLite schema or protocol version changes are required. This writes existing auth-profile rows only.

The original combined rewrite was production +566/-73 and tests +290/-13. The first migration extraction was production +422/-0. After the split and cleanup pass, this PR is production +341/-8 and tests +249/-0. The remaining production growth is the Doctor-owned storage migration boundary; catalog serialization and runtime auth are no longer mixed into it.

User Impact

Running openclaw doctor --fix copies and verifies existing model credentials in SQLite without changing which credential current runtime uses. Existing config and catalogs remain byte-identical, so this stage cannot strand an operator between the old and new credential paths.

This PR alone does not stop future plaintext catalog writes and does not claim the exposure is fixed. The runtime-security follow-up must land after this migration; it will stop serialization, consume verified profile references, and delete catalog request-auth fallback with no runtime dual-read.

Evidence

Pre-fix direction: current main has no Doctor migration, so the regression suite fails because the migration module and SQLite copies do not exist.

Post-fix focused proof on current main base:

  • node scripts/run-vitest.mjs src/commands/doctor-model-catalog-credentials.test.ts src/agents/sessions/model-registry.test.ts src/flows/doctor-health-contributions.test.ts
    • Doctor contribution: 107/107 passed
    • credential migration: 5/5 passed
    • ModelRegistry/parser: 26/26 passed
    • total: 138 passed
  • node scripts/check-changed.mjs
    • Testbox tbx_01kznf0vkcw7kfz1rcmd7dnqzj
    • Actions run 31373394145
    • exitCode 0; formatting, Plugin SDK manifest, typecheck, lint, database-first, dead-code, import-cycle, and boundary guards passed
  • git diff --check passed.
  • Codex autoreview ran twice after the split and parser follow-up; both completed clean with no accepted/actionable findings.

ClawSweeper's prior findings are addressed by the split: config is not rewritten before discovery understands references, inherited main references are covered, and commented root catalogs use the runtime parser. The old runtime-auth and serialization rank-up moves belong to the ordered follow-up and are intentionally not hidden in this migration PR.

@steipete
steipete requested a review from a team as a code owner May 27, 2026 04:53
@openclaw-barnacle openclaw-barnacle Bot added agents Agent runtime and tooling size: S maintainer Maintainer-authored PR labels May 27, 2026
@clawsweeper

clawsweeper Bot commented May 27, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: found issues before merge. Reviewed August 10, 2026, 4:06 AM ET / 08:06 UTC.

ClawSweeper review

What this changes

Migrates plaintext root and plugin model-catalog credentials into per-agent SQLite profiles, rewrites catalogs to profile references, and removes catalog keys from model request configuration.

Merge readiness

⛔ Blocked by patch quality or review findings - 10 items remain

Keep open. Current main still permits catalog credentials, and this maintainer-owned rewrite addresses the earlier writer and outbound-auth gaps, but three concrete migration regressions block merge.

Priority: P1
Reviewed head: c1eb078786a8aaacd80f58475e4e2324f4431623

Review scores

Measure Result What it means
Overall readiness 🧂 unranked krab (1/6) The branch has a coherent goal but three P1 migration regressions make it unready to merge.
Proof confidence 🌊 off-meta tidepool Not applicable: Repository metadata identifies the author as a member, so the external-contributor proof gate does not apply; exact-head CI and focused migration regressions remain required.
Patch quality 🧂 unranked krab (1/6) Security review found an item that needs attention.

Verification

Check Result Evidence
Real behavior Not applicable Not applicable: Repository metadata identifies the author as a member, so the external-contributor proof gate does not apply; exact-head CI and focused migration regressions remain required.
Evidence reviewed 6 items Current main still has the reported behavior: The planner serializes final root and plugin provider configurations directly, and the model registry stores catalog provider configuration for request auth.
Existing test and docs define the legacy contract: Current tests expect a catalog-only key to be returned for request auth, while model documentation says a nonempty models.json apiKey wins in merge mode.
Migrated config references are passed to discovery as literals: The branch rewrites configured apiKey values to profile IDs, but the provider discovery resolver checks configured strings before profile credentials and returns the string as its discovery key.
Findings 3 actionable findings [P1] Resolve migrated config profile IDs during discovery
[P1] Preserve inherited profile references in worker catalogs
[P1] Parse root catalogs with the runtime's JSON-comment rules
Security Needs attention Commented root catalogs evade credential migration: The migration parses root models.json with raw JSON.parse even though the runtime accepts comments and trailing commas, leaving plaintext credentials in a supported catalog format.

How this fits together

Model catalog generation combines configured and discovered provider metadata into root and plugin catalogs. Doctor migrates persisted catalog state, while model execution should obtain credentials only from the canonical auth-profile store.

flowchart LR
  A[Provider config and catalogs] --> B[Doctor migration]
  B --> C[Agent SQLite auth profiles]
  B --> D[Sanitized model catalogs]
  D --> E[Model registry]
  C --> F[Provider discovery and requests]
  E --> F
Loading

Before merge

  • Resolve migrated config profile IDs during discovery (P1) - rewriteConfigCredentials writes a profile ID such as provider:config, but the discovery resolver checks the configured string before profiles and sends that ID as the discovery key. A migrated configured provider can therefore fail catalog discovery immediately after Doctor persists the config; resolve a valid profile reference before the literal-config path and add a Doctor-to-discovery regression.
  • Preserve inherited profile references in worker catalogs (P1) - This reads only the worker's local store, although runtime auth merges inherited main profiles and gives local entries precedence. A worker catalog reference backed only by main is treated as plaintext, then written locally as the literal profile ID, overriding the inherited real credential; scan effective inherited references or leave them untouched.
  • Parse root catalogs with the runtime's JSON-comment rules (P1) - ModelRegistry accepts comments and trailing commas in root models.json, but this raw JSON.parse only records a warning on the same valid file. Doctor then leaves its plaintext key in place, defeating the migration for a supported catalog format; share the runtime parser contract and cover a commented catalog.
  • Resolve security concern: Commented root catalogs evade credential migration - The migration parses root models.json with raw JSON.parse even though the runtime accepts comments and trailing commas, leaving plaintext credentials in a supported catalog format.
  • Resolve merge risk (P1) - Exact-head CI is still incomplete.
  • Resolve merge risk (P1) - The migration adds 493 net production lines on a compatibility-sensitive credential path; the repaired upgrade cases need focused proof before merge.
  • Complete next step (P2) - This protected, maintainer-owned PR needs its author or a maintainer to resolve the security-sensitive migration findings.
  • Improve patch quality - Repair the three migration paths in the review findings.
  • Improve patch quality - Add focused Doctor-to-discovery, inherited-worker, and commented-catalog regressions.
  • Improve patch quality - Wait for exact-head CI to complete.

Findings

  • [P1] Resolve migrated config profile IDs during discovery — src/commands/doctor-model-catalog-credentials.ts:249
  • [P1] Preserve inherited profile references in worker catalogs — src/commands/doctor-model-catalog-credentials.ts:260
  • [P1] Parse root catalogs with the runtime's JSON-comment rules — src/commands/doctor-model-catalog-credentials.ts:89
  • [high] Commented root catalogs evade credential migration — src/commands/doctor-model-catalog-credentials.ts:89
Agent review details

Security

Needs attention: A supported commented root catalog can bypass migration and retain plaintext credentials.

PR surface

Source +493, Tests +277. Total +770 across 10 files.

View PR surface stats
Area Files Added Removed Net
Source 5 566 73 +493
Tests 5 290 13 +277
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 10 856 86 +770

Review metrics

Metric Value Why it matters
Production vs test LOC production +493, tests +277 The new migration owner and persistence flow need proportionate compatibility and upgrade validation.

Stored data model

Persistent data-model change detected: migration/backfill/repair: src/commands/doctor-model-catalog-credentials.test.ts, migration/backfill/repair: src/commands/doctor-model-catalog-credentials.ts, migration/backfill/repair: src/flows/doctor-health-contributions.test.ts, migration/backfill/repair: src/flows/doctor-health-contributions.ts, serialized state: src/agents/models-config.plan.ts, serialized state: src/agents/models-config.skips-writing-models-json-no-env-token.test.ts, and 8 more. Confirm migration or upgrade compatibility proof before merge.

Root-cause cluster

Relationship: canonical
Canonical: #87166
Summary: This is the active maintainer-owned migration after several closed one-sided catalog-redaction proposals.

Members:

Proposal only: this assessment does not dispatch repair, suppress jobs, mutate sibling items, close, or merge anything.

Merge-risk options

Maintainer options:

  1. Repair migration compatibility before merge (recommended)
    Resolve profile IDs during discovery, retain inherited worker profile references, and cover comment-tolerant root catalog migration.
  2. Pause the migration rewrite
    Keep the PR open until the persisted credential reference format can preserve all current provider-discovery and worker-profile behavior.

Technical review

Best possible solution:

Keep Doctor as the sole migration owner, but resolve profile references during discovery, preserve inherited worker references, and parse root catalogs with the runtime’s established JSON-comment contract.

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

Yes. Source establishes focused reproductions for migrated config discovery, inherited worker profile references, and comment-tolerant root catalogs.

Is this the best way to solve the issue?

No. The Doctor-owned migration boundary is appropriate, but it must retain the established profile-resolution and catalog-parsing contracts.

Full review comments:

  • [P1] Resolve migrated config profile IDs during discovery — src/commands/doctor-model-catalog-credentials.ts:249
    rewriteConfigCredentials writes a profile ID such as provider:config, but the discovery resolver checks the configured string before profiles and sends that ID as the discovery key. A migrated configured provider can therefore fail catalog discovery immediately after Doctor persists the config; resolve a valid profile reference before the literal-config path and add a Doctor-to-discovery regression.
    Confidence: 0.99
  • [P1] Preserve inherited profile references in worker catalogs — src/commands/doctor-model-catalog-credentials.ts:260
    This reads only the worker's local store, although runtime auth merges inherited main profiles and gives local entries precedence. A worker catalog reference backed only by main is treated as plaintext, then written locally as the literal profile ID, overriding the inherited real credential; scan effective inherited references or leave them untouched.
    Confidence: 0.99
  • [P1] Parse root catalogs with the runtime's JSON-comment rules — src/commands/doctor-model-catalog-credentials.ts:89
    ModelRegistry accepts comments and trailing commas in root models.json, but this raw JSON.parse only records a warning on the same valid file. Doctor then leaves its plaintext key in place, defeating the migration for a supported catalog format; share the runtime parser contract and cover a commented catalog.
    Confidence: 0.99

Overall correctness: patch is incorrect
Overall confidence: 0.98

AGENTS.md: found and applied where relevant.

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

Labels

Label changes:

  • add rating: 🧂 unranked krab: Overall readiness is 🧂 unranked krab; proof is 🌊 off-meta tidepool and patch quality is 🧂 unranked krab.
  • add status: ⏳ waiting on author: ClawSweeper has contributor-facing work open and is waiting for author action. Not applicable: Repository metadata identifies the author as a member, so the external-contributor proof gate does not apply; exact-head CI and focused migration regressions remain required.
  • remove rating: 🦪 silver shellfish: Current PR rating is rating: 🧂 unranked krab, so this older rating label is no longer current.
  • remove status: 📣 needs proof: Current PR status label is status: ⏳ waiting on author.

Label justifications:

  • P1: The migration can immediately break provider discovery or worker-agent authentication for existing setups.
  • merge-risk: 🚨 compatibility: Doctor rewrites persisted catalogs and configured provider credentials into a new reference form.
  • merge-risk: 🚨 auth-provider: The patch changes how provider discovery and runtime request authentication select credentials.
  • merge-risk: 🚨 security-boundary: A skipped root-catalog migration can leave plaintext credentials in model-visible catalog state.
  • rating: 🧂 unranked krab: Overall readiness is 🧂 unranked krab; proof is 🌊 off-meta tidepool and patch quality is 🧂 unranked krab.
  • status: ⏳ waiting on author: ClawSweeper has contributor-facing work open and is waiting for author action. Not applicable: Repository metadata identifies the author as a member, so the external-contributor proof gate does not apply; exact-head CI and focused migration regressions remain required.

Evidence

Security concerns:

  • [high] Commented root catalogs evade credential migration — src/commands/doctor-model-catalog-credentials.ts:89
    The migration parses root models.json with raw JSON.parse even though the runtime accepts comments and trailing commas, leaving plaintext credentials in a supported catalog format.
    Confidence: 0.99

What I checked:

Likely related people:

  • steipete: Current-main blame and recent model-catalog lifecycle commits connect this author to the planner, registry, and auth-profile boundaries. (role: recent area contributor; confidence: high; commits: d6ee4c357015, 498a2caaf2e1, cc57514e680d; files: src/agents/models-config.plan.ts, src/agents/sessions/model-registry.ts, src/agents/plugin-model-catalog.ts)
  • Jason (Json): Recent generated-catalog repair and prepared-runtime work covers the SQLite catalog lifecycle affected by this migration. (role: adjacent catalog lifecycle contributor; confidence: medium; commits: c0c55a82fa83, a67ad03eea4b; files: src/agents/plugin-model-catalog.ts, src/agents/sessions/model-registry.ts)

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 (3 earlier review cycles)
  • reviewed 2026-06-24T18:57:48.794Z sha a088aa6 :: needs real behavior proof before merge. :: [P1] Sanitize plugin catalog writes too | [P1] Keep the config marker out of request auth
  • reviewed 2026-06-29T15:30:04.357Z sha a088aa6 :: needs real behavior proof before merge. :: [P1] Sanitize plugin catalog writes too | [P1] Keep the config marker out of request auth
  • reviewed 2026-07-31T11:15:21.297Z sha a088aa6 :: needs real behavior proof before merge. :: [P1] Sanitize every generated catalog writer | [P1] Keep the config marker out of request authentication

@steipete

Copy link
Copy Markdown
Contributor Author

We should pick this back up once the PI-removal work has merged. That will let us land the secret-preserving behavior against the new model registry path instead of carrying another PI compatibility shim here.

@clawsweeper clawsweeper Bot added proof: sufficient ClawSweeper judged the real behavior proof convincing. 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 May 27, 2026
@clawsweeper

clawsweeper Bot commented May 27, 2026

Copy link
Copy Markdown
Contributor

ClawSweeper PR egg

✨ Hatched: 🥚 common Moonlit Review Wisp

Hatch command

Comment @clawsweeper hatch when this PR is hatchable.

Hatchability rules:

  • Merged PRs are hatchable.
  • Open PRs are hatchable when they are status: 👀 ready for maintainer look, status: 🚀 automerge armed, or labeled clawsweeper:automerge.
  • Closed unmerged PRs are hatchable only when one of those hatchable labels is still present in the durable record.

Rarity: 🥚 common.
Trait: stacks clean commits.
Image traits: location branch lighthouse; accessory lint brush; palette rose quartz and slate; mood curious; pose guarding a tiny green check; shell glossy opal shell; lighting warm desk-lamp glow; background subtle branch markers.
Share on X: post this hatch
Copy: My PR egg hatched a 🥚 common Moonlit Review Wisp in ClawSweeper.

What is this egg doing here?
  • Eggs appear after the PR passes real-behavior proof. It is here for vibes, not verdicts: it does not change labels, ratings, merge decisions, or automation.
  • The shell reacts to review momentum: open follow-up work warms it up, re-review makes it wobble, and a clean final review lets it hatch.
  • Hatchability usually comes from sufficient real-behavior proof, no blocking P0/P1/P2 findings, no security attention needed, and clean correctness. A merged PR is already final, so merge makes the egg hatchable independently.
  • The hatch is seeded from this repository and PR number, so the same PR keeps the same creature; the reviewed head SHA can only change safe visual details.
  • Rarity is just collectible sparkle: 🥚 common, 🌱 uncommon, 💎 rare, ✨ glimmer, and 🌈 legendary.

@clawsweeper clawsweeper Bot added rating: 🌊 off-meta tidepool PR readiness rating does not apply to this item. and removed proof: sufficient ClawSweeper judged the real behavior proof convincing. 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 May 29, 2026
@clawsweeper clawsweeper Bot added rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. P1 High-priority user-facing bug, regression, or broken workflow. 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. merge-risk: 🚨 security-boundary 🚨 May affect sandboxing, authorization, credentials, or sensitive data. and removed rating: 🌊 off-meta tidepool PR readiness rating does not apply to this item. labels Jun 15, 2026
@clawsweeper clawsweeper Bot added the rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. label Jul 31, 2026
@steipete
steipete force-pushed the codex/pr-83294-models-json-api-key-marker branch from a088aa6 to 5b56f9c Compare August 10, 2026 07:25
@steipete steipete self-assigned this Aug 10, 2026
@openclaw-barnacle openclaw-barnacle Bot added commands Command implementations size: L and removed size: S labels Aug 10, 2026
@clawsweeper clawsweeper Bot added rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. and removed rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. labels Aug 10, 2026
@steipete
steipete force-pushed the codex/pr-83294-models-json-api-key-marker branch from c1eb078 to 031aae4 Compare August 10, 2026 09:25
@openclaw-barnacle openclaw-barnacle Bot removed the agents Agent runtime and tooling label Aug 10, 2026
@openclaw-barnacle openclaw-barnacle Bot added the agents Agent runtime and tooling label Aug 10, 2026
@steipete steipete changed the title fix(models): strip plaintext api keys from models json fix(models): migrate catalog credentials into SQLite Aug 10, 2026
@steipete

Copy link
Copy Markdown
Contributor Author

@clawsweeper re-review

The PR has been split to the copy-only SQLite migration stage. It no longer rewrites config/catalog bytes or changes runtime authentication. The inherited-profile and comment-tolerant root-catalog findings now have focused regressions; the runtime serialization/auth boundary will land as the ordered follow-up.

@clawsweeper

clawsweeper Bot commented Aug 10, 2026

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

Command router queued. I will update this comment with the next step.

@steipete
steipete merged commit fe9bd75 into main Aug 10, 2026
130 checks passed
@steipete
steipete deleted the codex/pr-83294-models-json-api-key-marker branch August 10, 2026 09:47
@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. P1 High-priority user-facing bug, regression, or broken workflow. rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. size: L status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants