Skip to content

Commit dc0e4c0

Browse files
committed
fix(anthropic): reject a longer number, not any dot, in the family tail
The capitalization and dotted-minor repair is right, but widening the tail from (?!\d) to (?![\d.]) to stop "claude-opus-4.20250514" also rejected "claude-opus-4-8.1": the minor group matches "8", the tail sees the following dot, the match is discarded, and the regex backtracks to a major-only "4.0". That id parsed as Opus 4.8 before this PR, so it would newly take the legacy thinking.enabled wire shape — the exact 400 this change exists to prevent, reintroduced for a different id family. A dotted suffix after a dashed minor is not a dotted minor. The tail's job is to reject a longer NUMBER, which the original (?!\d) already did; the dotted-minor support belongs entirely to the [.-] separator. Keeping (?!\d) and adding only [.-] and /i covers every id the PR intended, preserves every id the old regex classified correctly, and additionally recovers "claude-opus-4.20250514" and "claude-opus-4.8.1", which the wider tail turned into no match at all. Tests: the adaptive matrix gains the dashed-capitalized and end-of-string dotted cells so the capitalization and separator axes are covered independently, plus "claude-opus-4-8.1" as the regression for the above. The legacy matrix gains a capitalized date-pinned id, which previously reached that branch by failing to parse rather than by parsing correctly. The #545 explicit-disable matrix gains "Claude-Sonnet-5" — the only case that exercises claudeFamilyVersion's second caller, where a miss is invisible because the request simply goes out without the disable. Verified red-then-green: with the original tail restored, only the claude-opus-4-8.1 case fails (59 pass, 1 fail); with this correction, 60 pass, 0 fail. tsc --noEmit clean.
1 parent 3304814 commit dc0e4c0

2 files changed

Lines changed: 27 additions & 1 deletion

File tree

‎src/adapters/anthropic.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -469,7 +469,7 @@ function claudeFamilyVersion(modelId: string): { family: string; major: number;
469469
// Find the segment that actually starts with `claude-`, rather than assuming it is either
470470
// the first (breaks `anthropic/claude-sonnet-5`) or the last (breaks `claude-sonnet-5/variant`,
471471
// where the slash carries a vendor suffix rather than a routing prefix).
472-
const match = /(?:^|\/)claude-([a-z]+)-(\d+)(?:[.-](\d{1,2}))?(?![\d.])/i.exec(modelId);
472+
const match = /(?:^|\/)claude-([a-z]+)-(\d+)(?:[.-](\d{1,2}))?(?!\d)/i.exec(modelId);
473473
if (!match) return undefined;
474474
return {
475475
family: match[1]!.toLowerCase(),

‎tests/anthropic-reasoning.test.ts‎

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,18 @@ describe("anthropic extended-thinking gate", () => {
6262
// out to a model that rejects it with a 400 (Bedrock ValidationException).
6363
"Claude-Opus-4.8-joybuilder",
6464
"claude-opus-4.8-joybuilder",
65+
// The separator and the capitalization are independent axes, and the PR changed
66+
// both at once ([.-] plus the /i flag). Cover the whole 2x2 so a later regex edit
67+
// that repairs one axis while breaking the other cannot pass: dashed-capitalized
68+
// and dotted-lowercase are exactly the cells the original two cases leave open.
69+
"Claude-Opus-4-8",
70+
"Claude-Opus-4.8",
71+
"claude-opus-4.8",
72+
// A dotted SUFFIX after a dashed minor is not a dotted minor. Widening the tail to
73+
// (?![\d.]) to stop "4.20250514" also rejected "4-8.1", silently demoting an id the
74+
// old regex classified correctly — a regression inside the fix for the opposite bug.
75+
// The tail must reject a longer NUMBER, not any dot.
76+
"claude-opus-4-8.1",
6577
])("adaptive-thinking model %s sends thinking.adaptive + output_config.effort", async (modelId) => {
6678
const b = await bodyOf(parsed("xhigh", { temperature: 0.3, topP: 0.9 }, modelId));
6779
expect(b.thinking).toEqual({ type: "adaptive" });
@@ -283,6 +295,12 @@ describe("anthropic extended-thinking gate", () => {
283295
// Capitalized/dotted ids below the adaptive threshold must stay on the legacy
284296
// wire shape (guard against over-broad family parsing).
285297
"Claude-Opus-4.6-joybuilder",
298+
// The date-pinned guard is the reason the minor group is bounded to {1,2} with a
299+
// (?!\d) tail. A capitalized date-pinned id never matched the old lowercase regex
300+
// at all, so it reached this branch by failing to parse rather than by parsing
301+
// correctly — the same observable outcome for two opposite reasons. Now that /i
302+
// makes it parse, assert it still reads as minor 0 and stays legacy.
303+
"Claude-Opus-4-20250514",
286304
])("budget-thinking model %s keeps thinking.enabled with budget_tokens", async (modelId) => {
287305
const b = await bodyOf(parsed("high", {}, modelId));
288306
const thinking = b.thinking as { type: string; budget_tokens: number } | undefined;
@@ -327,6 +345,14 @@ describe("anthropic extended-thinking gate", () => {
327345
// The slash can also carry a vendor SUFFIX rather than a routing prefix, so the family
328346
// segment is not reliably first or last. Both directions are real routed shapes.
329347
"claude-sonnet-5/variant",
348+
// claudeFamilyVersion() has TWO callers through meetsFamilyMinimum():
349+
// usesAdaptiveThinking() and supportsExplicitThinkingDisable(). Every case above
350+
// reaches only the first one, so a capitalization regression in the parser would
351+
// silently drop the explicit disable while the adaptive matrix stayed green.
352+
// A missed disable is invisible in the wire shape: the request simply goes out
353+
// without the field and the model thinks anyway, on a 64-token budget it shares
354+
// with generation (#545).
355+
"Claude-Sonnet-5",
330356
])("%s + reasoning 'none' sends an explicit thinking disable (#545)", async (modelId) => {
331357
const b = await bodyOf(parsed("none", { maxOutputTokens: 64, stopSequences: ["</block>"] }, modelId));
332358
expect(b.thinking).toEqual({ type: "disabled" });

0 commit comments

Comments
 (0)