Skip to content

fix: normalize provider keys during model config merge - #95722

Merged
steipete merged 6 commits into
openclaw:mainfrom
Pick-cat:fix-provider-key-case-merge
Jul 16, 2026
Merged

steipete merged 6 commits into
openclaw:mainfrom
Pick-cat:fix-provider-key-case-merge

Conversation

@Pick-cat

@Pick-cat Pick-cat commented Jun 22, 2026 •

Copy link
Copy Markdown
Contributor

What Problem This Solves

Fixes a model config merge bug where provider map keys were only trimmed, not normalized as provider ids. If generated/catalog providers used openai and user config or existing models.json entries used OpenAI, merge planning could produce duplicate provider entries or fail to preserve existing secrets onto the canonical provider.

ClawSweeper review correctly flagged a paired issue at the secret-boundary: after canonicalizing keys in mergeProviders, the source-managed marker enforcement (enforceSourceManagedProviderSecrets) was still doing a trim-only lookup against the original source provider key. That meant a sourceConfigForSecrets keyed as OpenAI would miss the now-canonical openai generated entry, the SecretRef marker would not be reapplied, and the resolved runtime apiKey could be written to models.json as plaintext. The follow-up closes that gap and moves every provider-map collision through one canonical helper.

Why This Change Was Made

Provider ids are canonicalized by trimming and lowercasing. Generated, explicit, existing-secret, and source-managed provider maps now share one collision contract:

  • Exact canonical spelling wins regardless of insertion order.
  • If no exact canonical spelling exists, the later variant wins, matching the existing trim-collision behavior.
  • Invalid source entries are filtered before collision resolution, so malformed canonical data cannot suppress a valid alias.

This keeps SecretRefs attached to the canonical provider while making mixed-case collision behavior deterministic.

User Impact

  • Users with mixed-case provider keys in models.providers or existing models.json no longer get duplicate provider entries in generated model config. Explicit settings and preserved local secrets merge into the canonical provider id.
  • Mixed-case SecretRef source configs (models.providers.OpenAI with { source: "env", id: "OPENAI_API_KEY" }) now correctly project back to the canonical openai generated entry as the env marker "OPENAI_API_KEY" instead of the resolved runtime secret value.
  • Configs containing both canonical and mixed-case spellings get stable results independent of object order.

Evidence

Real plan-level proof (planOpenClawModelsJsonWithDeps) for a mixed-case sourceConfigForSecrets (models.providers.OpenAI = { apiKey: { source: "env", id: "OPENAI_API_KEY" } }) against a runtime config whose apiKey has already been resolved to sk-runtime-resolved.

Before this PR (trim-only lookup) — runtime secret leaks into generated models.json:

{
  "providers": {
    "openai": {
      "baseUrl": "https://api.openai.com/v1",
      "apiKey": "sk-runtime-resolved",
      "api": "openai-completions",
      "models": []
    }
  }
}

After this PR — source SecretRef env marker is reapplied:

{
  "providers": {
    "openai": {
      "baseUrl": "https://api.openai.com/v1",
      "apiKey": "OPENAI_API_KEY",
      "api": "openai-completions",
      "models": []
    }
  }
}

Both snapshots use synthetic non-secret values.

Regression proof on Linux Node 24, AWS Crabbox run run_cd25bdec60f7:

  • Scoped format check passed.
  • src/agents/models-config.merge.test.ts: 21/21 passed, including canonical-before-alias, alias-before-canonical, alias-only, and existing SecretRef collisions.
  • src/agents/models-config.runtime-source-snapshot.test.ts: 11/11 passed, including both key orders and malformed canonical source data with a valid alias.
  • Autoreview clean after fixing its accepted malformed-source collision finding.
  • git diff --check clean.

@openclaw-barnacle openclaw-barnacle Bot added agents Agent runtime and tooling size: XS labels Jun 22, 2026
@Pick-cat
Pick-cat force-pushed the fix-provider-key-case-merge branch from 0fa59d9 to 8e497a5 Compare June 22, 2026 10:29
@clawsweeper

clawsweeper Bot commented Jun 23, 2026 •

Copy link
Copy Markdown
Contributor

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

Summary
The PR canonicalizes provider-map keys across generated model-config merging, existing-secret preservation, and source-managed secret-marker reapplication, with mixed-case collision regressions.

PR surface: Source +27, Tests +240. Total +267 across 5 files.

Reproducibility: yes. A high-confidence source and planner path uses models.providers.OpenAI as the source SecretRef configuration with a canonical openai runtime provider; the old trim-only lookup misses the marker and can plan the resolved runtime key for serialization.

Review metrics: 1 noteworthy metric.

  • Normalized merge boundaries: 3 boundaries unified. Generated-provider merging, persisted-secret merging, and source-managed marker enforcement now use one provider-key collision contract.

Merge readiness
Overall: 🦞 diamond lobster
Proof: 🦞 diamond lobster
Patch quality: 🦞 diamond lobster
Result: ready for maintainer review.

