Skip to content

Commit c93bd50

Browse files
committed
fix(claude): match the thinking gate on prefixed model ids too (lidge-jun#545)
A modelMap entry can point at a routed destination like anthropic/claude-sonnet-5, which custom-provider routing decodes back into a slash-carrying native id. Both capability predicates anchored on ^claude-, so those requests silently missed the gate and the model thought anyway — the exact defect, just harder to see. Extracted the shared family/version parse so usesAdaptiveThinking() gets the same tolerance, and pinned all four id shapes plus a prefixed negative case. Also pins the Cursor effect: an explicit "none" now selects the lowest tier rather than the top one. Cursor has no off switch for a reasoning model, and the lowest tier is the closest honest reading of "do not think" — dropping the instruction sent these to the maximum tier, the opposite of what the caller asked for.
1 parent 8bc14b0 commit c93bd50

3 files changed

Lines changed: 60 additions & 18 deletions

File tree

‎src/adapters/anthropic.ts‎

Lines changed: 37 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -408,16 +408,43 @@ const ADAPTIVE_THINKING_FAMILY_MINIMUMS: Record<string, readonly [major: number,
408408
fable: [0, 0],
409409
};
410410

411-
function usesAdaptiveThinking(modelId: string): boolean {
412-
// Minor is 1-2 digits with a non-digit lookahead so date-pinned ids ("claude-opus-4-20250514")
413-
// parse as minor 0 instead of minor 20250514; suffixed ids ("claude-opus-4-8[1m]") still match.
414-
const match = /^claude-([a-z]+)-(\d+)(?:-(\d{1,2}))?(?!\d)/.exec(modelId);
415-
if (!match) return false;
416-
const minimum = ADAPTIVE_THINKING_FAMILY_MINIMUMS[match[1]];
411+
/**
412+
* Family/version parse for a Claude model id, tolerant of a routing prefix.
413+
*
414+
* `parsed.modelId` is not always bare: a `modelMap` entry may point at a routed
415+
* destination such as `anthropic/claude-sonnet-5`, which custom-provider routing
416+
* decodes back into a slash-carrying native id. Anchoring on `^claude-` alone
417+
* would silently fail those, and a capability predicate that quietly returns
418+
* false is worse than one that throws — the request just goes out wrong.
419+
*
420+
* Minor is 1-2 digits with a non-digit lookahead so date-pinned ids
421+
* ("claude-opus-4-20250514") parse as minor 0 instead of minor 20250514;
422+
* suffixed ids ("claude-opus-4-8[1m]") still match.
423+
*/
424+
function claudeFamilyVersion(modelId: string): { family: string; major: number; minor: number } | undefined {
425+
const bare = modelId.slice(modelId.lastIndexOf("/") + 1);
426+
const match = /^claude-([a-z]+)-(\d+)(?:-(\d{1,2}))?(?!\d)/.exec(bare);
427+
if (!match) return undefined;
428+
return {
429+
family: match[1]!,
430+
major: Number(match[2]),
431+
minor: match[3] === undefined ? 0 : Number(match[3]),
432+
};
433+
}
434+
435+
function meetsFamilyMinimum(
436+
modelId: string,
437+
minimums: Record<string, readonly [major: number, minor: number]>,
438+
): boolean {
439+
const parsed = claudeFamilyVersion(modelId);
440+
if (!parsed) return false;
441+
const minimum = minimums[parsed.family];
417442
if (!minimum) return false;
418-
const major = Number(match[2]);
419-
const minor = match[3] === undefined ? 0 : Number(match[3]);
420-
return major > minimum[0] || (major === minimum[0] && minor >= minimum[1]);
443+
return parsed.major > minimum[0] || (parsed.major === minimum[0] && parsed.minor >= minimum[1]);
444+
}
445+
446+
function usesAdaptiveThinking(modelId: string): boolean {
447+
return meetsFamilyMinimum(modelId, ADAPTIVE_THINKING_FAMILY_MINIMUMS);
421448
}
422449

423450
/**
@@ -437,13 +464,7 @@ const EXPLICIT_THINKING_DISABLE_FAMILY_MINIMUMS: Record<string, readonly [major:
437464
};
438465

439466
function supportsExplicitThinkingDisable(modelId: string): boolean {
440-
const match = /^claude-([a-z]+)-(\d+)(?:-(\d{1,2}))?(?!\d)/.exec(modelId);
441-
if (!match) return false;
442-
const minimum = EXPLICIT_THINKING_DISABLE_FAMILY_MINIMUMS[match[1]];
443-
if (!minimum) return false;
444-
const major = Number(match[2]);
445-
const minor = match[3] === undefined ? 0 : Number(match[3]);
446-
return major > minimum[0] || (major === minimum[0] && minor >= minimum[1]);
467+
return meetsFamilyMinimum(modelId, EXPLICIT_THINKING_DISABLE_FAMILY_MINIMUMS);
447468
}
448469

449470
/** `output_config.effort` accepts low|medium|high|xhigh|max — "minimal" is rejected with a 400. */

‎tests/anthropic-reasoning.test.ts‎

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -148,8 +148,16 @@ describe("anthropic extended-thinking gate", () => {
148148
// max_tokens:64. Omitting the field lets a default-on model think anyway, and thinking
149149
// shares that 64-token budget — so generation stopped before the stop sequence and the
150150
// client retried. Say "disabled" out loud, but only where the vendor accepts it.
151-
test("Sonnet 5 + reasoning 'none' sends an explicit thinking disable (#545)", async () => {
152-
const b = await bodyOf(parsed("none", { maxOutputTokens: 64, stopSequences: ["</block>"] }, "claude-sonnet-5"));
151+
test.each([
152+
"claude-sonnet-5",
153+
"claude-sonnet-5-20260101",
154+
"claude-sonnet-5[1m]",
155+
// A modelMap entry can point at a routed destination, which custom-provider routing
156+
// decodes back into a slash-carrying native id. An id-shape miss here is silent: the
157+
// request simply goes out without the disable and the model thinks anyway.
158+
"anthropic/claude-sonnet-5",
159+
])("%s + reasoning 'none' sends an explicit thinking disable (#545)", async (modelId) => {
160+
const b = await bodyOf(parsed("none", { maxOutputTokens: 64, stopSequences: ["</block>"] }, modelId));
153161
expect(b.thinking).toEqual({ type: "disabled" });
154162
expect(b.output_config).toBeUndefined();
155163
// The caller's own limits must survive untouched — they were never the defect.
@@ -169,6 +177,7 @@ describe("anthropic extended-thinking gate", () => {
169177
"claude-opus-4-8",
170178
"claude-haiku-4-5",
171179
"claude-sonnet-4-6",
180+
"anthropic/claude-fable-5",
172181
])("%s + 'none' sends NO explicit disable (#545 gate stays narrow)", async (modelId) => {
173182
// Fable always thinks and rejects an explicit disable; the Opus 4.7/4.8 adaptive wire
174183
// leaves thinking off when omitted. Widening the gate to every adaptive family would

‎tests/cursor-effort-suffix.test.ts‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,18 @@ describe("Cursor per-model reasoning-effort suffix", () => {
4848
expect(modelIdFor("cursor/claude-4.6-opus")).toBe("claude-4.6-opus-max");
4949
});
5050

51+
// #545 made Claude Desktop's `thinking:{type:"disabled"}` survive translation as the "none"
52+
// sentinel instead of being dropped. For a modelMap that routes such a request to Cursor,
53+
// that changes the selected tier — pin it so the cross-provider effect is deliberate.
54+
//
55+
// Cursor has no "off" for a reasoning model, so the lowest tier is the closest honest
56+
// reading of "do not think". Dropping the instruction sent these to the model's TOP tier,
57+
// which is the opposite of what the caller asked for.
58+
test("an explicit 'none' picks the lowest tier, not the top one (#545)", () => {
59+
expect(modelIdFor("cursor/claude-opus-4-8", "none")).toBe("claude-opus-4-8-low");
60+
expect(modelIdFor("cursor/claude-opus-4-8")).toBe("claude-opus-4-8-max");
61+
});
62+
5163
test("single-tier models always use their one tier", () => {
5264
expect(modelIdFor("cursor/gpt-5.5-extra", "low")).toBe("gpt-5.5-extra-high");
5365
expect(modelIdFor("cursor/claude-4.6-sonnet", "high")).toBe("claude-4.6-sonnet-medium");

0 commit comments

Comments
 (0)