#9905: fix: require provider prefix for models set without alias (#5790)
commands
agents
stale
size: S
trusted-contributor
Root cause: `models set` defaulted to `anthropic/` provider when no prefix was given, causing local models like `qwen2.5-coder:7b` to be stored as `anthropic/qwen2.5-coder:7b`.
Fix: Reject models without provider prefix unless they match a known alias; clear error message guides users to use `provider/model` format.
Test: Added tests for rejection case, explicit prefix case, and alias bypass case.
Fixes #5790
<!-- greptile_comment -->
<h3>Greptile Summary</h3>
This PR fixes issue #5790 where `models set` (and other model commands) would silently default to the `anthropic/` provider when no provider prefix was given. This caused local models like `qwen2.5-coder:7b` to be incorrectly stored as `anthropic/qwen2.5-coder:7b`.
- `resolveModelTarget` in `src/commands/models/shared.ts` now rejects model strings without a `/` provider prefix unless they match a known user-configured alias, throwing a clear error message guiding users to use `provider/model` format
- The fix applies consistently across all model commands (`set`, `set-image`, `fallbacks add/remove`, `image-fallbacks add/remove`, `aliases set`) since they all use `resolveModelTarget`
- Three new tests in `models.set.e2e.test.ts` cover the rejection case, explicit prefix case, and alias bypass case
- A new test in `model-fallback.e2e.test.ts` documents that the fallback loop respects user-configured providers and does not inject `anthropic` into the candidate list
The implementation is clean — the guard check is correctly placed after alias resolution but before returning, and uses the existing `resolved.alias` field to determine whether the input matched an alias. No issues found.
<h3>Confidence Score: 5/5</h3>
- This PR is safe to merge — it's a focused input validation fix with comprehensive test coverage and no regressions.
- The change is a well-scoped guard clause in a single function (`resolveModelTarget`) that adds input validation rather than changing core logic. The fix correctly uses existing data (`resolved.alias`) from the model resolution pipeline. All three key scenarios (rejection, explicit prefix, alias bypass) are tested. The function is used by 6 command files, all of which benefit from this validation consistently. The fallback test provides additional confidence that the broader system respects user-configured providers. No edge cases were found that could cause regressions.
- No files require special attention.
<sub>Last reviewed commit: e04381a</sub>
<!-- greptile_other_comments_section -->
<!-- /greptile_comment -->
Most Similar PRs
#13626: fix(model): propagate provider model properties in fallback resolution
by mcaxtr · 2026-02-10
83.4%
#11198: fix(models): strip @profile suffix from model selection
by mcaxtr · 2026-02-07
82.2%
#16838: fix: include configured fallbacks in model allowlist
by taw0002 · 2026-02-15
80.9%
#11349: fix(agents): do not filter fallback models by models allowlist
by liuxiaopai-ai · 2026-02-07
80.6%
#23136: fix: lookupContextTokens should handle provider/model refs
by patchguardio · 2026-02-22
80.5%
#9822: fix: allow local/custom model providers for sub-agent inference
by stammtobias91 · 2026-02-05
80.3%
#20185: fix(model): recognize default/reset/clear keywords to clear session...
by yxshee · 2026-02-18
80.0%
#17560: fix: Anthropic Prompt Caching Not Working - Missing cache_control H...
by MisterGuy420 · 2026-02-15
80.0%
#17469: Improve unknown-model errors for provider/model misconfiguration
by megahappyclaw · 2026-02-15
79.9%
#20080: fix: resolve model aliases correctly when keyed by short name
by kamal-ayman · 2026-02-18
79.9%