Commit Graph
7 Commits
Author SHA1 Message Date
yetone 2d90c7c565 redact: a hex number (0x and up to 16 hex digits) goes as written, whatever the local model takes it for
TakaNaShi_ShiKi on X: in reverse-engineering notes, an address written
as inline code, `0x004EA5E0`, went to the vendor as {{SECRET_6kkmmxxd}},
and the vendor's model lost the data it was asked about.

Which finder took it: no rule. With Secrets and Personal on and every
kind on, the rules alone mask none of the values in the new test (the
"by the rules" checks in TestHexNumberGoesAsWritten). The local model
did. Asked for real (Privacy Filter and AstrLink Guard from this Mac's
cache, copied to mote, MAGPIE_EVAL_CACHE), on a notes table:
  Privacy Filter: secret 0.679 on 0x0058C210 (beside "密钥表")
  AstrLink Guard: secret 0.625 on the same
  Privacy Filter, "The license check is at `0x004EA5E0`; the key table
  at `0x0058C210`.": account_number 1.000 and 0.995 on both
  Privacy Filter, "key: 0x004EA5E0": secret 0.992
modelFits let them through: hexRe, which holds back a bare hex run
unless a key's name is right before it, asks lower case and no 0x, and
numberLike reads 0x004EA5E0 as a number, so ACCOUNT took it too. That
is the sibling, with the real model's evidence; PHONE did not take one
in the fake-model test, and decimal numbers already have their own
checks (numberNamedSecret), so nothing wider is changed.

Now modelTakes takes no value of any kind that is 0x or 0X and 1 to
16 hex digits (hexLiteral, a 64-bit value: an address, a constant, a
flag). No cue is asked, unlike a bare hex run: the function at an
address is often named for a key (DecryptKey: 0x004EA5E0), and
secretCued would read that as "key:". A longer 0x value (a 64-digit
private key, a 128-bit 0x+32) is masked as before.

Tests:
- TestHexNumberGoesAsWritten (new): the reporter-shaped table row, a
  cued address, 0X upper case, 0xFFFFFFFFFFFFFFFF, a 64-bit x64dbg
  base; none masked by the rules, nor as secret, account_number or
  private_phone from the model; 0x+64 and 0x+32 still masked.
- TestMaskEval: cases hex-addresses and hex-addresses-en, with the real
  models' recordings added (only these two entries; the rest of the
  recordings were left as committed, since re-recording on mote moved
  other cases' scores slightly).
- Broken by hand: the hexLiteral check taken out of modelTakes.
  TestHexNumberGoesAsWritten FAILs with eight masks
  ("0x004EA5E0" as secret: masked "...`{{SECRET_7bm7qoxm}}`...", as
  account_number "{{ACCOUNT_rcgox2br}}", 0xFFFFFFFFFFFFFFFF and
  0x00007ff6a1b20000 as secret), and TestMaskEval/privacy-filter FAILs
  with 'hex-addresses: "0x0058C210" was masked, and should go as
  written' and both hex-addresses-en values. Restored: both pass.

Run (mote-run, at base 4ab1191bc): gofmt -l internal/redact (empty),
go vet ./internal/redact/, go test -count=1 ./internal/redact/... ok.
Not tried: the reporter's own text (not posted in full); a running
magpie with the model on.

docs/subsystems/gateway-routing.md says it beside the EVM address rule.
2026-11-08 11:48:50 +08:00
yetone 4e7661adce redact: an app's one-word name the model took for a person's goes as written
Reported by ylorn. on Discord (11-06): choosing apps in Alma, a question
about one app was answered with another's facts. Privacy Filter took the
apps' names (Cicada, Mimi, Phosphor, Parakeet, Muesli) for people's: in a
bare list of them, alone, and in the Markdown list of apps the assistant
answered with (probed on the real model: ~0.99 each). The follow-up
questions ("How about Mimi?", "Phosphor vs Parakeet") it did not flag, so
they went as written while the history held the names as placeholders;
Phosphor and Parakeet (8 bytes) then became known values and were masked
everywhere. The vendor could not tell which placeholder was which app.

