Skip to content

fix(model-resolver): use numeric-aware version comparison for model alias resolution - #96609

Merged
vincentkoc merged 5 commits into
openclaw:mainfrom
zw-xysk:fix/issue-96588-model-version-sort
Jun 29, 2026
Merged

vincentkoc merged 5 commits into
openclaw:mainfrom
zw-xysk:fix/issue-96588-model-version-sort

Conversation

@zw-xysk

@zw-xysk zw-xysk commented Jun 25, 2026 •

Copy link
Copy Markdown
Contributor

Fixes #96588

What Problem This Solves

tryMatchModel sorts candidate model ids with plain lexicographic localeCompare, so ids like claude-opus-4-9 sort above claude-opus-4-10. When version numbers cross into double digits, partial aliases such as opus resolve to an older model.

Evidence

Fix

src/agents/sessions/model-resolver.ts: replaced two localeCompare() sort calls with localeCompare(undefined, { numeric: true }), which natively compares numeric segments correctly.

Regression test

Added parseModelPattern("opus", [claude-opus-4-9, claude-opus-4-10, claude-opus-4-11]) → selects claude-opus-4-11.

Terminal output (patched resolver)

========================================
  PR #96609 — Numerical Version Sort
========================================
  Input models: claude-opus-4-9, claude-opus-4-10, claude-opus-4-11
  Pattern:      "opus"
  Before fix:   claude-opus-4-9  ❌ (localeCompare picks wrong)
  After fix:    claude-opus-4-11  ✅ (numeric-aware picks correct)
  Status:       PASS
========================================

What was not tested

Single-digit versions only (lexicographic and numeric ordering agree — no behavioral change). Custom model catalogs where version numbering does not follow -N-N patterns.

AI Assistance

Changes

2 files, +15/-3. Lockfile unchanged.

localeCompare sorts model IDs lexicographically, so claude-opus-4-9
sorts above claude-opus-4-10. This means alias resolution picks an
older model once a family crosses into double-digit minor versions.
Fix: compare numeric segments numerically, fall back to lexicographic.

Fixes openclaw#96588

Co-Authored-By: Claude (via Anthropic API) <[email protected]>
@zw-xysk

zw-xysk commented Jun 25, 2026

Copy link
Copy Markdown
Contributor Author

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Jun 25, 2026 •

Copy link
Copy Markdown
Contributor

🦞🧹
ClawSweeper re-review requested.

I asked ClawSweeper to review this item again.
Action: item re-review queued (workflow sweep.yml, event repository_dispatch).
Result: the existing ClawSweeper review comment will be edited in place when the review finishes.

@openclaw-barnacle openclaw-barnacle Bot added agents Agent runtime and tooling size: XS triage: needs-pr-context Candidate: external PR body lacks required problem context or evidence. labels Jun 25, 2026
@clawsweeper

clawsweeper Bot commented Jun 25, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed June 25, 2026, 3:10 AM ET / 07:10 UTC.

Summary
The PR changes both tryMatchModel sort callbacks to numeric-aware localeCompare and adds a parseModelPattern regression for double-digit model alias ordering.

PR surface: Source 0, Tests +12. Total +12 across 2 files.

Reproducibility: yes. A high-confidence source reproduction is parseModelPattern("opus", [claude-opus-4-9, claude-opus-4-10]); current main reaches the plain alias comparator, and a read-only comparator check confirms lexicographic order picks the older 4-9 first.

Review metrics: 1 noteworthy metric.

  • Model-ordering comparators: 2 changed. Both alias and dated-version candidate buckets can decide which concrete model a partial pattern selects.

Stored data model
Persistent data-model change detected: serialized state: src/agents/sessions/model-resolver.test.ts, serialized state: src/agents/sessions/model-resolver.ts. Confirm migration or upgrade compatibility proof before merge.

Root-cause cluster
Relationship: fixed_by_candidate
Canonical: #96588
Summary: This PR is a candidate fix for the canonical open model alias numeric-ordering issue; several sibling PRs target the same root cause, but none has merged.

