fix(models-config): let config baseUrl/apiKey override agent models.json in merge mode#37331
fix(models-config): let config baseUrl/apiKey override agent models.json in merge mode#37331maweibin wants to merge 2 commits intoopenclaw:mainfrom
Conversation
Greptile SummaryThis PR correctly fixes issue #37309 by inverting the precedence in merge mode so that config values take priority when non-empty. The fix:
Testing:
Documentation:
The change is minimal, surgical, and safe to merge. Confidence Score: 5/5
Last reviewed commit: 25bbfcc |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 25bbfcc801
ℹ️ About Codex in GitHub
Codex has been enabled to automatically 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 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
| const configHasApiKey = | ||
| typeof (newEntry as { apiKey?: string }).apiKey === "string" && | ||
| (newEntry as { apiKey?: string }).apiKey !== ""; | ||
| const configHasBaseUrl = | ||
| typeof (newEntry as { baseUrl?: string }).baseUrl === "string" && |
There was a problem hiding this comment.
Distinguish implicit providers from config overrides
In merge mode this check treats any non-empty newEntry.apiKey/baseUrl as a config override, but newEntry is built from both explicit config and implicitly discovered providers (resolveProvidersForModelsJson merges them first). That means providers discovered from env/profile now overwrite existing models.json secrets/endpoints even when the user omitted that provider in openclaw.json, which regresses the documented "config omits => preserve existing" behavior and can reset persisted custom endpoints/tokens on restart.
Useful? React with 👍 / 👎.
|
@gumadeiras can help me review this pr,thanks |
|
Closing this PR because the author has more than 10 active PRs in this repo. Please reduce the active PR queue and reopen or resubmit once it is back under the limit. You can close your own PRs to get back under the limit. |
Fixes #37309
Problem
In
models.mode: "merge", updatingbaseUrl(orapiKey) inopenclaw.jsonand restarting the gateway had no effect: the agent kept using the values stored in.openclaw/agent/.../models.json. Users had to manually edit the hiddenmodels.jsonto correct a wrong URL.Cause
mergeWithExistingProviderSecretsalways preserved non-emptyapiKey/baseUrlfrom the existing agentmodels.json, overwriting the values coming from config, so config was never able to override once agent state existed.Solution
In merge mode, only preserve agent
apiKey/baseUrlwhen config does not provide a non-empty value. When config provides a non-emptybaseUrlorapiKey, config wins. Thus:openclaw.jsonand restarting takes effect.Changes
mergeWithExistingProviderSecrets, preserve existingapiKey/baseUrlonly when the corresponding value from config is missing or empty.models.modehelp text to describe the new merge behavior.Testing
pnpm test -- src/agents/models-config --run(71 tests) passes.