Files
magpie/docs
yetone ea53eb1262 gateway: a request to an unmasked route isn't masked first (#3973)
wangbinyq (#3973): with masking on, a request to a provider set to
go unmasked was still masked whole before routing, then sent as the
agent wrote it, so the masking was thrown away. In their log that was
97.9% of magpie's own time: median 560ms, p99 16s, max 219s.

serve now masks after Resolve/FindGroup. When unredactedRoute holds
and no body goes anywhere else (bodiesKeptAway: no observer wanting
bodies, no request archive), masking is skipped. The redact writer
goes under capture, an order that commutes with the old one. A
turned-away request is logged masked (maskedCopy). count_tokens
masks only when its route isn't unmasked. The context card's text
stays masked: the kept body is masked when PromptText first reads
it (keptBody.plain), not on the request's way. The log and recent
calls keep the body as it went.

Run on mote at this tree (base 58fb3a778, rebased onto d74ef5e04
with no internal/gateway change in between):
- gofmt -l internal/gateway: none. GOOS=linux/windows/darwin go vet
  -tags nogui ./internal/gateway: ok.
- go test -tags nogui -count=1 -timeout 45m ./internal/gateway:
  one red, TestPluginStreamsPastTheBudgetWait (connection reset by
  peer, load ~80). That is #3946, already open. Alone with
  TestPromptTextIsWhatWasSent, -count=5: ok.
- The first full run caught TestPromptTextIsWhatWasSent red: the
  card's text held the key on an unmasked route. Fixed by the lazy
  masking above; it is green now.
- Broken by hand: on origin/main's gateway.go and redact.go, the new
  TestUnmaskedRouteIsNotMasked is red ("masked 1 times, want masking
  false", "count masked 1 times").
- Real run: old and new magpie serve in a sandbox HOME, redact on, a
  local Anthropic provider on a fake upstream, 15 requests of 1.2MB
  with emails, phone numbers and keys. Unmasked provider: median
  176ms on old, 13ms on new. Masked provider: 171ms vs 172ms.

Not tried: a real vendor account. The change sits before the
upstream call, and the fake upstream stands in for it.
2026-10-28 14:55:20 +08:00
..