Files
magpie/docs
ggbdpqandyetone 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 ddb1701fe): go test -tags nogui -count=1
  -timeout 45m ./... , 81 packages ok, no FAIL (gateway 755s). Other
  sessions' suites ran on mote at the same time (load ~20 to 30).
- Rebased on 2f65a33aa (gateway.go and providers-accounts.md changed
  upstream, in unrelated lines): gateway, provider, plugin and library
  rerun with -count=1 -timeout 45m, all ok.
- Then rebased on a0cb8b646 (Ark web search, gateway.go): go vet and
  -run 'TestClaude|TestAutoMode|TestExtraBody|TestHeaders|TestAudit|
  TestServerReview|Ark|Search' on gateway and provider at the pushed
  head, ok.

Not tried: a real Claude subscription A/B of the classifier's cache
reads (it would spend ~170k tokens a turn on the owner's live account);
the gain rests on the offline repro's block counts.

Fixes #3835

Co-authored-by: yetone <yetoneful@gmail.com>
2026-10-30 22:48:39 +08:00
..