Files
magpie/internal/redact
yetone 50f52b540b redact: a text masked for a vendor before is masked as it was then, so a cached prompt stays cached
With Privacy masking on, a value masked once is "known" and masked
wherever a later request has it (redact/known.go). When a rule first
finds a value in a later turn (a tool printing DB_PASSWORD=...), that
value was masked from then on in the system prompt and the turns already
sent with it as written. The prefix the vendor had cached changed, so
the whole prompt was written to the cache again and none of it was read.

Reported by audie on Discord: DeepSeek Harness on a routing group served
by a custom Anthropic-compatible provider. Adjacent turns 10s apart had
cache_read 0 and cache_write 412K to 427K.

Fix: Mask and MaskJSON (the vendor-bound paths, via masking.Masker) now
use sentKnownSpans. A text masked before gets the known values it had
the first time, keyed by a sha256 of the text and the options. Only
hashes and spans are kept, never a value, in two generations of 65536.
New text still gets every known value masked. Scrub (archives, sessions,
OTel; local only) keeps the latest known set.

Unchanged: if magpie restarts, or a text falls out of both generations,
the text is masked under the current known set once, as before.

What was run:
- internal/redact TestSentTextKeepsItsMasking and internal/gateway
  TestMaskedConversationKeepsItsCachedPrefix. The gateway test sends a
  dsh-shaped Chat Completions conversation to a group with an Anthropic
  member, and a Claude Code-shaped /v1/messages one. It checks that each
  turn's system, tools and earlier messages reach the fake upstream byte
  for byte. Both tests are red with sentKnownSpans forced back to
  knownSpans: the system prompt became "{{SECRET_...}}" on turn 3. Both
  are green with the fix.
- With masking off, a probe of the same dsh shape had the system, tools
  and earlier turns byte-identical on every turn.
- gofmt -l: clean. go vet: darwin, GOOS=linux -tags nogui ./...,
  GOOS=windows ./...: clean.
- Full suite at 8187919d7 (this tree, on origin/main bf2e067ef):
  set -o pipefail; go test -tags nogui -timeout 45m ./..., through the
  suite lock. 69 packages ok, none red (gateway 519s, agent 393s).

Not tried: audie's real setup. Their Privacy setting isn't known; with
masking off this is not the cause, and every breakpoint reading 0
(even the unchanged system block) points at the provider's own cache or
pool. Not tried against a real Anthropic or relay account. GUI not
touched, so the GUI suite was not run. Windows tests not run.
2026-10-23 20:53:53 +08:00
..
gateway: a request archive, off unless turned on, keeps each call's headers and bodies in the user's own S3 bucket and a recent call reads its own back (Jorben on Discord: 请求存档) — the Gateway page's recent calls only ever held the last bodies in memory, the first 256 KB of each, with no headers, gone at a restart. A switch over Recent calls ("Request archive", POST /api/settings/archive, settings' requestArchive) turns it on, refused with a reason while sync isn't set up with an s3:// bucket; with it on, each call the gateway serves gets an id (UTC HHMMSS-<16 hex>, said back in X-Magpie-Archive-Id) and, once it is recorded, its method, path and query, request headers and body and response status, headers and body go as one JSON file to <prefix>/magpie/archive/<YYYY-MM-DD>/<id>.json in the bucket sync keeps its backup in, signed with the same client (davsync.Bucket, no new SDK). Before anything leaves, Authorization, x-api-key, Cookie, Set-Cookie, any header or JSON field or query parameter named for a key, token, secret or password, and anything that looks like a key or token anywhere in the text (the redaction rules' patterns, in a stream's data lines too) become [REDACTED] — gone, no placeholder kept; the archive is plain JSON, readable in the bucket, not sealed with the passphrase. Uploads go one at a time on their own goroutine from a queue of 16 calls, each body capped at the 256 KB the call already keeps and marked truncated; a full queue drops the call with a log line, a failed upload is logged and shown under the switch until the next one goes, and no request waits on any of it. A recent call the archive kept shows its date and id under its bodies, and "Fetch from archive" (GET /api/archive?date=&id=, only a date and an id of that shape) shows the request's and response's headers and bodies as the bucket has them, or says it isn't there yet. The hook is in record() and the Call literal, so PR #239's request log lines are not touched; the archived call carries its usage, and with #239 its vendor request id. Only calls through serve() are archived, not Codex's backend, image or video calls. TestArchiveOn, TestArchiveOff, TestArchiveName, TestRequestArchiveToS3 (a real gateway request through the signature-checking fake S3), TestScrub and request-archive.test.cjs fail without the change; TestSettingsSaveKeepsWhatItDoesNotSend now sets requestArchive. A sandbox magpie web with a fake vendor and a fake S3 server uploaded nothing while off; on, it uploaded a signed archive with none of eight planted secrets in it, read it back through /api/archive and in the page, and with the S3 server down served the call in 0.1 s and said why the upload failed. go vet, go build -tags nogui (darwin, GOOS=linux), GOOS=windows go build, go test -tags nogui ./... pass (Claude account tests and TestClaudeRunEndsWhenTheClientLeaves pass alone); request-archive, click-scroll, old-webkit, sse-body, gateway-fold pass.
2026-10-01 17:13:34 +08:00