4794de398ea8337d223a91e207181c56fcf4ad76
10
Commits
| Author | SHA1 | Message | Date | |
|---|---|---|---|---|
|
|
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.
|