Problem
ModelAlias.resolve / resolveRef validates a model reference differently depending on whether any aliases are configured. With no aliases it uses parseRefString, which rejects an empty variant and a variant containing a second #. With aliases present it takes the loop path in resolveRef, which accepts both — silently dropping an empty variant and keeping a # inside the variant verbatim.
Evidence (verified 2026-10-24 on main 58dd3fb)
File: packages/schema/src/model-alias.ts
- No-alias path delegates to
parseRefString (line 53), whose check at line 233 throws when variant is empty or contains #.
- Alias path (lines 57-169) records
explicitVariant from the first # (lines 72-73) with no equivalent validation, and builds the final ref from it at line 169 onward.
Reproduction (Bun, importing packages/core/src/model-alias.ts, aliases = { models: { flash: "openai/gpt-4o" }, variants: { high: "xhigh" } }):
| Input |
No aliases |
With aliases |
openai/gpt-4o# |
THROWS Invalid model reference: openai/gpt-4o# |
returns "openai/gpt-4o" (empty variant silently dropped) |
openai/gpt-4o#high#extra |
THROWS Invalid model reference: openai/gpt-4o#high#extra |
returns "openai/gpt-4o#high#extra" (second # kept in the variant) |
Why it matters
The same malformed reference is an error for one user and silently accepted for another, purely because the second user configured an unrelated alias. The double-# form produces a ResolvedRef.variant of high#extra and a canonical ref no other parser in the repo accepts, so it will fail later — further from the cause — or be passed to a provider as a variant name that can never match. The empty-variant form hides a typo (model# for model#high).
Acceptance criteria
- With aliases configured,
openai/gpt-4o# throws the same invalid-reference error as the no-alias path.
- With aliases configured,
openai/gpt-4o#high#extra throws the same invalid-reference error as the no-alias path.
- Validation also covers a variant that arrives via an alias target (e.g. a model alias expanding to
provider/model# or provider/model#a#b), not only a variant typed in the original input.
- New tests in
packages/core/test/model-alias.test.ts cover both shapes on the alias path; all existing model-alias tests still pass.
- Dedup checked 2026-10-24: no open or closed issue tracks this validation parity gap (fix(core): bare-alias variant is preserved by the session runner (PR #390) but dropped by ModelResolver (PR #382) #391 is about a bare-alias variant being dropped by ModelResolver, a different code path).
Single-repo: ModelAlias lives only in this repo's schema/core packages.