Skip to content

Commit 7ae52dc

Browse files
authored
fix(model-resolver): use numeric-aware version comparison for model alias resolution
1 parent bf83ea1 commit 7ae52dc

2 files changed

Lines changed: 15 additions & 3 deletions

File tree

‎src/agents/sessions/model-resolver.test.ts‎

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { describe, expect, it } from "vitest";
44
import type { Model } from "../../llm/types.js";
55
import { DEFAULT_MODEL, DEFAULT_PROVIDER } from "../defaults.js";
66
import type { ModelRegistry } from "./model-registry.js";
7-
import { findInitialModel, restoreModelFromSession } from "./model-resolver.js";
7+
import { findInitialModel, parseModelPattern, restoreModelFromSession } from "./model-resolver.js";
88

99
function model(provider: string, id: string): Model {
1010
return {
@@ -57,3 +57,15 @@ describe("model resolver fallback selection", () => {
5757
expect(result.model).toBe(firstAvailable);
5858
});
5959
});
60+
61+
describe("parseModelPattern version sorting", () => {
62+
it("selects the numerically highest version when aliases span double-digit minors", () => {
63+
const models = [
64+
model("anthropic", "claude-opus-4-9"),
65+
model("anthropic", "claude-opus-4-10"),
66+
model("anthropic", "claude-opus-4-11"),
67+
];
68+
const result = parseModelPattern("opus", models);
69+
expect(result.model?.id).toBe("claude-opus-4-11");
70+
});
71+
});

‎src/agents/sessions/model-resolver.ts‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -116,11 +116,11 @@ function tryMatchModel(modelPattern: string, availableModels: Model[]): Model |
116116

117117
if (aliases.length > 0) {
118118
// Prefer alias - if multiple aliases, pick the one that sorts highest
119-
aliases.sort((a, b) => b.id.localeCompare(a.id));
119+
aliases.sort((a, b) => b.id.localeCompare(a.id, undefined, { numeric: true }));
120120
return aliases[0];
121121
}
122122
// No alias found, pick latest dated version
123-
datedVersions.sort((a, b) => b.id.localeCompare(a.id));
123+
datedVersions.sort((a, b) => b.id.localeCompare(a.id, undefined, { numeric: true }));
124124
return datedVersions[0];
125125
}
126126

0 commit comments

Comments
 (0)