ac4af582301a4e8a29245dbba767eba31334ddf9
14
Commits
| Author | SHA1 | Message | Date | |
|---|---|---|---|---|
|
|
137187a401 |
gateway: Claude Code's auto mode classifier follows a /model switch at once
CyberCaius on Discord: after switching models, the first auto mode permission check went to the previous model. The model is Claude Code's choice, not magpie's. Claude Code 2.1.310 ($Xe/BB) names ANTHROPIC_DEFAULT_SONNET_MODEL for the classifier, not the session's model. magpie's sonnet tier follows the main model only once Follow runs (the GUI's state poll), and Claude Code reads env again only on its next start. So right after /model the classifier named the old main model. At the gateway, a classifier request (recognised from its body: a <transcript> and a <block>/<severity> verdict, no tools) on a sonnet tier that follows a main model settings.json no longer has goes to the tier the new main model gives it (followAt, keeping the tier's effort). It is left alone when the user set CLAUDE_CODE_AUTO_MODE_MODEL, when the sonnet tier is their own, when the base URL isn't magpie's, or when the main model hasn't moved. WSL distros are read the same way. Only the classifier is rerouted: a turn naming the old model may be another open session that is still on it. The haiku, opus and subagent siblings are #3474. Run (sandbox HOME; packages at |
||
|
|
c8901d4723 |
gateway: auto mode's classifier asks a model of unknown levels for no reasoning
CyberCaius on Discord (#help): in Claude Code's auto mode every
classifier request ended 499 in magpie, on a new-api relay's
gpt6.1-sol (an OpenAI-compatible provider the user added), v0.1.1364.
Cause (likely; not confirmed against the reporter's relay): Claude Code
2.1.310 sends the classifier as a non-stream sideQuery, thinking off or
left out, 64 (or 2112) tokens, and waits 60s an attempt for it (WWt in
the bundle; 120s cap on large prompts). fitAutoModeClassifier asked for
the least reasoning only when magpie knew the model's levels. For a
relay's own name it sent no reasoning_effort / reasoning.effort, so a
reasoning model reasoned at its vendor's default over the whole policy
and transcript. That ran past Claude Code's wait, and Claude Code
closed the request (499).
Change:
- automode.go: with the levels unknown, the classifier is asked for
effort none, marked as magpie's own ask (Request.OwnEffort).
- gateway.go forwardTranslated: a 400 to that own effort
(ownEffortRefused) is asked again. If it named the level, it is
asked at low (offRefused). If it named the field ("Unrecognized
request argument supplied: reasoning_effort", "Unsupported
parameter: 'reasoning.effort'"), it is asked without the effort, as
before. Either is remembered in unfit until restart. Only the
classifier gets OwnEffort, and no other request changes.
- docs/subsystems/gateway-routing.md: a bullet on the local
classifier.
Run:
- TestAutoModeClassifierReasonsLeastOnAnUnknownModel covers Chat and
Responses, non-stream, thinking off/64 and left out/2112. It is red
on the old code: no effort was sent in any of the four cases.
- TestAutoModeClassifierEffortRefusedGoesWithout covers a named level
going to low, and the Chat and Responses field refusals going
without. Each next ask takes one request.
- TestAutoModeClassifierOnlyTheClassifier now expects none for unknown
levels (the
|
||
|
|
ccbc727818 |
agent, gateway: a Claude model magpie can only ask translated no longer keeps auto mode's server review on (nexnull on Discord)
nexnull (Claude Code 2.1.308, magpie v0.1.1318, DeepSeek 4.1 flash) saw
Claude Code's notice that auto mode's classifier "isn't eligible because
your requests go through 127.0.0.1:3425". The wiring leaves
CLAUDE_CODE_AUTO_MODE_SERVER unset while any model Claude Code can reach
through magpie is reviewed (claudeReviewed), and it judged that by
AutoModeReviewed, which counts a Claude model by its name. A relay that
lists claude-* beside DeepSeek with only a Chat (or Responses) URL, or a
Claude model the user pinned to chat, is asked translated: a probe showed
such a request goes to /v1/chat/completions with no safeguards and no
safeguard_results. So the review stayed on and the notice showed.
AutoModeReviewable (gateway/automode.go) is AutoModeReviewed on a route
that reaches the Messages API: the Claude subscription, or a provider
with an Anthropic URL whose APIs for the model (a user pin first) include
Anthropic. claudeReviewed asks it for the provider and each fallback, so
Claude Code and T3 Code get CLAUDE_CODE_AUTO_MODE_SERVER=0 there. It is
still magpie's own stashed value (claude.auto_mode_server): a user's own
value is left alone, and disconnect or restore takes magpie's off.
serverReview, already on the Messages route, keeps AutoModeReviewed.
Chosen on purpose: any reachable model that is really reviewed keeps the
review on. Writing 0 by mistake would lose server review on Claude
silently, while leaving it on by mistake costs the notice, which Enter
dismisses for 24h. A relay with an Anthropic URL (OpenRouter, AiHubMix)
still counts as reviewable, since some pass the field through. No
client mimicry and no prompt or identity text changes.
Pass-through on Anthropic routes (asked in the same task): no defect.
Probes against a fake upstream showed the anthropic-beta (with
dangerous-tool-use-2026-09-03) and anthropic-version forwarded, the
safeguards body byte-identical, a stream:false reply relayed byte for
byte with safeguard_results and an unknown key intact, and the SSE relay
keeping an unknown key, an unknown event type and toolu ids. The probe
file was removed and is not committed.
Full run at 983425662, the same change one commit back:
- gofmt -l: clean. go vet ./..., GOOS=linux go vet -tags nogui ./...,
GOOS=windows go vet ./...: ok.
- set -o pipefail; go test -timeout 45m ./...: EXIT 0, 68 packages ok,
no FAIL (internal/agent 386s, internal/gateway 507s), run alone after
another session's suite ended.
- TestAutoModeReviewableAsksOnMessages and
TestClaudeReviewedOnlyWhereMessagesReachClaude are red on the old code
("cr/claude-sonnet-5: true, want false"; "a relay without an Anthropic
endpoint: \"\", want 0").
Rebased then onto
|
||
|
|
6690caaaec |
gateway: auto mode's review isn't asked of another subscription's Claude model, and Claude Code's set model is judged where it goes
Claude Code 2.1.302 tells a session behind magpie "this session isn't eligible because your requests go through 127.0.0.1:3425" and points the gateway at code.claude.com/docs/en/auto-mode-classifier-billing. That page asks a gateway to forward the dangerous-tool-use-2026-09-03 beta and the top-level `safeguards` field, and to return `safeguard_results` (message_delta.delta in a stream) with tool-use ids unchanged; one that can't should have clients set CLAUDE_CODE_AUTO_MODE_SERVER=0. magpie already does this on every route Anthropic answers (Claude subscription bridge, api.anthropic.com, relays, Bedrock, Vertex) and writes the 0 when no reachable model is reviewed ( |
||
|
|
5b14ebf49a |
gateway: a Claude subscription run is told the user's words after a tool result as theirs, not the tool's (#1878)
JinJieBeWater found that Claude Code's AgentSummary label request ("Describe
your most recent action in 3-5 words. Do not use tools.", sent as a text
block after the sub-agent's last tool_result) reached the inner Claude as
tool output, so it went on with the task instead of answering the label.
Two paths had it:
- renderParts (a run started anew, or a resumed turn) wrote the text right
after the tool's last line. A text or file part after a tool result in the
same message now closes it with "[end of tool result id=…]" and is marked
"[user message]". A result followed by nothing or by another result is
told as before, so existing prompts and their cache prefix don't change.
- match folded the text into the last result, and continueWith handed it to
Claude Code as the MCP result. It no longer folds; saidWithResults takes
the words, and continueWith writes them to Claude Code's stdin as a user
message before handing the results over, waiting for Claude Code's
command_lifecycle "queued" for that uuid (2s at most). Claude Code then
tells its model the message with the result as one the user sent while it
worked, in the same turn.
Going on in the run, rather than starting a new one for such requests, keeps
the cache prefix (#1716/#1717) and #872's mid-turn messages, which use the
same shape. #872's text is now queued as the user's instead of appended to
the result. Words in a message that holds images (pi-ai's "Attached
image(s) from tool result:" captions) still fold into the result, decided by
the message's parts, not its text. A tool whose output says "Do not use
tools." keeps it inside its result. The fork test's fake Claude now models
mid-turn absorption the way Claude Code does.
Run: gofmt -l; go vet on darwin, linux (-tags nogui), windows for
./internal/gateway; go test -tags nogui ./internal/gateway/ -count=1 green;
-race -count=3 on the new tests. Broken by hand, each red: no end marker;
an end marker after every result; the words not passed to continueWith; the
old fold into the result; the words queued after the result is handed over.
Real Claude Code 2.1.296 driven through the gateway in a sandbox HOME
against a local mock of Anthropic: on continuation the next request's
tool_result holds "SOURCE_LAST_LINE" then the "user sent a new message
while you were working" reminder with the label request; on a new run the
prompt holds the closed result and "[user message]".
Not run: the owner's real Claude subscription (its credentials are in the
Keychain, off-limits here), so the real model's answer to the label isn't
seen; Windows tests; the full ./... suite.
|
||
|
|
24350a3722 |
agent, gateway: Claude Code on a model Anthropic doesn't review gets auto mode's server review turned off, so it no longer says magpie isn't eligible (1EFLOPS on X)
1EFLOPS runs Claude Code through magpie on Codex's gpt-6.1-sol. In auto mode, Claude Code 2.1.296 says "this session isn't eligible because your requests go through 127.0.0.1:3425 ... ask your gateway to implement https://code.claude.com/docs/en/auto-mode-classifier-billing". What the page asks of a gateway: pass the anthropic-beta header (dangerous-tool-use-2026-09-03), the request's `safeguards` field, and `safeguard_results` in the reply through unchanged, and leave tool-use ids alone. The results are verdicts from Anthropic's own safety classifier. For a gateway that can't provide them, the page's remedy is CLAUDE_CODE_AUTO_MODE_SERVER=0. Pro, Max and Team plans never see the notice. In the bundle, Claude Code falls back on server_unsupported, server_unavailable_disabled or server_no_result, and the notice shows whenever there's no real verdict. Only that variable removes it. Per route: - Claude subscription bridge, Anthropic API key, relays in front of Anthropic, Bedrock and Vertex: already pass the beta, `safeguards` and `safeguard_results` through ( |
||
|
|
8c21a41846 |
gateway: auto mode's server review reaches Claude alone, and its verdict comes back on every route (lc on Discord)
lc saw Claude Code's notice that the session isn't eligible for the free server-side auto mode classifier "because your requests go through 127.0.0.1:3425". Claude Code 2.1.295 sends the dangerous-tool-use-2026-09-03 beta and a `safeguards` field, and reads `safeguard_results` from every reply (a stream's message_delta, a whole reply's top level). A reply without them latches the session to the local classifier and shows the notice. What changed: - serverReview (automode.go), called from forwardOnce, so passthrough, count_tokens and the translated path alike: a body naming a model that isn't Claude (DeepSeek's, Kimi's Anthropic APIs) goes without the beta and without safeguards. AiHubMix answers them with 400 "safeguards: Extra inputs are not permitted"; DeepSeek ignores them. A provider that turned the beta away (remembered by s.betas, e.g. Bedrock's "Unexpected value(s)") gets no safeguards either. Claude, a body with no model (Bedrock's path) and api.anthropic.com keep both as sent. - anthropicWholeEvents: a whole reply streamed after keepalives put safeguard_results in message_start, where Claude Code doesn't read it. It now goes in message_delta.delta. - buildAnthropic sends safeguards to a claude-* model; decodeAnthropic carries delta.safeguard_results to the encoder, which already wrote them. Tool ids are left as they were on every path. - magpie does not write CLAUDE_CODE_AUTO_MODE_SERVER=0 for other vendors' models: /model can move the same session to a Claude model behind the gateway, and the setting would hide its eligibility there. Said in automode.go's header comment. How magpie presents itself is unchanged. Tests use Claude Code 2.1.295's captured beta header, an object classifier_context and the status.available.tool_uses verdict shape. TestAutoModeReviewOnlyForClaude, TestAutoModeReviewGoesWithItsBeta, TestAutoModeReviewOfAWholeReplyStreamed and TestAutoModeReviewTranslated each fail with the source changes reverted (400 from the vendor, verdict in message_start, safeguards dropped to Claude / verdict not given back). Run: gofmt -l; go vet, GOOS=linux and GOOS=windows go vet -tags nogui ./internal/gateway; go test -tags nogui ./internal/gateway (ok, 191s) under a scratchpad HOME. End to end: real Claude Code 2.1.295 -p --permission-mode auto under a sandbox CLAUDE_CONFIG_DIR, through this build's gateway on 127.0.0.1:3563, to a fake Anthropic API answering with safeguard_results: on ant/claude-sonnet-5 the beta and safeguards reached the fake, Bash ran on the server verdict and no notice was shown; on ds/deepseek-flash neither reached the fake and Claude Code classified locally with the notice, as designed. Not run against Anthropic's real API: no first-party Anthropic key was available. |
||
|
|
2b5f19fc73 |
gateway: a request whose tool results another request already answered (Claude Code's fork sub-agents and their lead, a turn sent again) gets a Claude Code run of its own instead of a 409 "the agent's turn is already being resumed" (ylorn on Discord)
A Claude Code fork sub-agent's first request is its lead's conversation
with a result for each of the lead's in-flight calls ("Fork started —
processing in background") and its directive after. The lead's own resume
and every fork it started therefore match the same run at once; the first
to claim it won and the rest got a terminal 409 that Claude Code does not
retry, so the forks died. The 409 dates from
|
||
|
|
06420a7121 |
tests: a fake program is a file macOS has already let run (testenv.Program), so a fake's first start no longer eats a test's wait under load
macOS checks a newly written executable before its first exec: 0.27s alone, 2-5s while other new programs start (a go test ./... starting its test binaries). The same file again takes 0.009s, and the pass is kept across a rename and an in-place rewrite. |
||
|
|
bd456fa51e |
fix: keep Claude continuations and routing stats bound to accounts (#854)
* fix(gateway): bind Claude tool-result continuations to their account * fix(gui): keep routing statistics on stable account identities |
||
|
|
e8cd4bac8c |
fix: 透传 Claude 订阅审批上下文与服务端结果 (#794)
Co-authored-by: yizhuolin <yizhuolin@i-calorie.com> |
||
|
|
8026e3ce15 | claude: Claude Code's auto mode checks read their prompt from the cache, and a request with thinking off runs with it off (0xAncientTwo on X: Claude 额度在 magpie 下掉得特别快) — behind a gateway Claude Code's auto mode classifier is a request of its own for each action it checks, billed to the subscription (on Claude Code's own sign-in Anthropic runs it server-side), with a ~37k-token security-monitor prompt. Its system starts with x-anthropic-billing-header: cc_version=….<hash>, the hash taken from the request's first user message, which for the classifier differs on every check; the bridge put the system, header first, into the cached instructions block, so every check wrote all ~37k tokens to the cache again (2x the input price at the 1h TTL) and read 2303. renderClaudePrompt now leaves the header out (Claude Code's runs send their own). Claude Code's small asks and its classifier also send thinking disabled, and the bridge ran them at Claude Code's default, which on Haiku thought 1.8k–5k output tokens before a 64-token verdict or a title; a request with thinking off now runs with --thinking disabled, and that is part of the run's key, so it never resumes a run that thinks or the other way round. With the owner's real Claude subscription, the captured classifier request replayed twice with two hashes: on origin/main each check wrote 36482 and read 0; now the second wrote 343 and read 36086 (Sonnet 4.6, 10 tokens out). On Haiku 4.5 a check had 2599 reasoning tokens before and 0 now. TestClaudeInstructionsWithoutBillingHeader and TestAutoModeClassifierOnTheClaudeBridge's --thinking disabled check fail on the old code; the gateway's TestClaude* and TestAutoMode* pass. | ||
|
|
b9895c2ded | tests: the gateway's and Devin's tests run on Windows in a home of their own — on Windows os.UserHomeDir reads USERPROFILE, not HOME, so a test that set HOME to a temp dir still found the one USERPROFILE every gateway test shares (and the box's real agents); Devin's CLI keeps its sign-in under APPDATA. Each such test now sets USERPROFILE with HOME (setHome), TestDevinOwnMovesWithPlan sets APPDATA, and the tests whose Claude Code is a shell script skip on Windows, where it can't run and the box's real claude ran instead. Tests only. The gateway suite and TestDevinOwnMovesWithPlan pass on Windows; go test -tags nogui ./... passes on macOS. | ||
|
|
7a3337dd25 |
gateway: Claude Code's auto mode classifier gets an answer through magpie on models that reason, and never lingers as a kept Claude Code run (#250 netfishx: the classifier often fails; Claude Code notes the session "isn't eligible" for free classifier requests through 127.0.0.1:3425) — per code.claude.com/docs/en/auto-mode-classifier-billing and Claude Code 2.1.285, behind a gateway its first requests ask the API to classify (the dangerous-tool-use-2026-09-03 beta, a safeguards field, safeguard_results in the reply); keyed Anthropic already relays them as sent and returns the reply as it came (now guarded by a test), and no other model answers them, so Claude Code falls back to classifying locally: a request of its own on the session's model, the transcript in <transcript> blocks, a system prompt asking <block>yes|no</block>, thinking off, 64 tokens for the first stage stopping at </block>, 60s. A model that reasons whatever it is told (OpenAI Responses/Chat, DeepSeek, a vendor's model behind an Anthropic API) spent the 64 tokens reasoning and answered nothing, which Claude Code reads as no verdict and blocks. Now (automode.go) such a request to a model that isn't Claude gets 2048 tokens more when it asked for less, as Claude Code gives a Claude model that can't turn thinking off, and the least reasoning its levels allow (fitEffort "none"), left to the vendor when they aren't known; a Claude model's request goes byte for byte. Through the Claude subscription the classifier, whose transcript spans several user messages, was kept as an idle claude run (the one-off test was fewer than two messages), pushing out the conversations' own: a request with no tools and no reply is one-off now, and the classifier runs at --effort low. magpie never answers safeguard_results itself. Tested in automode_test.go against httptest fakes and a fake claude: Responses and Chat (budget raised, effort none/low), unknown levels (room given, effort left, a title ask untouched), a vendor on an Anthropic endpoint, the bridge (no idle runs, --effort low) fail on main; TestAutoModeServerSideReviewRelayed keeps the beta, safeguards, safeguard_results and tool-use ids as they are. go vet ./internal/..., go build -tags nogui (and GOOS=linux, GOOS=windows) and go test -tags nogui ./... pass. Not tried in a real auto-mode session nor with real vendors taking effort none.
|