Skip to content

Commit 3e3a028

Browse files
L-Y-Jliyongjie.103lidge-jun
authored
fix(anthropic): classify capitalized/dotted Claude ids as adaptive thinking (#2483)
* fix(anthropic): classify capitalized/dotted Claude ids as adaptive thinking claudeFamilyVersion only matched lowercase `claude-\<family>-\<major>-\<minor>` ids. Vendor ids such as `Claude-Opus-4.8-joybuilder` failed both the case-sensitive prefix match and the dotted minor parse (4.8 -> minor 0), so usesAdaptiveThinking() returned false and the adapter sent the legacy `thinking: {type: "enabled", budget_tokens}` wire shape to models that reject it (Bedrock 400: "thinking.type.enabled is not supported for this model. Use thinking.type.adaptive and output_config.effort"). Make the parser case-insensitive, accept `.` as a minor separator, and lowercase the captured family before table lookup. Date-pinned ids (claude-opus-4-20250514) and legacy families (opus <= 4.6) keep their previous classification. * test(anthropic): cover capitalized/dotted Claude ids in thinking wire-shape matrix Regression for the family parser fix: Claude-Opus-4.8-joybuilder and claude-opus-4.8-joybuilder must pick the adaptive wire shape, while Claude-Opus-4.6-joybuilder (below the adaptive threshold) must stay on the legacy thinking.enabled shape. * 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. --------- Co-authored-by: liyongjie.103 <[email protected]> Co-authored-by: bitkyc08-arch <[email protected]>
1 parent 73a11a8 commit 3e3a028

2 files changed

Lines changed: 36 additions & 2 deletions

File tree

‎src/adapters/anthropic.ts‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -469,10 +469,10 @@ 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)/.exec(modelId);
472+
const match = /(?:^|\/)claude-([a-z]+)-(\d+)(?:[.-](\d{1,2}))?(?!\d)/i.exec(modelId);
473473
if (!match) return undefined;
474474
return {
475-
family: match[1]!,
475+
family: match[1]!.toLowerCase(),
476476
major: Number(match[2]),
477477
minor: match[3] === undefined ? 0 : Number(match[3]),
478478
};

‎tests/anthropic-reasoning.test.ts‎

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,23 @@ describe("anthropic extended-thinking gate", () => {
5757
"claude-opus-4-7",
5858
"claude-opus-4-8",
5959
"claude-opus-4-8[1m]",
60+
// Vendor ids may be capitalized and/or use a dotted minor; the family parser must
61+
// still classify them as adaptive or the legacy thinking.enabled wire shape goes
62+
// out to a model that rejects it with a 400 (Bedrock ValidationException).
63+
"Claude-Opus-4.8-joybuilder",
64+
"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",
6077
])("adaptive-thinking model %s sends thinking.adaptive + output_config.effort", async (modelId) => {
6178
const b = await bodyOf(parsed("xhigh", { temperature: 0.3, topP: 0.9 }, modelId));
6279
expect(b.thinking).toEqual({ type: "adaptive" });
@@ -275,6 +292,15 @@ describe("anthropic extended-thinking gate", () => {
275292
"claude-sonnet-4-5",
276293
"claude-opus-4-6",
277294
"claude-opus-4-20250514",
295+
// Capitalized/dotted ids below the adaptive threshold must stay on the legacy
296+
// wire shape (guard against over-broad family parsing).
297+
"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",
278304
])("budget-thinking model %s keeps thinking.enabled with budget_tokens", async (modelId) => {
279305
const b = await bodyOf(parsed("high", {}, modelId));
280306
const thinking = b.thinking as { type: string; budget_tokens: number } | undefined;
@@ -319,6 +345,14 @@ describe("anthropic extended-thinking gate", () => {
319345
// The slash can also carry a vendor SUFFIX rather than a routing prefix, so the family
320346
// segment is not reliably first or last. Both directions are real routed shapes.
321347
"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",
322356
])("%s + reasoning 'none' sends an explicit thinking disable (#545)", async (modelId) => {
323357
const b = await bodyOf(parsed("none", { maxOutputTokens: 64, stopSequences: ["</block>"] }, modelId));
324358
expect(b.thinking).toEqual({ type: "disabled" });

0 commit comments

Comments
 (0)