Skip to content

fix(doctor): prevent catalog imports beside stored SecretRefs - #179802

Merged
steipete merged 1 commit into
mainfrom
upd/upd-l1779
Oct 21, 2026
Merged

steipete merged 1 commit into
mainfrom
upd/upd-l1779

Conversation

@steipete

Copy link
Copy Markdown
Contributor

What Problem This Solves

Fixes: openclaw doctor --fix can copy a stale plaintext model-catalog key into a new auth profile even when that provider already has an API-key or token SecretRef in its effective auth store.

Supersedes #179195, thanks @ensignwesley.

User Impact

Doctor and update-time Doctor leave stored SecretRefs authoritative over generated catalog credentials, including references inherited by child agents. Explicit literal keys in models.providers still migrate, even beside an expired token reference. Existing references, source catalogs, and unrelated credentials remain intact; no configuration or schema changes are required.

Why This Change Was Made

The migration distinguished config-level references but missed stored references. Catalog candidates now retain their source, and the locked writer rechecks the current effective store before importing them. It uses the auth writer's existing shared-store view, removing the stale caller-supplied snapshot and its extra read. The single-use env-marker predicate is folded into its owner. Production delta: +38/-39 (net -1); tests +89; docs +2.

This also addresses the useful finding on the original PR: a provider-wide guard must not discard an independently configured literal credential. Release-note context: Doctor no longer creates competing plaintext profiles from generated model catalogs beside stored SecretRefs; explicit configured credentials still migrate. Thanks @ensignwesley (#179195).

Evidence

  • On unchanged main 8940c8134ad9, five new cases failed because a stale catalog credential was imported. The real built CLI reproduced the defect: doctor --fix --non-interactive reported one copied credential, and SQLite contained the original SecretRef plus custom:models-json.
  • The fixed real CLI preserved the SecretRef and produced zero plaintext profiles. The positive control imported an explicit configured key while leaving the stale catalog key absent. All fixture credentials and endpoints were synthetic; every invocation used a worktree-local HOME, OPENCLAW_STATE_DIR, and temporary directory.
  • Installed published stable [email protected], used its real Doctor to import a legacy SecretRef, then added a stale generated catalog and ran the candidate Doctor on that state. Both exited successfully; the candidate retained only the reference profile. Normal missing-feature/setup warnings remained nonblocking. Original-state capture reported the host volume's staging-ancestor permissions; these were disposable synthetic states containing no operator data.
  • Node importing-consumer tests: 128 passed across all five importing test files (206.46 s wall time across three wrapper-selected shards). Focused Bun suite: 13 passed, 40.07 s total / about 5.2 s test time; the earlier focused Node run passed 12 tests before adding local-child coverage (30.35 s total / about 7.3 s test time). The final Node owner file ran 13 tests in 6.65 s of test time. Compiler preparation accounts for most focused-run wall time. Existing retained-agent and deletion-journal consumer files took 72.20 s and 67.34 s of test time, respectively; no individual test exceeded 30 s.
  • Core and Doctor-test tsgo, scoped oxlint, oxfmt, git diff --check, and Madge passed (zero cycles). Line-cap, assertion, SQLite dialect, test-timeout, mock-export, and Doctor-deprecation checks passed.
  • Full check:changed was replaced by the scoped checks above under the local gate budget. The separate database-worker inventory was stopped after roughly 80 s without output. The max-lines check reports inherited suppressions in unchanged ui/src/pages/chat/components/chat-message.test.tsx, ui/src/pages/config/config-page-state.ts, and ui/src/pages/sessions/sessions-page-state.ts; those files match the untouched base. PR CI supplies broad proof.
  • Independent Codex review was attempted, but the helper refused its resolved shared-scratch temporary directory after TMP overrides were unset. No isolation guard was bypassed; lead review of this head remains necessary.

The importing-consumer command was OPENCLAW_VITEST_RUNTIME=node node scripts/run-vitest.mjs src/infra/state-migrations.retained-deleted-agent.test.ts src/flows/doctor-health-contributions.auth-import-order.test.ts src/flows/doctor-health-contributions.test.ts src/commands/doctor-model-catalog-credentials.test.ts src/commands/doctor-agent-deletion-journal.test.ts --maxWorkers=1. Other focused commands included OPENCLAW_VITEST_RUNTIME=bun node scripts/run-vitest.mjs src/commands/doctor-model-catalog-credentials.test.ts --maxWorkers=1, node scripts/run-tsgo.mjs -p tsconfig.core.json --incremental, node scripts/run-tsgo.mjs -p test/tsconfig/tsconfig.core.test.commands-doctor.json --incremental, and node --import ./scripts/tsx.mjs scripts/check-madge-import-cycles.ts. Live proof ran node openclaw.mjs doctor --fix --non-interactive and pnpm dev doctor --fix --non-interactive with isolated environment paths.

Preserve stored API-key and token references when importing generated model
catalog credentials, including inherited references and changes during the
repair prompt. Keep explicit configured literal credentials eligible for
migration and use the auth writer's current shared-store view.

Supersedes #179195; thanks @ensignwesley.

Co-authored-by: Wesley <[email protected]>
@clawsweeper

clawsweeper Bot commented Oct 21, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

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

ClawSweeper review in progress

ClawSweeper is reviewing this revision. This supersedes any previous blocked status.

View the workflow run.

@steipete
steipete marked this pull request as ready for review October 21, 2026 18:58
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 21, 2026 •

Copy link
Copy Markdown
Contributor

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-21T19:06:55.342186Z 554084e Draft marked ready
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@openclaw-barnacle openclaw-barnacle Bot added docs Improvements or additions to documentation gateway Gateway runtime commands Command implementations size: S labels Oct 21, 2026

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 554084ee59

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment on lines +193 to +195
inheritedStore = sharedStore;
const effectiveStore = sharedStore
? mergeAuthProfileStores(sharedStore, localStore)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Preserve the relocated shared-store environment

When params.env.OPENCLAW_AGENT_DIR relocates a legacy shared auth store and a SecretRef is added while the repair prompt is pending, this locked recheck reads the wrong shared store: only stateDir is passed to updateAuthProfileStoreWithLock, and its write preparation explicitly clears OPENCLAW_AGENT_DIR. Consequently sharedStore points at the default main-agent path, so a child catalog can still import the stale plaintext key beside the newly added reference. Pass the complete supplied environment through the locked writer (or otherwise resolve the shared owner from it) before using this view.

Useful? React with 👍 / 👎.

@clawsweeper clawsweeper Bot added the clawsweeper:intake:bug Preliminary submission classification; full source review pending. label Oct 21, 2026
@steipete

Copy link
Copy Markdown
Contributor Author

Landing despite one red job: checks-ui-e2e (1/2). It fails the Control UI boot-module-boundaries e2e test, which this PR doesn't touch; the PR changes no ui/ files. All non-UI checks are green.

@steipete
steipete merged commit 3f016b1 into main Oct 21, 2026
190 of 196 checks passed
@steipete
steipete deleted the upd/upd-l1779 branch October 21, 2026 19:27
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Oct 22, 2026
…efs (openclaw#179802)

Doctor guarded config-level SecretRefs but not references stored in the auth store, so it could write plaintext model credentials beside them. Generated catalog credentials are now checked against the auth writer's effective store; explicitly configured keys still migrate. Supersedes openclaw#179195, thanks @ensignwesley.

Co-authored-by: Wesley <[email protected]>
RomneyDa added a commit that referenced this pull request Nov 10, 2026
…efs (#179802)

Doctor guarded config-level SecretRefs but not references stored in the auth store, so it could write plaintext model credentials beside them. Generated catalog credentials are now checked against the auth writer's effective store; explicitly configured keys still migrate. Supersedes #179195, thanks @ensignwesley.

Backport the bounded catalog-only repair for 2026.11.4. Preserve the existing provider env-marker helper and stable UTF-8 handling. Add real Doctor auth-phase regression coverage for shared and local references installed during confirmation.

(cherry picked from commit 3f016b1)

Co-authored-by: Wesley <[email protected]>
Co-authored-by: RomneyDa <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

clawsweeper:intake:bug Preliminary submission classification; full source review pending. commands Command implementations docs Improvements or additions to documentation gateway Gateway runtime size: S

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant