forwardOnce turns thinking {type: enabled, budget_tokens} into adaptive
for a model that thinks only adaptively (adaptiveThinking): an Anthropic
client's own budget, or one buildAnthropic made for a model magpie knows
by another name than the vendor's (relay/opus mapped to
claude-opus-4-7: a Chat client's reasoning_effort, which the previous
commit's display didn't reach). Enabled thinking shows its text
(display "summarized" by default); adaptive thinking on Opus 4.7 and
later leaves it out unless asked, so magpie's rewrite hid the thinking
the client asked for. It now asks display "summarized" unless the
request names its own display.
adaptiveThinking now runs before withoutRefusedShapes, so a provider
that refused display isn't sent one again, and refuseShapes reads the
display as forwardOnce sends it, so a strict relay's 400 for it is
learned when the client's body had none.
Run: TestBudgetTurnedAdaptiveIsShown fails without the display (relayed
budget, plain and streamed, and a Chat effort on an alias: thinking
empty) and with the old order (a strict relay's 400 passed to the
client); passes with the change. TestAdaptiveOnlyModelsNeverGetABudget
and TestFableAndMythosNeverGetABudget expect display on a relayed
budget, and a client's own display ("omitted") is kept. go test -tags
nogui ./internal/gateway ./internal/usage under a temp HOME, gofmt -l,
GOOS=linux and GOOS=windows go vet -tags nogui. Not tried against a
real Anthropic key or a real strict relay.
Claude Opus 4.7, 4.8, 5 and 5.5, Sonnet 5 and 5.5, Haiku 5.5, Fable and
Mythos default thinking.display to "omitted": a thinking block comes
back with an empty thinking field unless "summarized" is asked for
(Anthropic's thinking docs, Controlling thinking display). buildAnthropic
asked them {"type":"adaptive"} alone, so a Chat client's
reasoning_effort or a Responses client's reasoning (Codex) got a reply
with no reasoning_content and no reasoning summary, while OpenAI's
(summary "auto" in buildResponses) and the Claude subscription's
(--thinking-display summarized) show it, as 4.6 did by default.
buildAnthropic now asks {"type":"adaptive","display":"summarized"}. A
relay that refuses display is asked again without it and from then on
sent none (refuseShapes, as for Claude Code's display). Thinking turned
off later (disabled, between_tools, none) replaces the whole thinking
object, so display never goes with it.
Run: TestTranslatedClaudeReasoningIsShown (a fake Anthropic API that
writes thinking text only for display summarized, and for 4.6 by
default) fails on the old code for Opus 5.5, Opus 4.7 and Fable 5.1 over
Chat and Opus 5.5 over Responses (no display, no reasoning in the
reply); TestTranslatedDisplayLeftOutWhereRefused fails on the old code
and passes with it (a strict relay still answers, then is sent none).
TestAdaptiveThinking and TestFableAndMythosNeverGetABudget expect the
new shape for a built request. The shapes tests
(TestRelayRefusingClaudeCodesNewShapes, TestClaudeCodesNewShapesKeptWhereTaken)
pass. Not tried with a real Anthropic key, Bedrock or Vertex, nor in
the real Codex UI.
Co-authored-by: ggbdpq <ggbdpq@gmail.com>
adaptiveOnly read a Claude's version with claudeVersion, which knew
opus, sonnet and haiku only, while claudeLine (thinkingOffOf,
samplingRefused) already knew fable and mythos. So claude-fable-5,
claude-fable-5-1, claude-mythos-5 and claude-mythos-5-1 were taken for
models that take thinking.type=enabled with budget_tokens:
buildAnthropic turned a Chat or Responses client's reasoning_effort into
a budget, forwardOnce's adaptiveThinking relayed an agent's budget as it
came, and AdaptiveThinking didn't tell Pi (forceAdaptiveThinking), dsh
or omp (anthropic-adaptive) to ask adaptively. Anthropic documents that
Fable 5 and 5.1 and Mythos 5 and 5.1 answer thinking.type=enabled with
budget_tokens with a 400 and take only {"type": "adaptive"} with the
effort in output_config.
claudeVersion now reads fable and mythos too, so all three paths treat
these models as Opus 5.5 is treated. claude-mythos-preview has no
version in its id and is left as it was.
What was run: TestFableAndMythosNeverGetABudget (a fake Anthropic
upstream answering 400 to enabled) fails on the old main: adaptiveOnly
false for all five ids, and status 400 for a relayed Fable budget, a
Chat client's reasoning_effort on Fable and a relayed Mythos budget. It
passes with the change, as do TestAdaptive*, TestThinkingOff*,
TestSampling*, TestClaudeFiveFive* and TestHaikuFiveFive*. Broken by
hand (mythos dropped from the regex) the Mythos cases fail again.
gofmt -l prints nothing; go vet -tags nogui ./... passes for darwin,
linux and windows; go test -tags nogui -count=1 ./... under a temp HOME
passes.
Not tried against Anthropic itself: the owner's Claude sign-in keeps
its token in the keychain, which a sandbox doesn't read (and must not
refresh), and the one relay with Fable listed (aihubmix) has no balance
for it; that relay also takes a budget on Opus 5.5, so it doesn't show
Anthropic's refusal either.
Reported and fixed by ggbdpq (#1470).
Co-authored-by: factory-droid[bot] <138933559+factory-droid[bot]@users.noreply.github.com>