Restore was not the cause: placeholders are a keyed hash of kind and value,
one per value, and restore maps each back to its own value in any case
(TestManyNamesRestoreEachToItself, a guard: it passes on the old code too).

personFits now lets one ASCII word go when what is around it says a thing
and nothing says a person (thingNamed, internal/redact/thingname.go): a
person's word beside it (my colleague, Hi, Mr, said, told) masks; a thing's
word beside it (using, switched to, the ... app, vs, apps like, 这个软件)
lets go; else its sentence decides (he/she/relations/greetings/said mask;
app/macOS/subscription/vs/软件 let go); else a list item among items that
speak of apps, or a text of capitalized names only, lets go.

Trade-off, by design: a single first name alone, or a first name in a
sentence that speaks of an app with nothing of a person ("Mimi uses the
app daily"), goes as written. A full name (John Smith), a Chinese name
(张伟), and a first name beside a relation, a greeting, said or a pronoun
are masked as before.

Run (mote, worktree at 84ad780b6 + this):
- go test ./internal/redact/... ./internal/pii/... ./internal/masking/...
  ./internal/otlp/... ./internal/sessions/... ./internal/settings/... ok
- go test -run 'Mask|Redact|Privacy|Person|Known' ./internal/gateway
  ./internal/gui ok
- TestMaskEval re-recorded with both real models (MAGPIE_EVAL_CACHE);
  only the 12 new cases' recordings are added, old entries kept as they
  were (mote's re-record drifted 4 AstrLink and 2 Privacy Filter entries
  by score; not taken in). New cases app-names, app-alone, app-markdown
  (real Privacy Filter flags), app-compare/vs/list/using/zh (model finds
  none; guard), app-and-person, app-and-full-name, app-and-zh-name,
  greeting (person controls).
- gofmt -l clean; GOOS=linux and GOOS=windows go vet ./internal/redact ok.

Broken by hand:
- the personFits hook off: TestAppNamesNotPersons red 9/9,
  TestPersonBesideAppStillMasked red on the 3 apps, TestMaskEval red on
  app-names (5), app-alone, app-markdown (3) with the real recordings.
- thingNamed always true: TestPersonBesideAppStillMasked red on Mimi (x2),
  Laura, Daniel.

Not tried: a real Alma chat through the gateway with the model on; Windows
and Linux runs (pure Go string code, vetted for both); the full suite runs
after the push.
2026-11-06 09:28:25 +08:00
yetone ea7c0067e0 privacy: each local model's confidence threshold is the user's to set
Yayoi_no_yume on X asked for the privacy model's threshold to be
adjustable: they read it as fixed at 0.5, and from their own use find
0.85-0.95 right for AstrLink. The 0.5 is Privacy Filter's (pf-serve's
argv default); AstrLink Guard already masked at its publisher's 0.8.

Both models now find at a floor of 0.5 (pii.Floor) and give each span
its score: Guard's least token probability (rounded through float32,
so a span read back from the cache file sits on the same side of a
threshold), pf-serve's own. masking.model keeps the spans at
pii.Threshold or over: settings.RedactModelScore[model] when it is in
[0.5, 1), else the model's MinScore (Privacy Filter 0.5, AstrLink
Guard 0.8). Settings -> Privacy shows a Confidence threshold row under
the model (app menu, 0.5 to 0.95 and Default), /api/privacy-model
takes do:"score". The setting is this computer's own, like the model.

The defaults stay. TestMaskEval's cases, rules + model + magpie's
checks, by threshold:

  Privacy Filter 0.5-0.8   masked 41/42  kept 112/113
  Privacy Filter 0.85-0.95 masked 40/42  (a Chinese name lost)
  AstrLink Guard 0.5-0.7   masked 42/42  kept 112/113
  AstrLink Guard 0.8-0.85  masked 41/42  (a phone in a tool result)
  AstrLink Guard 0.9       masked 40/42
  AstrLink Guard 0.95      masked 40/42  kept 113/113

