ac4af582301a4e8a29245dbba767eba31334ddf9
9
Commits
| Author | SHA1 | Message | Date | |
|---|---|---|---|---|
|
|
9a92fd099b |
claude: a long auto mode classifier keeps its cache marks as claude -p (#5585, #5655)
With Claude Code's interactive mode on, the classifier was pasted into a new run each call with none of its marks: Claude Code marks only the last block of what it is pasted, and the classifier's tail changes every call, so each call read only Claude Code's own prompt and wrote the whole transcript again (126K and 132K a call at 1h's 2x in iamnil's rows). Desktop's header-less classifier lost its marks at parse time ( |
||
|
|
dca338f3a3 |
gateway: a relayed Claude run keeps its cache as long as the request's own marks ask (Linka)
v0.1.3247 ( |
||
|
|
dbc74414bb |
claude: a relayed run keeps its prompt cache as long as the user picked, not always an hour
linkaww (Discord #feedback, server v0.1.3237 in Docker, Claude Code 2.1.319) set the Agents page's prompt cache for the main conversation and subagents to 5 minutes, and settings.json had "5m", but 237 of 241 relayed requests since 11-01 wrote an hour's cache. cleanClaudeEnv took CLAUDE_CODE_PROMPT_CACHE_TTL out of the run's environment and put back "1h" every time ( |
||
|
|
498b6419ff |
claude: a turn Anthropic refuses in the interactive mode as a third-party app's is asked again as claude -p, and the agent's prompt is remembered
Raven (Discord #general): Cindy with Pi as its engine, routed through
group/auto to a Claude subscription, failed every turn with "Anthropic
refused an interactive-mode turn on claude-opus-5-5 as a third-party
app's", and the message told them to turn the interactive mode off in
Settings, which makes every request of every agent run as -p (about twice
the plan count).
Now, with the interactive mode on:
- a refusal carrying "Third-party apps now draw from your extra usage",
met before a byte of the reply reached the client (stream head, or a
whole reply with no parts), is asked again once as claude -p
(redoAsPrint); the client sees only the -p answer;
- the agent's system prompt (sha256 of its first 2KB, billing header
dropped, so Pi's trailing <cwd> doesn't change it) is remembered for
12h, and its next turns go straight to -p (wantTUI, req.tuiRefused,
clientCache.print) while every other agent stays interactive;
- a refusal after the reply had begun (keepalive sent, or text said) is
not redone, so nothing is spent twice; the prompt is still remembered
and the message now says magpie runs its next turns as -p: ask again;
- a -p run that is refused too fails as before ("run as claude -p"),
once, no loop;
- the setting is untouched; with it off (claudePrintMode) everything is
-p as before. The run is the real claude binary, nothing else changed
in what is sent.
This reverses the #4503 call (
|
||
|
|
9f17ad4c12 |
claude: the interactive mode takes safeguards and a client's cache marks
With the interactive mode on, nothing runs as -p any more (
|
||
|
|
81245e6cf6 |
gateway: a translated Messages ask keeps the cache marks its client put on it (#4571)
A plugin account only streams, so a client's whole-body Anthropic
Messages ask is translated: parsed into the request, built again for the
upstream, asked streamed and its answer assembled into one Message JSON.
The parse read none of the cache_control the client had put on its
blocks, and the build set its own marks — the system and the last block
of the last message, five minutes long. A client that marked the end of
its history, as Claude Code's auto mode classifier does, found that
boundary gone from the rebuilt body: the next turn, its history grown by
a block or two, matched only the fixed prefix up to the system block and
wrote the whole transcript again, and every write went out at five
minutes where the client had asked for an hour. The same ask with
stream:true is relayed as it came and shows none of it.
A translation of Anthropic's own now reads the request with its marks
(#3835's path) and the rebuild keeps them: a block the client marked is
marked again, the tail and the system take the client's ttl, and none of
magpie's own are added, so the mark that moves on with the history
stands at the same block the next turn. A mark on thinking, which
Anthropic does not mark, and one on a block the rebuild drops, are left
out. A set that fails the checks any Messages request must pass goes the
default way, its marks dropped as before, not refused with a 400 the old
translation never gave.
Run (macOS):
- Red before, green after: TestPluginWholeAskedKeepsTheClientCacheMarks
(the boundary unmarked and both marks ttl-less on main, the client's
blocks otherwise kept 1:1), TestPluginWholeAskedServesBadMarksAsBefore
green before and after.
- go test -tags nogui -count=1 ./internal/gateway: ok.
Issue #4571
Generated-by: GLM-5.3-Flash (ZCode)
Broken by hand: with the anthropic.go hunks reverted,
TestPluginWholeAskedKeepsTheClientCacheMarks is red: the boundary is
unmarked, and the tail and system are ttl-less. Matches devin plugin
0.1.29 (
|
||
|
|
e31ccf2307 |
gateway: a classifier's own cache marks are kept, and a moved mark leaves its old block boundary in place (#3835)
Claude Desktop's auto mode classifier marks its transcript blocks with
native cache_control but sends none of magpie's private headers, so
serveSubscription took the default parse and the marks were dropped.
And even a request that opted in lost its older boundaries:
renderCachedParts ended a block only where a mark still stood, so a
mark that moved on with the conversation's growth let the block it
used to end merge into the next marked one. Anthropic's prefix check
looks back over block boundaries, not into them: the boundary gone,
each classifier turn found none of the last one's write and wrote the
whole transcript again (about 170k tokens a turn at the reporter's
site).
A part that came from one of the client's own content blocks now ends
its rendered block whether or not it still carries a mark; only the
mark's presence adds cache_control. A classifier-shaped Messages body
carrying cache_control is parsed for its marks like an opted-in
client's. Plain-string messages still merge into history chunks, so a
retained prefix reaches as far back as it did.
Changed from ggbdpq's patch: the classifier never asked for its marks
through X-Magpie-Cache-Marks, so a set the bridge can't keep (a TTL
order Anthropic refuses, more than four marks) now goes the default
way, as before, instead of being refused with a 400 that the old code
never gave. TestClaudeClientCacheClassifierBadMarksServedAsBefore
holds it. The bridge doc says so.
Run (mote, macOS):
- Red on origin/main (the reporter's offline repro, renamed beside the
other client-cache tests): client_marks 6 -> 6 blocks with 307
reusable bytes, as the issue reports; the classifier's marks dropped
without the header.
- go test -tags nogui -count=1 -run 'TestClaudeClientCache|TestAudit|
TestClaude|TestAutoMode|TestServerReview' ./internal/gateway: ok.
- Broken by hand: the fallback removed, the new bad-marks test red
("refused before run startup: 400 ... a ttl='1h' cache_control block
must not come after a ttl='5m'"); restored, green.
- gofmt -l clean. go vet (darwin, GOOS=windows, GOOS=linux) ok on
gateway and provider. Full suite at b80d1ba7b (this commit, on the
#2937 one, rebased on
|
||
|
|
ec64543952 |
claude: a switch gives a Claude subscription's run the agent's instructions as its system prompt, in place of Claude Code's
Every request through a Claude subscription is answered by the real
Claude Code, which sends its own system prompt, with the agent's
instructions in the run's first user message. Settings › Replies › Short
Claude system prompt (claudeLeanPrompt, off by default) starts the run
with --system-prompt-file holding the agent's instructions instead
(without a client Claude Code's billing line, plus the tool-choice
line), and the first message holds the conversation alone. The file is
under the distro's mount in WSL. A request with client cache marks
(#1717) is never lean. The mode is part of the run's identity, so a run
started in one mode never takes the other's turns. The row says the
risk: requests look less like Claude Code's own.
Measured with a real Claude subscription, Sonnet 5.5, Claude Code
2.1.301, off then on:
- chat client, ~600-token prompt, 2 tools, 3 turns: 10,048 -> 6,580
input tokens (-35%)
- claude -p as the client, Read and Bash, 4 requests: 85,453/85,471 ->
81,948/81,977 (-4%)
A fixed ~0.9-1.2K tokens a request.
Run at this head (rebased on
|
||
|
|
d9e87eb328 |
gateway: clients opt into Claude subscription cache marks and TTLs (#1717)
Problem: Messages clients need control of cache boundaries and TTLs when a Claude subscription answers. Ordinary clients must retain their run identity, prompt and environment. A routing group's API-key member keeps its marks and must not report the subscription bridge's drops. Change: Select client-owned marks only with X-Magpie-Cache-Marks: client. Map system and fresh-history boundaries and the request tail, default missing TTLs to 5m, validate slot and TTL order, and separate opted-in run identities. Retain prefix constraints across live and saved runs. Report unmappable marks only for the Claude subscription try. Bound its selection hold to two seconds and clear the report and hold for a non-Claude fallback. Check ordinary identity bytes without a version-specific hash golden. What was run: Sandbox HOME, nogui: go vet ./... on darwin; gateway vet with GOOS=linux and GOOS=windows; full gateway tests; focused cache and usage tests with -race. gofmt and git diff --check passed. The group probe failed before the fix with tools:1 on the API-key reply in both routing orders and both stream modes. Hand-broken candidate scoping, stale report clearing, keepalive holds and ordinary identity bytes each failed behavior tests. Live, Claude Code on a Claude subscription and an Anthropic API key, through a recording proxy: in a group whose API-key member answers, in either order and both stream modes, the reply has no dropped-mark header and upstream receives the tool mark; a Claude answer reports tools:1; a failed Claude try followed by an API-key answer leaves no report. With a delayed API-key reply, the group's first keepalive came 0.85 s after a direct request's. Without the header, the outgoing request equals one from a gateway built at the same base. No GUI or real Linux/Windows execution. |