#16104: fix: implement model aliases for /model command
stale
size: S
trusted-contributor
Cluster:
Model Alias Fixes
## Summary
Adds support for a top-level `aliases` config key as a convenience alternative to `agents.defaults.models.*.alias`. This allows users to define model shortcuts in a more intuitive format.
## Changes
- Added `aliases` property to `OpenClawConfig` type
- Added legacy migration to convert top-level `aliases` to `agents.defaults.models.*.alias`
- Added legacy rule for deprecation warning
- Added unit tests for the new migration
## Testing
- All 382 existing tests pass
- Added 5 new tests specifically for the aliases migration
- Build completes successfully
## Example Usage
Users can now define aliases like:
```json
{
"aliases": {
"fast": "ollama/minimax-m2.5:cloud",
"deep": "ollama/kimi-k2.5:cloud"
}
}
```
Then use `/model fast` instead of `/model ollama/minimax-m2.5:cloud`.
The aliases are automatically migrated to the internal format on load, so the existing implementation continues to work.
Fixes openclaw/openclaw#16074
<!-- greptile_comment -->
<h3>Greptile Summary</h3>
This PR adds a top-level `aliases` config key as a shorthand for defining model aliases, which are then auto-migrated to the canonical `agents.defaults.models.*.alias` format on config load. The implementation includes a new legacy migration, a deprecation rule, a type definition update, and thorough tests.
- The migration correctly handles existing aliases (no overwrite), invalid values (non-string/empty), and preserves surrounding config.
- One edge case: the migration reports a change and deletes `raw.aliases` even when **all** entries are invalid, causing an unnecessary config rewrite. A `migrated` flag would fix this.
- Test coverage is solid with 5 new cases covering the happy path, conflict preservation, empty input, invalid values, and config preservation.
<h3>Confidence Score: 4/5</h3>
- This PR is safe to merge with low risk; the flagged edge case only causes a spurious no-op config rewrite, not data loss.
- The migration logic is straightforward and follows established patterns in the codebase. The one issue found (reporting a change when all entries are invalid) is a minor correctness bug that won't cause data loss — it just triggers an unnecessary config file rewrite. Tests are thorough but miss this specific edge case.
- `src/config/legacy.migrations.part-2.ts` — the aliases migration has an edge case where all-invalid entries still trigger a config rewrite.
<sub>Last reviewed commit: 7e590eb</sub>
<!-- greptile_other_comments_section -->
<!-- /greptile_comment -->
Most Similar PRs
#20080: fix: resolve model aliases correctly when keyed by short name
by kamal-ayman · 2026-02-18
80.1%
#8252: Config: honor legacy memorySearch alias
by sauerdaniel · 2026-02-03
77.4%
#20049: fix(model-selection): resolve short-name alias keys correctly
by widingmarcus-cyber · 2026-02-18
76.1%
#17560: fix: Anthropic Prompt Caching Not Working - Missing cache_control H...
by MisterGuy420 · 2026-02-15
75.9%
#9905: fix: require provider prefix for models set without alias (#5790)
by petter-b · 2026-02-05
75.3%
#19927: fix(agents): replace hardcoded Anthropic model IDs with pattern mat...
by Milofax · 2026-02-18
75.0%
#13401: fix: slug generator should use agent's primary model instead of har...
by pahud · 2026-02-10
73.3%
#21963: fix(cli): models fallbacks add now includes primary model in allowlist
by ashiabbott · 2026-02-20
73.1%
#18697: fix: include forward-compat models in model catalog for allowlist val…
by dmitry-orabey · 2026-02-17
73.0%
#11602: fix(config): skip stale legacy config files when openclaw.json exists
by akoscz · 2026-02-08
73.0%