Overall follows the weaker of proof and patch quality, so missing proof can cap an otherwise strong patch.

Risk before merge

  • [P1] Existing configurations containing both canonical and mixed-case spellings will collapse to one provider entry; exact canonical spelling intentionally wins even if object insertion order previously selected another value.
  • [P1] The changed path controls provider credentials and SecretRef projection into generated models.json; a regression could select the wrong credential source or persist a resolved secret, although the added coverage materially reduces that risk.
  • [P1] The current head is behind main and has one failing Node shard, so the final three-way result and failure cause have not yet been validated on an up-to-date exact head.

Maintainer options:

  1. Refresh and validate the exact head (recommended)
    Rebase onto current main, rerun the failing Node shard, and merge if the failure is resolved or proven unrelated while the focused provider and SecretRef regressions remain green.
  2. Pause for duplicate-key compatibility sampling
    Hold the PR if maintainers want additional evidence from real configurations containing both canonical and mixed-case provider keys before adopting canonical-spelling precedence.

Next step before merge

  • [P2] A maintainer should refresh the branch, inspect or rerun the single failing Node shard on the rebased exact head, and merge if the focused provider-key and SecretRef coverage remains green; no narrow code defect is currently available for an automated repair.

Security
Cleared: The patch adds no dependency, permission, network, workflow, or execution surface and strengthens the existing SecretRef persistence boundary with focused plaintext-leak regressions.

Review details

Best possible solution:

Keep one shared provider-key normalizer at all generated-model merge and secret-marker boundaries, preserve the maintainer-defined canonical-spelling precedence, and land only after rebasing and clearing the exact-head failing shard without weakening the focused collision and secret-leak regressions.

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

Yes. A high-confidence source and planner path uses models.providers.OpenAI as the source SecretRef configuration with a canonical openai runtime provider; the old trim-only lookup misses the marker and can plan the resolved runtime key for serialization.

Is this the best way to solve the issue?

Yes. Sharing the established provider-id normalizer across all relevant map boundaries is narrower and safer than adding case-specific fallbacks, and the latest maintainer-authored commit explicitly defines the ambiguous collision precedence.

AGENTS.md: found and applied where relevant.

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

Label changes

Label justifications:

  • P1: The defect can duplicate or mis-associate provider configuration and can expose a resolved provider credential in generated models.json for affected mixed-case configurations.
  • merge-risk: 🚨 compatibility: Merging changes how existing duplicate case-variant provider keys collapse and which entry wins during upgrades or regeneration.
  • merge-risk: 🚨 auth-provider: Provider identity normalization directly affects which API-key, headers, models, and existing persisted credentials are associated with a configured provider.
  • merge-risk: 🚨 security-boundary: The source-managed lookup governs whether a non-secret SecretRef marker or a resolved runtime credential is written to generated configuration.
  • rating: 🦞 diamond lobster: Overall readiness is 🦞 diamond lobster; proof is 🦞 diamond lobster and patch quality is 🦞 diamond lobster.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Sufficient (live_output): Synthetic but production-path before/after planner output demonstrates the observable secret-marker correction, backed by a Linux Node 24 Crabbox run and focused collision tests; no private credential was used.
  • proof: sufficient: Contributor real behavior proof is sufficient. Synthetic but production-path before/after planner output demonstrates the observable secret-marker correction, backed by a Linux Node 24 Crabbox run and focused collision tests; no private credential was used.
Evidence reviewed

PR surface:

Source +27, Tests +240. Total +267 across 5 files.

View PR surface stats
Area Files Added Removed Net
Source 3 47 20 +27
Tests 2 240 0 +240
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 5 287 20 +267

What I checked:

Likely related people:

  • steipete: Assigned the PR and authored the latest commit defining exact canonical spelling precedence for provider-key collisions. (role: recent area contributor and collision-policy author; confidence: high; commits: b9f00c9b4ffb; files: src/agents/models-config.providers.keys.ts, src/agents/models-config.merge.test.ts, src/agents/models-config.runtime-source-snapshot.test.ts)
  • BigUncle: Previously implemented normalized provider-key merge and base-URL precedence behavior in the same generated models-config area, making them relevant for compatibility context. (role: adjacent feature contributor; confidence: medium; commits: c06014dca56b; files: src/agents/models-config.merge.ts, src/agents/models-config.merge.test.ts)
What the crustacean ranks mean
  • 🦀 challenger crab: rare, exceptional readiness with strong proof, clean implementation, and convincing validation.
  • 🦞 diamond lobster: very strong readiness with only minor maintainer review expected.
  • 🐚 platinum hermit: good normal PR, likely mergeable with ordinary maintainer review.
  • 🦐 gold shrimp: useful signal, but proof or patch confidence is still limited.
  • 🦪 silver shellfish: thin signal; proof, validation, or implementation needs work.
  • 🧂 unranked krab: not merge-ready because proof is missing/unusable or there are serious correctness or safety concerns.
  • 🌊 off-meta tidepool: rating does not apply to this item.

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.

