Files
magpie/internal/redact
yetone 3806014ac8 redact: Chinese personal names are masked, where the model misses or overreaches them (#1977)
OpenAI's Privacy Filter gives common Chinese names (张伟, 李娜, 陈建国,
黄晓明) almost no PERSON weight. Lowering the O label's emission by 2 or
4 in a patched pf-serve didn't bring them back. It also returns spans
that run past the name (「王芳,她下周一」, 「张伟先生」).

zhname.go adds a rule layer behind the model, only when personal data
is covered:
- a surname (single, compound, or 小/老 + surname) with a 1–2
  character given name is masked when something around it says it is
  a person:
  - a role before it (客户, 联系人:, 我叫, 作者:, @);
  - a verb before it (给, 告诉, 抄送) or after it (说, 反馈, 先生);
  - a title or 总 (孙经理, 邓总);
- a name joined by 和/与/跟/及/、 to a name already found counts too;
- words that start with a surname (张量, 高度, 王国, 周五, 总是) are
  never taken;
- the model's PERSON spans with Han in them are cut at punctuation or a
  title, and only when at least two characters remain.

Run:
- Real model, end to end through MaskJSON (pf-serve q8, Metal):
  - masked 张伟, 王芳 (cut), 李娜, 刘洋, 陈建国, 赵丽颖, 欧阳娜娜, 司马光,
    黄晓明, 周杰伦, 小王, 老李, 马云, 王老板, 邓总, 孙经理, 刘总监,
    吴敏, 郑浩, 何静, 唐宁, 许文强, 罗志祥, 林老师 and 郭靖;
  - Japanese, Korean and English names are unchanged.
- Missed, with nothing around them that says person: 「模块是谢磊写的」
  and 「和黄蓉团队」.
- False positives: none over 2237 lines of the repo's Chinese docs and
  i18n, or 61 developer sentences.
- Cost: ~19ms CPU over 880KB.
- Broken by hand:
  - with the layer off, TestChineseNames has 8 names unmasked;
  - with the two-character guard off before a title, 感谢李老师 goes red.
- Checks:
  - gofmt -l is clean;
  - go vet is clean on darwin, GOOS=linux -tags nogui and GOOS=windows.
- go test ./... -timeout 45m at load ~750: 63 packages ok, redact
  among them. internal/agent (TestReconnectKeepsTheLastPick) and
  internal/gateway (TestLargeRequestEndpoints) hit the 45m timeout with
  no failed assertion, and are being rerun alone.
2026-10-20 05:15:19 +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