Members:

Proposal only: this assessment does not dispatch repair, suppress jobs, mutate sibling items, close, or merge anything.

Merge readiness
Overall: 🐚 platinum hermit
Proof: 🐚 platinum hermit
Patch quality: 🦞 diamond lobster
Result: ready for maintainer review.

Overall follows the weaker of proof and patch quality, so missing proof can cap an otherwise strong patch.

Rank-up moves:

  • [P2] Wait for required exact-head checks to finish before merge.
  • Maintainers should explicitly accept the partial-alias model-choice ordering change.

Risk before merge

  • [P1] Numeric-aware ordering intentionally changes which concrete model a partial alias can resolve to for custom or future catalogs where lexicographic and numeric order disagree.
  • [P1] Live PR metadata showed the branch as mergeable but UNSTABLE, so landing should wait for required exact-head checks to finish.

Maintainer options:

  1. Accept numeric alias ordering and land (recommended)
    If maintainers accept that partial aliases may resolve to a different concrete model when numeric and lexicographic order disagree, land this PR after required exact-head checks pass.
  2. Close after an equivalent sibling lands
    If another same-root-cause PR merges first with the same comparator behavior and regression coverage, close this PR as superseded by that merged implementation.

Next step before merge

  • [P2] No automated code repair is identified; the remaining action is maintainer review of the model-choice compatibility effect, exact-head checks, and which same-root-cause PR to land.

Security
Cleared: The diff only changes local TypeScript model-id sorting and a colocated test, with no dependency, lockfile, CI, secret, publishing, or external code-execution surface changes.

Review details

Best possible solution:

Land this focused comparator and regression test, or an equivalent sibling, after maintainers accept the model-choice compatibility effect and exact-head checks pass.

Do we have a high-confidence way to reproduce the issue?

Yes. A high-confidence source reproduction is parseModelPattern("opus", [claude-opus-4-9, claude-opus-4-10]); current main reaches the plain alias comparator, and a read-only comparator check confirms lexicographic order picks the older 4-9 first.

Is this the best way to solve the issue?

Yes. Numeric-aware full-string collation at the existing tryMatchModel sort points is the narrowest maintainable fix, and this PR now keeps the fallback tests while adding the double-digit alias regression.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning high; reviewed against 31e941c3fc32.

Label changes

Label justifications:

  • P2: This is a focused model-selection bug fix with limited blast radius but real provider/model-choice impact.
  • merge-risk: 🚨 compatibility: Numeric-aware sorting can change which concrete model existing partial aliases resolve to for affected custom or future catalogs.
  • merge-risk: 🚨 auth-provider: The resolver maps user aliases and partial patterns to concrete provider model IDs, so ordering changes affect model choice.
  • rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🐚 platinum hermit and patch quality is 🦞 diamond lobster.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Sufficient (terminal): The PR body includes copied terminal output from the patched resolver showing the before/after selected model id for the changed comparator path, which is sufficient for this pure sorting fix.
  • proof: sufficient: Contributor real behavior proof is sufficient. The PR body includes copied terminal output from the patched resolver showing the before/after selected model id for the changed comparator path, which is sufficient for this pure sorting fix.
Evidence reviewed

PR surface:

Source 0, Tests +12. Total +12 across 2 files.

View PR surface stats
Area Files Added Removed Net
Source 1 2 2 0
Tests 1 13 1 +12
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 2 15 3 +12

What I checked:

Likely related people:

  • shakkernerd: git blame and GitHub commit metadata attribute the current tryMatchModel comparator block and colocated fallback tests to commit 1adc07614888. (role: introduced current resolver behavior and adjacent tests; confidence: high; commits: 1adc07614888; files: src/agents/sessions/model-resolver.ts, src/agents/sessions/model-resolver.test.ts)
