fix(models): resolve openrouter:free and openrouter:auto compatibility aliases#57456
fix(models): resolve openrouter:free and openrouter:auto compatibility aliases#57456russellju16-afk wants to merge 3 commits into
Conversation
Greptile SummaryThis PR fixes a bug (#57066) where Key changes:
One minor inconsistency to be aware of: Confidence Score: 4/5Safe to merge; the core bug fix is correct and well-tested, with one minor alias-priority inconsistency worth addressing. The fix correctly resolves the reported mis-attribution bug with proper shallow copies and case-insensitive lookup. Tests are thorough. Score is 4 rather than 5 only because of the alias-priority inconsistency between resolveConfiguredModelRef and resolveModelRefFromString — a user who defines a custom alias named openrouter:free will see different behavior depending on which resolution path is taken. src/agents/model-selection.ts — the compat-alias priority relative to user-defined aliases in resolveConfiguredModelRef vs. resolveModelRefFromString should be aligned.
|
| Filename | Overview |
|---|---|
| src/agents/model-selection.ts | Adds OPENROUTER_COMPAT_ALIASES map and checks it in both parseModelRef (before slash-split) and resolveConfiguredModelRef (before user-alias lookup), correctly fixing the mis-attribution bug. Shallow-copy via spread prevents caller mutation. Minor priority inconsistency with resolveModelRefFromString noted. |
| src/agents/model-selection.test.ts | Adds test cases for both openrouter:free and openrouter:auto aliases in parseModelRef (including whitespace-trimming and uppercase variants) and in resolveConfiguredModelRef. Remaining changes are whitespace/formatting reformats only. |
Prompt To Fix All With AI
This is a comment left during a code review.
Path: src/agents/model-selection.ts
Line: 330-336
Comment:
**Alias priority inconsistency with `resolveModelRefFromString`**
In `resolveConfiguredModelRef`, compat aliases are checked *before* user-defined aliases (line 333), so `OPENROUTER_COMPAT_ALIASES` always wins. However, in `resolveModelRefFromString` (lines 294–315), user-defined aliases are checked *before* `parseModelRef` is called — meaning a user-configured alias named `openrouter:free` would win there.
These two code paths disagree on priority. If a user defines a custom alias `openrouter:free` pointing to a different model, `resolveConfiguredModelRef` will silently ignore it, while any other caller that goes through `resolveModelRefFromString` will respect it. Consider making the priority uniform (either compat-first everywhere or user-first everywhere) or documenting the intentional asymmetry in a comment.
How can I resolve this? If you propose a fix, please make it concise.Reviews (1): Last reviewed commit: "fix(models): return shallow copy from Op..." | Re-trigger Greptile
| if (!trimmed.includes("/")) { | ||
| // Check OpenRouter compatibility aliases (e.g. "openrouter:free") before | ||
| // any user-defined alias or provider-fallback logic. (#57066) | ||
| const compatAlias = OPENROUTER_COMPAT_ALIASES[trimmed.toLowerCase()]; | ||
| if (compatAlias) { | ||
| return { ...compatAlias }; | ||
| } |
There was a problem hiding this comment.
Alias priority inconsistency with
resolveModelRefFromString
In resolveConfiguredModelRef, compat aliases are checked before user-defined aliases (line 333), so OPENROUTER_COMPAT_ALIASES always wins. However, in resolveModelRefFromString (lines 294–315), user-defined aliases are checked before parseModelRef is called — meaning a user-configured alias named openrouter:free would win there.
These two code paths disagree on priority. If a user defines a custom alias openrouter:free pointing to a different model, resolveConfiguredModelRef will silently ignore it, while any other caller that goes through resolveModelRefFromString will respect it. Consider making the priority uniform (either compat-first everywhere or user-first everywhere) or documenting the intentional asymmetry in a comment.
Prompt To Fix With AI
This is a comment left during a code review.
Path: src/agents/model-selection.ts
Line: 330-336
Comment:
**Alias priority inconsistency with `resolveModelRefFromString`**
In `resolveConfiguredModelRef`, compat aliases are checked *before* user-defined aliases (line 333), so `OPENROUTER_COMPAT_ALIASES` always wins. However, in `resolveModelRefFromString` (lines 294–315), user-defined aliases are checked *before* `parseModelRef` is called — meaning a user-configured alias named `openrouter:free` would win there.
These two code paths disagree on priority. If a user defines a custom alias `openrouter:free` pointing to a different model, `resolveConfiguredModelRef` will silently ignore it, while any other caller that goes through `resolveModelRefFromString` will respect it. Consider making the priority uniform (either compat-first everywhere or user-first everywhere) or documenting the intentional asymmetry in a comment.
How can I resolve this? If you propose a fix, please make it concise.There was a problem hiding this comment.
Fixed — swapped the check order in resolveConfiguredModelRef so user-defined aliases are checked first, consistent with resolveModelRefFromString.
Summary
openrouter:freeresolves toanthropic/openrouter:free;openrouter:autoshould also be handled explicitly #57066:openrouter:freewas mis-resolved toanthropic/openrouter:freebecauseparseModelRefonly splits on/OPENROUTER_COMPAT_ALIASESmap with explicit mappings foropenrouter:free→meta-llama/llama-3.3-70b-instruct:freeandopenrouter:auto→autoparseModelRefandresolveConfiguredModelRefbefore the slash-split logicTest plan
parseModelRefandresolveConfiguredModelRefopenrouter:free, verify it resolves correctly🦞 Generated with Claude Code