Files
magpie/internal/maskrec
yetone b904cc22bf maskrec: the latest requests' bodies are kept zstd in memory, in 32 MiB (#2278)
The 脱敏 page shows a recent request as the vendor got it, so memory
kept the latest 100 bodies whole, up to 64 MiB. apple-ouyang's heap
profile on #2278 had gateway.sentOf holding 64 MB of them, a sixth of
the live heap, kept for a page that is rarely open.

Each body is now compressed (zstd, fastest, outside the store's lock)
as Hold takes it, held apart from the record, and decoded only when
SentOf asks. The budget counts stored bytes and is halved to 32 MiB:
a request carrying a screenshot's base64 hardly compresses. On real
local session files zstd -1 makes Claude Code's text 4 to 5 times
smaller, and a Codex rollout with screenshots 1.4 times.

Records in memory no longer hold a body at all, so Get has nothing
to clear.

Run at this tree (rebased on origin/main 97b6a36c5), on mote:
- go vet -tags nogui for linux, windows, darwin: ok (maskrec, gateway)
- go test -race ./internal/maskrec: ok
- go test -race -run 'Mask|Sent|Redact|Privacy|Tail' ./internal/gateway: ok
Before the rebase (at 6104e88aa), vet of ./... on three OSes was ok,
and the whole race run of internal/gateway and internal/gui had three
reds not of this change: TestTailOfReadsInPlace (fixed on main since,
4ca64c21b), TestMainWindowCorners (#3949), and a race in
TestPluginPageStartsItsHost (fixed in the next commit).

Broken by hand: keeping as many bytes as the body (the encoded body
padded to its size) turns TestSentKeptCompressed red: "a 1048712-byte
request is kept in 1069709 bytes".

Not tried: the footprint of a live gateway under real masked traffic.

Reported-by: apple-ouyang
2026-10-28 22:29:10 +08:00
..