Skip to content

fix(models): resolve openrouter:free and openrouter:auto compatibility aliases#57456

Closed
russellju16-afk wants to merge 3 commits into
openclaw:mainfrom
russellju16-afk:fix/openrouter-compat-aliases
Closed

fix(models): resolve openrouter:free and openrouter:auto compatibility aliases#57456
russellju16-afk wants to merge 3 commits into
openclaw:mainfrom
russellju16-afk:fix/openrouter-compat-aliases

Conversation

@russellju16-afk

Copy link
Copy Markdown

Summary

Test plan

  • Added tests for both aliases in parseModelRef and resolveConfiguredModelRef
  • 64/65 model-selection tests pass (1 pre-existing failure unrelated)
  • Manual: set agent model to openrouter:free, verify it resolves correctly

🦞 Generated with Claude Code

@openclaw-barnacle openclaw-barnacle Bot added agents Agent runtime and tooling size: M labels Mar 30, 2026
@greptile-apps

greptile-apps Bot commented Mar 30, 2026

Copy link
Copy Markdown
Contributor

Greptile Summary

This PR fixes a bug (#57066) where openrouter:free and openrouter:auto were mis-resolved to anthropic/openrouter:free because parseModelRef only splits on / and resolveConfiguredModelRef had no special handling for the colon-separated shorthand. The fix introduces a OPENROUTER_COMPAT_ALIASES constant map and checks it before any slash-split or provider-fallback logic in both parseModelRef and resolveConfiguredModelRef.

Key changes:

  • New OPENROUTER_COMPAT_ALIASES constant maps openrouter:freemeta-llama/llama-3.3-70b-instruct:free and openrouter:autoauto, both on the openrouter provider.
  • Both resolution entry points (parseModelRef and resolveConfiguredModelRef) now short-circuit on a compat-alias match before any splitting or provider inference, using { ...compatAlias } shallow copies.
  • Comprehensive new tests cover case-insensitivity (OPENROUTER:FREE), leading/trailing whitespace, and correct provider attribution in resolveConfiguredModelRef.
  • Most other diff lines are mechanical formatting reformats (80-col wrapping) with no logic change.

One minor inconsistency to be aware of: resolveConfiguredModelRef checks compat aliases before user-defined aliases, while resolveModelRefFromString checks user-defined aliases before delegating to parseModelRef (where compat aliases are resolved). In practice this only matters if a user explicitly defines a custom alias named openrouter:free, which is an unlikely and unsupported configuration.

Confidence Score: 4/5

Safe 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.

Important Files Changed

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

Comment thread src/agents/model-selection.ts Outdated
Comment on lines +330 to +336
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 };
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 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.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed — swapped the check order in resolveConfiguredModelRef so user-defined aliases are checked first, consistent with resolveModelRefFromString.

@russellju16-afk russellju16-afk closed this by deleting the head repository Apr 11, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agents Agent runtime and tooling size: M

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: OpenRouter compatibility aliases: openrouter:free resolves to anthropic/openrouter:free; openrouter:auto should also be handled explicitly

1 participant