fix: add catalog validation to models set command#18129
fix: add catalog validation to models set command#18129steipete merged 1 commit intoopenclaw:mainfrom
models set command#18129Conversation
`models set` accepts any syntactically valid model ID without checking
the catalog, allowing typos to silently persist in config and fail at
runtime. It also unconditionally adds an empty `{}` entry to
`agents.defaults.models`, bypassing any provider routing constraints.
This commit:
- Validates the model ID against the catalog (skipped when catalog is
empty during initial setup)
- Warns when a new entry is added with empty config (no provider routing)
Closes openclaw#17183
✍️ Author: Claude Code with @carrotRakko (AI-written, human-approved)
| } | ||
|
|
||
| // 3. Track whether this is a new entry | ||
| const isNewEntry = !cfg.agents?.defaults?.models?.[key]; |
There was a problem hiding this comment.
The isNewEntry check uses the first config snapshot (cfg), but updateConfig reads the config again internally. If the config file changes between these two reads, isNewEntry could be incorrect. While unlikely in typical CLI usage, this could be avoided by checking isNewEntry after the update using the updated config returned from updateConfig.
Prompt To Fix With AI
This is a comment left during a code review.
Path: src/commands/models/set.ts
Line: 31:31
Comment:
The `isNewEntry` check uses the first config snapshot (`cfg`), but `updateConfig` reads the config again internally. If the config file changes between these two reads, `isNewEntry` could be incorrect. While unlikely in typical CLI usage, this could be avoided by checking `isNewEntry` after the update using the `updated` config returned from `updateConfig`.
How can I resolve this? If you propose a fix, please make it concise.| const resolved = resolveModelTarget({ raw: modelRaw, cfg }); | ||
| const key = `${resolved.provider}/${resolved.model}`; |
There was a problem hiding this comment.
Resolved model target at line 16, which is then resolved again inside applyDefaultModelPrimaryUpdate (shared.ts:177)
Prompt To Fix With AI
This is a comment left during a code review.
Path: src/commands/models/set.ts
Line: 16:17
Comment:
Resolved model target at line 16, which is then resolved again inside `applyDefaultModelPrimaryUpdate` (shared.ts:177)
How can I resolve this? If you propose a fix, please make it concise.|
@steipete @sebslight Could you clarify what "accidental merge" means here?
The revert comment says "reverting to restore previous behavior" but doesn't explain what was wrong with the new behavior. If there's a specific concern, I'd like to address it and resubmit. The underlying issue (#17183 — ✍️ Author: Claude Code with @carrotRakko (AI-written, human-approved) |
Summary
models setaccepts any string as model ID — typos silently persist in config and fail at runtime with "Unknown model"{}entries bypass provider routing constraints configured for other models/modelchat command,models list, or the allowlist/routing logic itselfChange Type (select all)
Scope (select all touched areas)
Linked Issue/PR
User-visible / Behavior Changes
openclaw models set <invalid-model>now exits with an error:Unknown model: <id>(previously succeeded silently)openclaw models set <valid-model-without-config>now prints a warning before applying (previously silent)Security Impact (required)
NoNoNoNoNoRepro + Verification
Environment
agents.defaults.modelswith provider routing entriesSteps
openclaw models set openrouter/nonexistent/fake-model-v99openclaw models set openrouter/openai/gpt-4o(valid model not in config)Expected
Actual
Evidence
Before:
After:
Human Verification (required)
--forceor--skip-validationflags (none exist)Compatibility / Migration
Yes— existing valid configurations are unaffectedNoNoFailure Recovery (if this breaks)
src/commands/models/set.tsRisks and Mitigations
models setto be rejected✍️ Author: Claude Code with @carrotRakko (AI-written, human-approved)
Greptile Summary
Added validation to reject invalid model IDs in
models setcommand by checking against the catalog loaded fromloadModelCatalog. The validation is skipped when the catalog is empty to allow initial setup scenarios. The implementation also warns when adding models that don't have existing config entries.The change prevents typos from being silently persisted in config by validating model IDs against the catalog before applying updates. The warning for new entries helps users understand when models are being added without explicit provider routing configuration.
Confidence Score: 4/5
loadModelCatalogto verify the validation behavior insrc/commands/models.set.e2e.test.tsLast reviewed commit: 11aab35