An agent sends its whole history on every turn, so with masking on every
turn ran each rule's regexp over every message before it again; on a long
session most of magpie's CPU went there (#4353). ruleSpans now keeps what
the rules found in a text of 256 bytes or more, keyed by a SHA-256 of the
text, the day (a date over a year old can be a birthday), Secrets,
Personal, the kinds turned on and off and the user's own rules. Only the
hash and the places found are kept, no value. Two generations of 65,536
entries, as sentMemo keeps.
Run on mote at this tree:
- gofmt, go vet (darwin, GOOS=windows, GOOS=linux): ok
- TestRulesRunOnceAText and TestRuleMemoKeysWhatTheRulesRead: ok 3 of 3
alone; -race with TestMask*: ok
- go test ./internal/redact: ok; go test -timeout 45m ./internal/gateway:
ok (662s; run before the counter moved into ruleSpans' find, which no
gateway code reads)
- Broken by hand: memo bypassed -> "the rules ran over 41 texts for one
new turn"; day left out of the key -> line 74 red; kinds left out ->
line 69 red.
- BenchmarkMaskNextTurn (Codex history of 80 turns, then 81):
99.6ms/op before, 6.6ms/op after.
Real use: sandbox HOME copied from the owner's, masking on, real DeepSeek
account, deepseek-flash, four turns of a 115-123KB history with mails and
phone numbers. Masking took 22-24ms a turn before; after, 24ms for the
first turn and 1.7-2.1ms for each next one. Every reply HTTP 200 "ok"
(one empty reply at finish_reason length on each binary, the model's
reasoning using max_tokens).
Not run: the full ./... suite; Windows and Linux runs of the tests.
Picked onto 54087aa43 (3 files changed, 199 insertions(+), 34 deletions(-), none in internal/redact); not run again there.