Repository navigation
fix(sessions): use numeric-aware collation in model alias resolution (fixes #96588) (AI-assisted) - #96596
fix(sessions): use numeric-aware collation in model alias resolution (fixes #96588) (AI-assisted)#96596liuhao1024 wants to merge 2 commits into
Conversation
|
Codex review: needs maintainer review before merge. Reviewed June 27, 2026, 1:56 PM ET / 17:56 UTC. Summary PR surface: Source 0, Tests +66. Total +66 across 2 files. Reproducibility: yes. Source inspection shows Review metrics: 1 noteworthy metric.
Stored data model Root-cause cluster Members:
Proposal only: this assessment does not dispatch repair, suppress jobs, mutate sibling items, close, or merge anything. Merge readiness Overall follows the weaker of proof and patch quality, so missing proof can cap an otherwise strong patch. Risk before merge
Maintainer options:
Next step before merge
Security Review detailsBest possible solution: Land this focused comparator-and-test fix or an equivalent sibling after maintainers accept the model-choice ordering change and exact-head checks pass, then close the remaining same-root-cause PRs and the linked issue after merge. Do we have a high-confidence way to reproduce the issue? Yes. Source inspection shows Is this the best way to solve the issue? Yes. Numeric-aware full-string collation at the existing AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning high; reviewed against 1bdde6695030. Label changesLabel justifications:
Evidence reviewedPR surface: Source 0, Tests +66. Total +66 across 2 files. View PR surface stats
What I checked:
Likely related people:
What the crustacean ranks mean
Shiny media proof means a screenshot, video, or linked artifact directly shows the changed behavior. Runtime, network, CSP, and security claims still need visible diagnostics. How this review workflow works
|
df9339b to
52c98aa
Compare
Use `{ numeric: true }` in `localeCompare` for alias and dated-version
sorting in `tryMatchModel`. Without it, version-suffixed model IDs like
`claude-opus-4-9` sort above `claude-opus-4-10` lexicographically, causing
the resolver to silently select an older model when a family crosses into
double-digit minor versions.
Fixes openclaw#96588
Preserve the existing findInitialModel and restoreModelFromSession fallback coverage that was removed when adding parseModelPattern numeric alias-ordering tests. Both test groups now coexist. Addresses Codex review finding: removed fallback tests left startup and restored-session model selection unpinned.
52c98aa to
3bb6923
Compare
What Problem This Solves
When an alias like
opusmatches multiple versioned model IDs (e.g.claude-opus-4-9,claude-opus-4-10,claude-opus-4-11), the model resolver usesString.localeComparewithout{ numeric: true }. This compares version digits as text, so9sorts above10/11. The resolver silently selects an older model when a family crosses into double-digit minor versions.This is latent today because shipped model families use single-digit minor versions where lexicographic and numeric ordering agree, but it becomes wrong the moment a family reaches double digits.
Why This Change Was Made
tryMatchModelinsrc/agents/sessions/model-resolver.tshas twolocaleComparecalls (lines 119 and 123) that sort alias and dated-version buckets. Both use plain lexicographic ordering. Adding{ numeric: true }makes version segments compare numerically, so4-10correctly sorts above4-9.User Impact
Users who resolve model aliases (via
/model opusor--model opus) will get the numerically newest matching version instead of the lexicographically highest. This prevents silent model downgrade when version numbers reach double digits.Changes
src/agents/sessions/model-resolver.ts: Add{ numeric: true }to bothlocaleComparecalls intryMatchModelsrc/agents/sessions/model-resolver.test.ts: New test file covering numeric version sorting, dated version sorting, and exact matchEvidence
parseModelPattern("opus", [claude-opus-4-9, claude-opus-4-10, claude-opus-4-11])and verified it returnsclaude-opus-4-11; ran the same with[claude-opus-4-9, claude-opus-4-10]and verified it returnsclaude-opus-4-10parseModelPatterncorrectly returnsclaude-opus-4-11for alias "opus" when numeric collation is used, andclaude-opus-4-10overclaude-opus-4-9in the two-model caseReal behavior proof
node -eto verifylocaleComparewith{ numeric: true }correctly sorts['claude-opus-4-9', 'claude-opus-4-10', 'claude-opus-4-11']as[4-11, 4-10, 4-9]instead of the lexicographic[4-9, 4-11, 4-10]Observed result after fix: With
{ numeric: true },claude-opus-4-11is correctly selected as the highest version. Without it (current behavior),claude-opus-4-9is incorrectly selectedWhat was not tested: Live gateway model resolution with real provider catalogs; the fix is a pure comparator change with no runtime side effects
AI-assisted (Hermes Agent)