d3581077 made Devin's "Bash:0#a65b…" ids safe in the built-in Devin only. Any other upstream whose output reaches Claude Code through /v1/messages (a plugin's provider, a Chat or Responses relay, another vendor) could give an id with another character, and Claude Code drops the call and fails the turn "could not be parsed". The mapping now sits at the Anthropic boundary: anthropicEncoder and renderAnthropic give the client anthropicOutID (an unsafe id, or one beginning "mp_", as "mp_" and its base64url), and parseAnthropic turns tool_use ids and tool_result tool_use_ids back with anthropicInID, so the upstream gets its own id on the next turn, before unsignCalls reads Gemini's signatures off it. It is stateless, the same scheme as Devin's (safeCallID/rawCallID, which devinOutID/devinInID now call with "dv_"). An id that is safe already, Devin's "dv_…" ones (built-in and plugin) among them, goes both ways byte for byte, so prompt caching and every upstream that works today see no change. buildAnthropic still gives an Anthropic upstream the ids as they came. Chat's tool_calls id and Responses' call_id are left as they are: Codex and pi take any id, and no client that refuses one is known.
TestAnthropicCallIDsSafeBothWays gives the reporter's literal id from a Chat upstream through New().Handler() on /v1/messages, streamed and whole, and answers the call the way Claude Code does: with anthropicOutID/anthropicInID returning the id as it came (the old code) it fails "stream=true: call id \"Bash:0#a65b6a5e02194b87bbc796c4428c946d\", want one of [A-Za-z0-9_-] only"; with only anthropicInID taken out it fails with the upstream getting "mp_QmFz…" for its call and result. TestAnthropicSafeCallIDsUnchanged keeps toolu_/call_ ids and Devin's dv_ ids as they came, end to end too; with the mark set to "dv_" it fails on the double-encoded Devin ids.
go test -tags nogui ./internal/gateway ./internal/provider pass on Linux (golang:1.26.8 in Docker, temp HOME, module cache read-only; this Mac's syspolicyd is pegged and new binaries hang at launch, so no darwin test run). go vet -tags nogui ./internal/gateway for darwin, GOOS=linux and GOOS=windows, and gofmt -l pass. Not tried with a real Devin account or a real Claude Code session; an Anthropic upstream relayed as-is (passthrough) keeps its ids as it gave them.
SWE-2 names a call after its tool and turn ("Bash:0#a65b6a5e02194b87bbc796c4428c946d"). Claude Code takes a tool_use id only of [A-Za-z0-9_-], dropped every such call and failed the turn with "The model's tool call could not be parsed (retry also failed)"; Codex and pi take any id. decodeDevin now sends an id with another character, or one beginning "dv_", as "dv_" and its base64url (devinOutID), and buildDevin turns it back (devinInID) on the assistant's call and on the result that answers it, so Devin sees its own id. A safe id goes both ways as it came. It is stateless, and the same mapping the Devin plugin makes in 0.1.13 (outID/inID).
TestDevinCallIDsSafeBothWays takes Devin's reply with the reporter's literal id through serveDevin on Anthropic, Chat and Responses, and answers the call in the next request of each: with devinOutID and devinInID made to return the id as it came (the old behavior) it fails "anthropic: call id \"Bash:0#a65b6a5e02194b87bbc796c4428c946d\", want one of [A-Za-z0-9_-] only"; with only devinInID taken out (a one-way clean, as the issue proposed) it fails too, Devin getting the cleaned id. TestDevinSafeCallIDsUnchanged keeps safe ids, and a caller's own "dv_…", as they came.
go test -tags nogui ./internal/provider ./internal/gateway pass on Linux (golang:1.26.8 in Docker, temp HOME, module cache mounted read-only): on this Mac every freshly built test binary hangs at exec (syspolicyd at 100% CPU), so no darwin test run. go vet -tags nogui for darwin, GOOS=linux and GOOS=windows and gofmt -l pass. Not tried against a real Devin account.
The same fix plugin 0.1.12 makes, for the built-in's buildDevin: Devin
answers every request with temperature or top_p exactly 0 with 400 "an
internal error occurred (trace ID …)", on every model; 1e-6 goes through.
Any other value goes as it came, and none still as Devin's defaults
(1, 0.95).
Verified: TestDevinSamplingZero fails on the old devin.go ("temperature
0: temperature 0 top_p 0.95, want 1e-06 0.95", likewise top_p 0 and -0)
and passes with the change. It also catches top_p left unchanged and
every value under 0.5 sent as 1e-6. Devin's behaviour was checked live
on a real account through the plugin's request, which carries the same
field 8 (0 → 400 on swe-2 and claude-sonnet-5-5, 1e-6 → 200); the
built-in path itself wasn't run against Devin. go vet (darwin, linux,
windows) and go test -tags nogui ./internal/gateway pass in a sandbox
HOME.
An Anthropic request may send one turn's tool_use blocks in consecutive
assistant messages, answered by one user message. buildChat's
pairToolMessages, cursorMessages and buildDevin each closed the first
message's calls at the second one: the calls were answered "interrupted"
and the real results went out as a stray user message (Chat) or were
dropped (Cursor, Devin). joinSplitCalls now joins an assistant message
onto an assistant message before it that made tool calls, as Anthropic
reads them, so the calls are pending together. Responses, Messages,
Kiro and Gemini/Code Assist already kept the results.
Tests (split_calls_test.go): Chat, Cursor and Devin split cases fail on
main and pass now; a truly unanswered call of a split turn still gets
the synthetic result; text after a call in its own message; two text-only
assistant messages unchanged; Responses guard.
Claude Code tells the allowance in its rate_limit_event, not as headers, so
magpie says what it keeps of the account again as Anthropic does: a share
0-1 and a Unix-seconds reset per window, set as the request comes in and
again as the reply begins, after the turn's own event.
Claude Code 2.1.293 reads them only when it is signed in to claude.ai (the
sign-in field's claudeai); with magpie's key it ignores them.
Run: go test -tags nogui ./... (temp HOME); the two new tests fail without
limitHeaders; GOOS=linux/windows go vet of gateway and provider; real
Claude Code 2.1.293 in a sandbox HOME against a fake server sending these
headers: its statusline stdin had rate_limits.five_hour/seven_day with
used_percentage 42/17 when OAuth-signed in, none with ANTHROPIC_AUTH_TOKEN.
Not run: a real Claude account through a running magpie.
The IR held a schema only from Anthropic's output_config.format, and only
Messages (and Claude Code's --json-schema) were asked for one. A Responses
request to a provider magpie speaks Chat or Messages to (OpenRouter has no
Responses URL) lost text.format; a Chat request translated to Responses or
Messages lost response_format; an Anthropic schema translated to Chat or
Responses was lost too.
Format (format.go) now carries json_schema (name, description, schema,
strict) or json_object from Responses, Chat, Anthropic and Gemini, and each
builder asks for it in its upstream's field. Where a target can't say it
(json_object on Messages or Claude Code; the vendor bridges Cursor, Devin,
Kiro, Qoder, Command Code, Zed) it is told in the system prompt. An upstream
answering 400/422 naming the field (DeepSeek's "This response_format type is
unavailable now") is asked again with it told in words, and so from then on.
Relayed requests are unchanged.
buildDevin folds every offered tool's parameters through objectSchema
(provider.ObjectRoot, as anthropic.go does for #646); a schema with no root
combinator goes byte for byte as it came.
TestBuildDevinObjectRoot builds from #1196's literal parameters with oneOf,
anyOf and allOf; without the devin.go change it fails ("oneOf: sent {...
oneOf ..."). TestObjectRootKeepsOwnRequired fails on the old ObjectRoot with
"required = [id n]" (allOf's "kind" dropped). Run: go test -tags nogui
./internal/gateway ./internal/provider (temp HOME, pinned caches), both ok;
GOOS=linux and GOOS=windows go vet -tags nogui on both packages, ok. Not
tried against a real Devin account.
A tool_result that holds only an image (Claude Code's Read on a PNG) reached
Devin as "(no output)": buildDevin read the result's text and never its
Images. Carry the ones that hold bytes on the tool message; Devin takes no
URL.