Skip to content

Commit 3833342

Browse files
committed
fix(anthropic): do not let the __omit__ sentinel become an effort value
The provider default is read from modelDefaultReasoningEfforts, which can carry the __omit__ wire sentinel meaning 'send no reasoning field'. Treated as an ordinary effort it did the opposite of what it asks: adaptive models received output_config.effort: "__omit__" on the wire, and budget models had thinking turned ON with a default budget. Verified by probe before the fix, and the new regressions fail without it.
1 parent b2f95e1 commit 3833342

2 files changed

Lines changed: 49 additions & 2 deletions

File tree

‎src/adapters/anthropic.ts‎

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ import { CLAUDE_CODE_HEADERS, claudeCodeSessionId } from "./client-fingerprint";
2727
import { buildNonOpenAIToolCatalogNudgeForTools } from "./tool-catalog-nudge";
2828
import { decodeServerSentEvents } from "../lib/sse-decoder";
2929
import { isTranslatorBudgetExceededError, retainTranslatedEventBatch, type TranslatorBudget } from "../lib/translator-budget";
30-
import { modelRecordValue } from "../reasoning-effort";
30+
import { isReasoningEffortOmitted, modelRecordValue } from "../reasoning-effort";
3131

3232
/** Map a user content part to an Anthropic content block (text or image source). */
3333
function toAnthropicContentPart(p: OcxContentPart): unknown {
@@ -521,7 +521,14 @@ function adaptiveEffort(effort: string): string {
521521

522522
function defaultReasoningEffort(provider: OcxProviderConfig, modelId: string): string | undefined {
523523
const value = modelRecordValue(provider.modelDefaultReasoningEfforts, modelId);
524-
return typeof value === "string" && value.trim() ? value.trim() : undefined;
524+
if (typeof value !== "string") return undefined;
525+
const trimmed = value.trim();
526+
// `__omit__` means "send no reasoning field", not "an effort literally named
527+
// __omit__". Without this the sentinel reached the wire as
528+
// `output_config.effort: "__omit__"` on adaptive models, and enabled budget
529+
// thinking on the rest — the opposite of what it asks for (#2432).
530+
if (!trimmed || isReasoningEffortOmitted(trimmed)) return undefined;
531+
return trimmed;
525532
}
526533

527534
function usageFromAnthropic(usage: Record<string, number> | undefined): OcxUsage | undefined {

‎tests/anthropic-reasoning.test.ts‎

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -487,3 +487,43 @@ describe("Claude Desktop classifier round trip (#545)", () => {
487487
expect(body.stop_sequences).toEqual(["</block>"]);
488488
});
489489
});
490+
491+
describe("provider default reasoning effort (#2494)", () => {
492+
const withDefault = (model: string, effort: string) => ({
493+
...(provider as unknown as Record<string, unknown>),
494+
modelDefaultReasoningEfforts: { [model]: effort },
495+
} as unknown as OcxProviderConfig);
496+
497+
test("a configured default applies when the caller omits reasoning", async () => {
498+
const model = "anthropic/claude-sonnet-4.5";
499+
const b = await bodyOf(parsed(undefined, {}, model), withDefault(model, "high"));
500+
expect((b.thinking as { type?: string } | undefined)?.type).toBe("enabled");
501+
expect((b.thinking as { budget_tokens?: number }).budget_tokens).toBe(16384);
502+
});
503+
504+
test("an explicit caller effort still wins over the configured default", async () => {
505+
const model = "anthropic/claude-sonnet-4.5";
506+
const b = await bodyOf(parsed("none", {}, model), withDefault(model, "high"));
507+
expect(b.thinking).toBeUndefined();
508+
});
509+
510+
// The sentinel means "send no reasoning field". Treating it as an effort put
511+
// output_config.effort: "__omit__" on the wire for adaptive models and turned
512+
// budget thinking ON for the rest — the opposite of the request.
513+
test("the __omit__ sentinel never becomes an effort value", async () => {
514+
const adaptive = "anthropic/claude-fable-5";
515+
const a = await bodyOf(parsed(undefined, {}, adaptive), withDefault(adaptive, "__omit__"));
516+
expect(a.output_config).toBeUndefined();
517+
expect(a.thinking).toBeUndefined();
518+
519+
const budget = "anthropic/claude-sonnet-4.5";
520+
const b = await bodyOf(parsed(undefined, {}, budget), withDefault(budget, "__omit__"));
521+
expect(b.thinking).toBeUndefined();
522+
});
523+
524+
test("a blank default is ignored rather than treated as an effort", async () => {
525+
const model = "anthropic/claude-sonnet-4.5";
526+
const b = await bodyOf(parsed(undefined, {}, model), withDefault(model, " "));
527+
expect(b.thinking).toBeUndefined();
528+
});
529+
});

0 commit comments

Comments
 (0)