Files
magpie/internal/redact
yetone ec7e50b828 redact: a decimal's digits are not masked as a number of their own (willz, Discord)
willz on Discord: a tool's JSON with "height": 5.13393848347348 went to
the vendor with part of the number as a placeholder. A run of digits
right after the point of a decimal, or right before it, was judged on
its own: 0.13800138000 went as 0.{{PHONE_…}}, 6.4111111111111111e-3 as
6.{{BANK_CARD_…}}e-3, 1.110105194912310038 as 1.{{ID_CARD_…}}, and
13800138000.5 as {{PHONE_…}}.5. The rules' bound only kept digits off
either side, not a point with a digit beyond it.

mask now drops, after noIDs, any span of a personal-data kind (kindCats:
PHONE, BANK_CARD, ID_CARD, SSN, IP, the model's ACCOUNT and PHONE, …)
that starts with a digit after "<digit>." or ends with a digit before
".<digit>" (noDecimals, inDecimal). It is one choke point for every
finder: the rules, the local model's spans and values known from
before. Not changed: secrets (a key or password masked once is masked
wherever it is, a decimal's digits too), the user's words and rules,
and the signed-thinking path, which re-masks only secrets. A phone
number or card standing alone, in text, after a colon, in a JSON
string, or at a sentence's end ("13800138000.") is masked as before.
A number list written "1.13800138000" with no space now goes as
written; a comma decimal (5,13800138000) is not treated as one.

Reporter's literal: at 86254d404 the rules alone leave
5.13393848347348 as written (the 14 fractional digits are too long for
a phone or a card); it is masked when the local model labels the
fraction (TestDecimalDigitsNotMaskedByModel, 5.{{ACCOUNT_…}} on the old
code) or once its digits are a known value, which is how it leaked
into another test's body on the old code. Which finder masked it for
willz is not known; the fix covers all three.

Tests (decimal_test.go): TestDecimalDigitsNotMasked (the reporter's
bytes and siblings: negative, exponent, ID card, whole part, text, many
digits; through Mask and MaskJSON in a tool_result),
TestDecimalDigitsNotMaskedByModel, TestKnownNumberNotInDecimal (plain
and in a signed thinking block), TestStandaloneNumbersStillMasked,
TestKnownSecretInDecimalStillMasked.

Run at 28d191fbe (on origin/main 86254d404):
- old redact.go with the new tests: all four decimal tests FAIL as above
  (TestStandaloneNumbersStillMasked too, through the known ACCOUNT).
- broken by hand: without the fraction-side check 12 failing lines;
  without the whole-part-side check, {"total": 13800138000.5} and
  "13800138000.25" fail; without the personal-kind scope,
  TestKnownSecretInDecimalStillMasked fails.
- gofmt -l internal/redact: empty. go vet ./..., GOOS=linux go vet
  -tags nogui ./..., GOOS=windows go vet ./...: ok.
- go test -timeout 45m ./... (one suite on the machine, checked with
  ps): 68 packages ok, no FAIL; internal/redact, internal/gateway and
  internal/agent ok. An earlier full run during the edit also passed.
- after rebasing on fresh origin/main: go test ./internal/redact/... ok.

Not tried: the real local model (internal/pii) on willz's text, a real
gateway request, Windows or Linux runs of the package. No docs page
describes the rules' boundaries, so none changed.
2026-10-22 17:49:49 +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