models-config: apply config env vars before implicit provider discovery#32295
Conversation
Greptile SummaryThis PR fixes a bug where Bedrock (and other implicit provider) discovery silently failed when AWS credentials were configured via Changes:
Confidence Score: 5/5
Last reviewed commit: 1a51276 |
1a51276 to
b53b0c1
Compare
|
Landed via temp rebase onto main.
Thanks @hsiaoa! |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: b53b0c1799
ℹ️ 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".
| // available in process.env before implicit provider discovery. Some | ||
| // callers (agent runner, tools) pass config objects that haven't gone | ||
| // through the full loadConfig() pipeline which applies these. | ||
| applyConfigEnvVars(cfg); |
There was a problem hiding this comment.
Apply config env vars before resolving agentDir
Calling applyConfigEnvVars(cfg) after agentDir is computed means configs that set env.vars.OPENCLAW_AGENT_DIR (or PI_CODING_AGENT_DIR) are applied too late: ensureOpenClawModelsJson writes models.json to the pre-env directory, then mutates process.env to a different directory. In flows that re-resolve the agent dir after this call (for example loadModelCatalog in src/agents/model-catalog.ts), discovery can read from a different path than the one just written, so configured/implicit models may appear missing when the config object is passed directly (not via loadConfig()).
Useful? React with 👍 / 👎.
Summary
Fixes #32290.
ensureOpenClawModelsJson()callsresolveImplicitBedrockProvider()which checks for AWS credentials inprocess.env(e.g.AWS_PROFILE,AWS_ACCESS_KEY_ID). However, some callers (agent runner, tools, compaction) pass config objects that haven't gone through the fullloadConfig()pipeline — meaning config-defined env vars fromopenclaw.jsonenv.varsare never applied toprocess.envbefore discovery runs.This causes Bedrock discovery to silently fail or skip when AWS credentials are only configured via
openclaw.jsonenv.varsrather than being present in the host shell environment.The fix calls
applyConfigEnvVars(cfg)at the top ofensureOpenClawModelsJsonbefore any implicit provider discovery. This is idempotent (only sets vars not already present inprocess.env) and matches the existing pattern used inloadConfig().Test plan
models-configtests pass (68/68)config.env-varstests pass (6/6)AWS_PROFILEonly inopenclaw.jsonenv.vars, verifyopenclaw statusshows Bedrock models discovered