How this review workflow works
  • 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.
Review history (3 earlier review cycles)
  • reviewed 2026-06-27T10:01:23.693Z sha 8efe396e41b0787983ebda2a13557639419f6c02 :: needs maintainer review before merge. :: none
  • reviewed 2026-07-12T04:52:48.829Z sha 8efe396e41b0787983ebda2a13557639419f6c02 :: needs maintainer review before merge. :: none
  • reviewed 2026-07-16T07:02:15.418Z sha b9f00c9 :: needs maintainer review before merge. :: none

@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. 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. and removed 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. labels Jun 23, 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. 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 Jun 27, 2026
@Pick-cat

Copy link
Copy Markdown
Contributor Author

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Jun 27, 2026 •

Copy link
Copy Markdown
Contributor

🦞🧹
ClawSweeper re-review requested.

I asked ClawSweeper to review this item again.
Action: item re-review queued (workflow sweep.yml, event repository_dispatch).
Result: the existing ClawSweeper review comment will be edited in place when the review finishes.

Re-review progress:

@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. and removed 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. labels Jun 27, 2026
@openclaw-barnacle

Copy link
Copy Markdown

This pull request has been automatically marked as stale due to inactivity.
Please add updates or it will be closed.

@openclaw-barnacle openclaw-barnacle Bot added the stale Marked as stale due to inactivity label Jul 12, 2026
@Pick-cat

Copy link
Copy Markdown
Contributor Author

@clawsweeper re-review

@clawsweeper clawsweeper Bot added rating: 🦞 diamond lobster Very strong PR readiness with only minor maintainer review expected. and removed rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. labels Jul 12, 2026
@openclaw-barnacle openclaw-barnacle Bot removed the stale Marked as stale due to inactivity label Jul 12, 2026
@Pick-cat
Pick-cat force-pushed the fix-provider-key-case-merge branch 2 times, most recently from 99b3503 to 5c5c9a5 Compare July 15, 2026 13:02
Pick-cat added 4 commits July 15, 2026 21:07
…rkers

Make enforceSourceManagedProviderSecrets canonicalize provider keys with
normalizeProviderId so mixed-case (e.g. "OpenAI") source config still matches
the canonical "openai" generated provider. Without this, the trim-only source
lookup misses, the source SecretRef marker is never reapplied, and resolved
runtime secret values leak into generated models.json.

Adds plan-level regressions in models-config.runtime-source-snapshot.test.ts
covering mixed-case apiKey and header source configs.
oxlint(no-array-sort) flagged the new test assertions for using
.sort() on Object.keys(...). Switch to .toSorted() to keep the
check-lint shard green.
@steipete
steipete merged commit 60040d8 into openclaw:main Jul 16, 2026
115 checks passed
@steipete

Copy link
Copy Markdown
Contributor

Merged via squash.

github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Jul 17, 2026
* fix: normalize provider keys during model config merge

* fix: normalize source-managed provider keys when reapplying secret markers

Make enforceSourceManagedProviderSecrets canonicalize provider keys with
normalizeProviderId so mixed-case (e.g. "OpenAI") source config still matches
the canonical "openai" generated provider. Without this, the trim-only source
lookup misses, the source SecretRef marker is never reapplied, and resolved
runtime secret values leak into generated models.json.

Adds plan-level regressions in models-config.runtime-source-snapshot.test.ts
covering mixed-case apiKey and header source configs.

* fix: use Array#toSorted in mixed-case provider regression tests

oxlint(no-array-sort) flagged the new test assertions for using
.sort() on Object.keys(...). Switch to .toSorted() to keep the
check-lint shard green.

* style(agents): oxfmt models-config provider merge files

* fix(agents): define provider key collision precedence

---------

Co-authored-by: Peter Steinberger <[email protected]>
Co-authored-by: Peter Steinberger <[email protected]>
zooqueen pushed a commit to zooqueen/openclaw that referenced this pull request Sep 11, 2026
* fix: normalize provider keys during model config merge

* fix: normalize source-managed provider keys when reapplying secret markers

Make enforceSourceManagedProviderSecrets canonicalize provider keys with
normalizeProviderId so mixed-case (e.g. "OpenAI") source config still matches
the canonical "openai" generated provider. Without this, the trim-only source
lookup misses, the source SecretRef marker is never reapplied, and resolved
runtime secret values leak into generated models.json.

Adds plan-level regressions in models-config.runtime-source-snapshot.test.ts
covering mixed-case apiKey and header source configs.

* fix: use Array#toSorted in mixed-case provider regression tests

oxlint(no-array-sort) flagged the new test assertions for using
.sort() on Object.keys(...). Switch to .toSorted() to keep the
check-lint shard green.

* style(agents): oxfmt models-config provider merge files

* fix(agents): define provider key collision precedence

---------

Co-authored-by: Peter Steinberger <[email protected]>
Co-authored-by: Peter Steinberger <[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 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. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🦞 diamond lobster Very strong PR readiness with only minor 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.

2 participants