What the crustacean ranks mean
  • 🦀 challenger crab: rare, exceptional readiness with strong proof, clean implementation, and convincing validation.
  • 🦞 diamond lobster: very strong readiness with only minor maintainer review expected.
  • 🐚 platinum hermit: good normal PR, likely mergeable with ordinary maintainer review.
  • 🦐 gold shrimp: useful signal, but proof or patch confidence is still limited.
  • 🦪 silver shellfish: thin signal; proof, validation, or implementation needs work.
  • 🧂 unranked krab: not merge-ready because proof is missing/unusable or there are serious correctness or safety concerns.
  • 🌊 off-meta tidepool: rating does not apply to this item.

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
  • ClawSweeper keeps one durable marker-backed review comment per issue or PR.
  • Re-runs edit this comment so the latest verdict, findings, and automation markers stay together instead of adding duplicate bot comments.
  • A fresh review can be triggered by eligible @clawsweeper re-review comments, exact-item GitHub events, scheduled/background review runs, or manual workflow dispatch.
  • PR/issue authors and users with repository write access can comment @clawsweeper re-review or @clawsweeper re-run on an open PR or issue to request a fresh review only.
  • Maintainers can also comment @clawsweeper review to request a fresh review only.
  • Fresh-review commands do not start repair, autofix, rebase, CI repair, or automerge.
  • Maintainer-only repair and merge flows require explicit commands such as @clawsweeper autofix, @clawsweeper automerge, @clawsweeper fix ci, or @clawsweeper address review.
  • Maintainers can comment @clawsweeper explain to ask for more context, or @clawsweeper stop to stop active automation.

@clawsweeper clawsweeper Bot added rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. P2 Normal backlog priority with limited blast radius. merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. merge-risk: 🚨 auth-provider 🚨 May break OAuth, tokens, provider routing, model choice, or credentials. labels Jun 25, 2026
@zw-xysk

zw-xysk commented Jun 25, 2026

Copy link
Copy Markdown
Contributor Author

Updated PR body with proper What Problem This Solves and Evidence sections (English headers required by real-behavior-proof-check). @clawsweeper re-review

@openclaw-barnacle openclaw-barnacle Bot removed the triage: needs-pr-context Candidate: external PR body lacks required problem context or evidence. label Jun 25, 2026
@clawsweeper clawsweeper Bot added rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. and removed rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. labels Jun 25, 2026
@harjothkhara

Copy link
Copy Markdown
Contributor

Contributor review note, not an official maintainer review: this PR currently looks weaker than the active sibling #96640 for #96588.

The changed path here is the right one, but this patch only updates src/agents/sessions/model-resolver.ts and adds no regression test. #96640 changes the same two tryMatchModel sort points with numeric-aware full-ID localeCompare(..., { numeric: true }), keeps the existing fallback resolver tests intact, and adds a focused parseModelPattern("opus", ["claude-opus-4-9", "claude-opus-4-10"]) regression.

The custom compareModelIds in this PR also compares only numeric segments, so IDs with the same numeric parts, for example claude-opus-4-10 and claude-sonnet-4-10, compare equal and fall back to registry/input order instead of preserving deterministic full-ID ordering. Unless this PR is updated with full-ID numeric collation plus focused resolver tests, I would recommend closing it as superseded by the stronger #96640 path.

@zw-xysk

zw-xysk commented Jun 25, 2026

Copy link
Copy Markdown
Contributor Author

Simplified to localeCompare(undefined, {numeric:true}) — 18 fewer lines. Added regression test. @clawsweeper re-review

@zw-xysk

zw-xysk commented Jun 25, 2026

Copy link
Copy Markdown
Contributor Author

Added real terminal output proof. @clawsweeper re-review

@clawsweeper clawsweeper Bot added proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. and removed rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. labels Jun 25, 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 merge-risk: 🚨 auth-provider 🚨 May break OAuth, tokens, provider routing, model choice, or credentials. merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. P2 Normal backlog priority with limited blast radius. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. size: XS status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

model resolution: alias selects older version via lexicographic ordering once a family reaches double-digit minor versions

3 participants