The model alone does raise fewer false alarms higher up (Privacy
Filter's found-in-keep falls from 47 at 0.5 to 27 at 0.95, Guard's
from 8 to 2), but the checks after it drop most of those already, so
a higher threshold mostly costs values that should be masked.

Cache file: found-<model>.bin is now "pfound02" with a float32 score
per span. A "pfound01" file is still read, each span with score 1, so
texts cached before mask as they did and aren't asked again. For those
texts a higher threshold drops nothing and a lower one doesn't add a
Guard span scored 0.5-0.8 until the cache turns over (20000 answers).
merge() keeps the surer score of spans it joins. The eval recordings
(eval-model.json, eval-astrlink.json) were made again with scores,
from a scratch cache, the live found files untouched.

Run in the worktree at 11dcc743f + this change:
- go vet / gofmt -l on the touched packages: clean
- go test -count=1 -timeout 45m ./internal/pii/... ./internal/masking
  ./internal/redact ./internal/settings ./internal/gui ./internal/gateway: all ok (gateway 546s, rerun
  after an earlier run hit "no space left on device" on this machine;
  every failure in that run was a TempDir mkdir). This run caught
  TestSettingsSaveKeepsWhatItDoesNotSend wanting RedactModelScore set;
  it is now
- GUI: privacy-model.test.cjs 64/64 (chromium + webkit, 5 languages,
  1100 and 640px; the new threshold menu test among them),
  i18n-keys 4/4, redact-kinds, redact-rule-edit,
  redact-rule-row, redact-shape, redact-words-any-case all pass.
  masking-records 82/82, routing-masking 10/10, privacy-usage-stats 4/4,
  mask-actions 22/22. privacy-hides-accounts was 3/4 once (webkit en,
  page.goto's 5s at load ~290, the class of #3525, commented there),
  then 4/4 three times. Not run: the rest of the GUI suite.
Rebased on 508911e43 (which touched internal/pii fetch and mirror): at
that head, go build ./..., Linux and Windows go vet of pii, masking,
settings and redact, gofmt -l, and go test of pii/..., masking, redact,
settings and gui all ok; gateway not run again after the rebase.
Broken by hand: masking.model keeping every span (TestModelThreshold
  red); Threshold taking any value (TestModelThreshold red); the cache
  writing 1 for every score (TestRestartReadsWhatWasFound red); merge
  not keeping the surer score (TestMergeAcrossPieces red, after its
  joined span was made surer than the one it joins).
Not tried: the real app's window, Windows, Privacy Filter on a GPU
with the new score read (pf-serve itself is unchanged; it always sent
the score).
2026-10-27 14:10:33 +08:00
yetone b3729b8d56 redact: a model's or a toolchain's name the local model takes for a secret goes as written
The owner's 脱敏 page showed groqAPIModel = "llama3-70b-8192" masked as
a secret by the local model. The real model, asked again, also takes
claude-3-5-sonnet-20241022 beside it for one. namesThing now holds
modelName: lower-case words joined by dashes with a size part (70b,
8x7b, 32k), an eight-digit date part (20241022) or a yyyy-mm-dd date
(nightly-2026-09-01). A diceware passphrase (correct-horse-battery-
staple) or maple-4-river-77 has neither and is still masked.

The page's other value, nightly-2026-09-01 as a name, was recorded by
the running v0.1.1370 (10-24). The model labels it private_person, and
main already drops it (a name with a digit, a word in lower case, since
611b9e173); the new rust-toolchain eval case holds that.

Run:
- MAGPIE_EVAL_CACHE=$HOME/.cache go test -run TestMaskEval ./internal/redact
  with the real model: re-recorded, both new cases ok in "both", the
  model's column WRONG for all three values.
- go test ./internal/redact ./internal/pii: ok. gofmt clean; go vet for
  darwin, linux and windows.
- Broken by hand: modelName taken out of namesThing → settings-model red
  (both values) and the four new TestModelMisreadsNotMasked cases. The
  digit check in personFits alone taken out stays green on
  rust-toolchain, since the lower-case-word check also drops it.

Not run: the packages that import redact (gateway and others) before
the push; the change only narrows what the model's secrets mask.
2026-10-26 22:16:02 +08:00
yetone 720e491d2b redact: the local model's ids, decimals, model names and products in agent sessions go as written
A reporter on X (tearicerice, 10-26) had Claude Code check what the
local model masked and found "大概95%以上都是误判". Run over the last
120 turns of 22 real Claude Code sessions, rules-only against
rules-plus-model, the model alone found 69 distinct values, ~55 of them
wrongly. modelFits and modelTakes now leave these as written:

- PHONE: a decimal (a metric's 104.21875033916251, 23 such values) and
  a value starting with a letter ("run 48213097715").
- SECRET: a value right after an id's name (Claude Code's "with ID:
  kq3m8zx2t", "(ID: …)", <task-id>…, "backgroundTaskId":"…"); a
  lower-case slug with a slash (qwen/qwen3-14b); a lower-case file name
  (make-icons.sh); a grep regexp with \| or \b; words with a time of day
  in them (release about 17:05Z); a hex or digit run whose key cue is
  further back than "key:" / "token is" (GH_TOKEN in "env -u GH_TOKEN
  gh run view 48213097716" made the run id a secret).
- SECRET spans that took in a JSON key (ledgerId":"gl_…) start after
  the key's `":"`.
- madeID takes ids with more words and a nanoid's - and _
  (req_gateway_<hex>, tb_Ra4K…-ZqT2…), except under sk/rk/pk/whsec/
  shpat/shpss/xoxb/xoxp, whose keys have that shape.
- ADDRESS: an ASCII value with no space and a slash (a transcript's
  path). A Chinese address has no spaces and is unchanged; "3/12 Smith
  Street, Sydney" still masks.
- EMAIL: a value with no @ (eu.stg.acme.io, a host).
- PERSON, one word: an acronym (CI), a camel-case product with a
  capital after 3+ lower-case letters (CodeRabbit; McDonald, MacKenzie
  still mask), and a word the same text has as a host's name (Greptile
  beside app.greptile.com; not an address's local part, matt.lee@…).

Measured again on the same 22 sessions: 20 distinct model-only values,
12 of them real (people's names, the user's emails, an AWS account). The
8 left wrong are single dictionary or product words (Alma, Greptile
where no host is in the same text, Harness, Reds, Todo, Zhipu), 查询,
and an org id seen bare in a grep. The sessions' values were read in a
scratch test that isn't committed, and its logs are deleted; every
value in the tests and here is made up in the sessions' shapes.

Tests: 19 TestModelMisreadsNotMasked cases and 6 TestModelFindsStillMasked
cases (a Stripe-shaped sk_test_ key, a hex after "token is", McDonald,
Rina beside rina.lee@…, +1 415.555.0132, an address with a slash). 9
evaluation cases (metric-decimals, run-ids, background-tasks,
model-names, ls-files, gateway-ids, transcript-path, pr-checks,
team-notes), recorded with the real model.

Broken by hand, one at a time (each red): the decimal and leading-letter
phone checks, the path address check, regexpLike, idAfter and its camel
and > forms, the clock check, secretCued (back to cued), the slug and
file name checks, the JSON key trim, EMAIL needing an @, the acronym,
camel and hostIn name checks, madeID's longer ids and its keyHeads.
A decimal check for ACCOUNT was green when broken (versionRe already
covers it) and was dropped.

Run: go test -count=1 ./internal/redact ./internal/pii (ok),
MAGPIE_EVAL_CACHE TestMaskEval (re-recorded, ok). gofmt -l clean; go vet
./internal/redact for linux, windows and darwin. The packages that
import redact (gateway, gui, masking, otlp, sessions, settings) were
still running at push, beside another session's gateway run; not a
record of a pass.

Not tried: the reporter's own sessions, the WorkBuddy AI group/flash
traffic in their screenshot (~160 values a request), or their version.
Not looked at in the GUI's Masking page; the change is in what is
found, not in how it is shown.
2026-10-26 16:11:11 +08:00
yetone db6d1540ef redact: eval cases that reach more of modelTakes/modelFits
TestMaskEval's cases reached 5 of the 36 checks on model spans: breaking
any other one by hand left it green. This adds 21 cases (39 to 60), most
of them texts from modelfits_test.go and vendorchecks_test.go, the
places the model was seen misreading, and records the real model's spans
on them (testdata/eval-model.json).

Breaking each check by hand (breaks.py: one replacement in model.go,
TestMaskEval run, file restored) now turns 13 red (5 before):
secret-madeID, person-2runes, email-realEmail, person-zhTrim,
person-assistant, account-numberLike, account-cue, address-letter,
secret-wordstart, secret-uuid, secret-hexwords, secret-hexcue,
edge-delimiter.

Still green, because the real model gives no such span on any text tried
(24 more probed) or another check catches the same span first:
secret-namesThing, secret-len8, person-snakeWord, account-madeID,
cut-from-word, person-chars, person-filedot, person-pathpart,
person-colon, person-lowerword (person-chars keeps the same lower-case
word), account-hex, account-version, the four phone checks, secret-pattern,
secret-json, secret-link, secret-base64, email-wordstart, email-modcache,
email-userinfo. Their unit tests in modelfits_test.go still cover them
with recorded spans.

A new real miss: "hex40 ok? 1 <sha1>" is one secret span "1 <sha1>" to
the model, and the hex-words check only looks at the first field. Filed
as #3597 and marked Known.

Totals at this head (rules / model / both, masked and wrongly):
16/40 0/89, 38/40 28/89, 39/40 1/89.

Run: MAGPIE_EVAL_CACHE=$HOME/.cache go test -run TestMaskEval -v
./internal/redact (recorded, then replayed green); go test -count=1
./internal/redact ./internal/pii ok; go vet ./internal/redact for darwin,
linux and windows; gofmt -l clean; breaks.py over all 36 checks.
Not tried: the full suite (only test files changed in internal/redact).
2026-10-25 19:17:53 +08:00
yetone 180cfb565e redact: an evaluation of the masking, with the rules, the model and both
TestMaskEval scores 38 made-up texts of the kinds agents send (prose,
code, logs, tool results, JSON, CSV, Chinese) with 34 values to mask
and 40 to keep. The cases start from what users reported masked
wrongly (#3144, #3143, #3029, #3538, #3577, d3db461bb, 611b9e173,
#1977) and add the values masking is for. It logs, by kind, how many
each way masked of those to mask and, wrongly, of those to keep:
the rules alone, the local model as it said it, and both with the
checks on what the model found, and lists every value one way got
wrong.

What the real model said is recorded in testdata/eval-model.json, so
the test replays "both" with no model and no network, and fails when
a value comes out wrong, or a Known one right. MAGPIE_EVAL_CACHE
points it at a downloaded model to record again.

Baseline (privacy-filter q8, M4 Pro):
  rules  16/34 masked, 0/40 wrongly
  model  32/34 masked, 8/40 wrongly
  both   30/34 masked, 0/40 wrongly
The checks take all 8 of the model's wrong ones off. Of the 4 misses,
3 are phones the model found with the delimiter before them
(`":"+86 …`, `,+81 …`), which the PHONE check turns down (#3591),
and 1 is 刘洋, which the model doesn't find (#3592). Both are Known.

Run: MAGPIE_EVAL_CACHE=$HOME/.cache go test -run TestMaskEval -v
./internal/redact against the installed model (recorded); go test
./internal/redact ./internal/pii ok; go vet for darwin, linux,
windows; gofmt -l clean. internal/proc's TestNoCommandBypassesProc is
red, on origin/main too: internal/tui/keep.go (#3567).
Broken by hand: modelFits off: 4 keeps masked and the 3 #3591 phones
reported right, red. A case's text changed: red, the recording is
stale. Taking snakeWord, epochNumber or madeID's SECRET check off
alone stays green: the model makes neither mistake on these texts,
or a second check catches it.
Not tried: the model on Linux or Windows, or on the CPU.
2026-10-25 17:41:10 +08:00