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.