Skip to content

The sensitivity detector labels card numbers, SSNs and stated PINs high and IBANs medium, and the sweep pages its window from a per-agent cursor - #89

Merged
zlareb1 merged 74 commits into
mainfrom
feat/sensitivity-pii-shapes
Oct 21, 2026
Merged

zlareb1 merged 74 commits into
mainfrom
feat/sensitivity-pii-shapes

Conversation

@zlareb1

@zlareb1 zlareb1 commented Oct 20, 2026 •

Copy link
Copy Markdown
Member

Changelog category (leave one):

  • Improvement

Changelog entry (one or two sentences a user of Loom can read without the diff; the release pull request collects these into the release notes):

With sensitivity unset, a memory holding a payment card number (Luhn-checked), a US Social Security number, or a PIN, passcode, CVV or security code stated with its value is labelled high, so it is never embedded and is readable by key only with an audited read. An IBAN with a registered country code, that country's length and a passing mod-97 check is labelled medium. The daily sensitivity sweep reads its window in pages of LOOM_SENSITIVITY_SWEEP_MAX_ROWS_PER_PASS keys, up to the new live setting LOOM_SENSITIVITY_SWEEP_PAGES_PER_PASS (default 10) pages or half its pass deadline per pass, and resumes at the agent it stopped in, from a cursor in loom.worker_status; loom sensitivity-sweep --limit now caps the candidates found rather than the rows read, and refuses 0.

Why

The detector labelled only credential shapes high and email or phone numbers medium. Users of a chat service paste payment and identity data into conversations, and the detector missed it: "My employee badge PIN is 4471" was stored as an ordinary memory, embedded and returned by search.

The sweep's paging ships in this PR rather than a PR of its own, for three reasons. The sweep is the only labeller for rows that arrive by observe.record, copy_to, namespace.restore and the imports, so the new shapes protect those rows only if a pass reaches them: the old read took the first LOOM_SENSITIVITY_SWEEP_MAX_ROWS_PER_PASS matching rows every pass, so a card or PIN row behind that many selected rows the detector leaves unlabelled aged out of the window unlabelled. Both changes rewrite the same read: the new shapes need it to return value and value_json apart (a dotted key such as security.code keeps its words only in value) and to filter by shape, and the paging replaces that statement, so a split needs an intermediate read that neither PR keeps. And the paging tests place PIN rows behind the selected-but-unlabelled ones, which needs the PIN shape. A rollback reverts both together; neither changes stored data beyond the labels and the sweep's cursor row in loom.worker_status, which a reverted build does not read.

Scope and risk

  • server/memory/domain/sensitivity.py: four new shapes, each a single regex pass over the text. The detector is a deterministic lower bound: it recognises the label forms and shapes listed here, not every way a person can phrase a secret. The module docstring and security.md say so and list the label forms. The catch-all for extraction is an operator's extraction policy, which is a separate change.
    • Card number: either one ungrouped group of 15 digits (Amex) or 16, or, in a run of digit groups joined by single spaces or dashes (not starting after +), consecutive groups in a printed card grouping (4-4-4-4, 4-4-4-4-3, 4-6-5, 4-6-4) with at most three short groups (1-4 digits) around it, at most two of them after it. The leading digits must fix a network and its length. Visa: 4, at 16 or 19 digits. Mastercard: 51-55 and 2221-2720, at 16. Amex: 34 and 37, at 15. Diners: 300-305, 3095, 36, 38 and 39, at 14. JCB 3528-3589 and Discover/UnionPay 6011, 62, 644-649 and 65: at 16 or 19. The Luhn check must then pass. A card pasted with its expiry and CVV (4111 1111 1111 1111 0429 123), or after a date or another number, is still found. These stay unlabelled: a 19-digit decimal hash with a Visa prefix that passes Luhn (4000000000000000006, rejected by the length rule), one with no network's prefix (6000000000000000004), a row of port numbers (3000 5432 6379 9200 passes Luhn), a table of eight or more 4-digit numbers, a 15-digit IMEI (always Luhn-valid) and yyyymmdd runs. Groups joined by two spaces or by dots (4111 1111 1111 1111, 4111.1111.1111.1111) are not read; security.md names this gap. These are not read as cards but stay medium by the phone shape: a 13-digit phone number written without its + (4915123456787), two phone numbers side by side, and epoch milliseconds (1760000000000). The Visa-prefixed hash and the phone number both pass Luhn, so they test the length rule, not the checksum. A 19-digit Visa printed 4-4-4-4-3 whose first 16 digits fail Luhn (4000 0000 0000 0000 006) is labelled, as is an ungrouped 15-digit Amex (378282246310005).
    • SSN: ddd-dd-dddd without the never-issued ranges (area 000, 666, 9xx; group 00; serial 0000).
    • Stated PIN: one of the labels pin, pin code, pin number, passcode / pass code, cvv, cvc, cvv2, cvc2, cvv code, cvv number, cvc code, cvc number and security code. A two-word label may use _ or a space (PIN_CODE, security_code). A label starts after anything but a letter or digit, so a prefix counts (BADGE_PIN=4471, atm_pin: 4471, CARD_CVV=123) and a word ending in a label does not (spin: 4471). The value follows is, was, : or =, after an optional for and up to three words (PIN for the front door is 4471; four words or a bare pin with a direct value stay unlabelled). Every label except a bare pin also takes the value directly (CVV 123). A bare pin is also a verb (pin 128 rows) and a connector pin (GPIO pin 115, pin #115), so it does not. A direct value followed by of (passcode 100 of the batch, PIN code 100 of the batch) is a position and stays unlabelled. pin number, passcode, CVV/CVC and security code take 3-8 digits. pin and pin code take 3-5, because PIN: 560001 and PIN code 560001 are Indian postal codes, so a 6-digit PIN is labelled only when stated as a PIN number (a trade-off). The other trade-off: a connector pin written as an assignment or with number (GPIO pin: 115, GPIO pin number 115) reads as a PIN, the price of reading PIN: 4471 and PIN number 4471 as one. A test pins it, and security.md says so. A value ends where its number does, so a version or a date (the tzdata pin is 2024.1, pytz pin: 2023.3, base image pin is 2024-01-15, base image pin is 2024/01/15, PIN for certifi is 2024.2.2), or a run-on word (tzdata pin: 2024a, the pin is 1234abc), is not read as a PIN, while My PIN is 4471. still is. Each whitespace run in the pattern has its own anchor, so a long run of spaces is read in one pass. The new patterns are ASCII-only, matching the sweep's RE2 filter, so whatever the write path labels the sweep can also select. The label strings are plain regex that RE2 reads too: POSTCODE_LIKE_PIN_LABEL for pin and pin code (3-5 digits), PIN_CODE_LABEL for the direct pin code form (and POSTCODE_LIKE_PIN_LABEL is built from it), and PIN_LABEL for the rest (3-8 digits). One function, pin_grammar(space), builds the qualifier and separator for both the detector (\s) and the sweep's prefilter (the escape-aware whitespace class).
    • IBAN (medium): country code, numeric check digits and BBAN in groups of four, then the ISO 13616 checks: the country code is in the registry (_IBAN_LENGTHS, one length per country), the length is that country's, and the number is 1 mod 97. Without the registry check about 1 in 97 uppercase tokens of the shape (license keys, serials, ticket codes) passed. A spaced match can take in an uppercase token before or after the IBAN (XY12 GB82 ..., ... 1332 EUR), so each run of its groups is checked: at most ten groups, 55 runs. The card check skips the digits of a valid IBAN: a spaced IBAN's groups can read as a Luhn-valid card grouping (DE24 4005 0150 0000 0005 00 holds 4005 0150 0000 0005, a Visa-prefixed number that passes Luhn), which labelled about one in ten such DE, FR and IT IBANs high. The IBAN digits are masked in one pass over the text, so a value dense with IBANs is still read in linear time. Search demotes medium rows unless the question shows contact intent, and a question that names an IBAN or a bank account (number), plurals too, now counts as contact intent (any other account number does not), so the row that answers it is not demoted.
  • Unchanged: what a label means and who sets it. A caller's explicit level wins for the stored label, LOOM_MEMORY_SENSITIVITY_AUTODETECT turns detection on or off, and the places that call detect_sensitivity, reads_high and value_reads_high are the same. New: the shapes those functions read as high or medium, so every place that reads text as high (digests, extraction prompts, chunks, exports) now also treats a card number, SSN or stated PIN as high. reads_high now also decodes JSON \uXXXX escapes in raw text, because a chunk's indented JSON writes a vertical tab as \u000b even with ensure_ascii=False. detector_text still reads a JSON value one scalar at a time. A key whose last one, two or three words name a PIN-like secret now states its digits under that label, as a line of its own, so the free-text rules decide the length. pin, pin_code and pincode give pin is <value> (3-5 digits, so {"pin": "560001"} and {"pincode": "560001"}, postal codes, stay unlabelled). pin_number gives pin number is <value>. passcode, cvv, cvc and security_code each give <label> is <value> (3-8 digits). pass_code, cvv_2 and cvc2 count too, and each label is accepted by the free-text PIN pattern with is. A key is split into words at any run of characters that are neither letters nor digits, or at a change of case, so pin__code, pin/code and pinCode all count. An ssn, ssn_number, ssn_no or social_security_number key states an SSN, dashes optional. A key is read by its last one or two words (three for social_security_number), compared as word tuples, so p_in is not pin; each multi-word entry is also derived written as one word (pincode, passcode, cvv2, cvvcode, ssnno, SOCIALSECURITYNUMBER), not listed by hand. A key splits into words with the camelCase rule (badge/Pin, ATM/Pin; Spin and ATMPIN are one word each). A run of two or more capitals before a lowercase word is also read a second way, as a word of its own (PINcode is PIN/code, CVVcode, SSNno). ATMPin and PINcode have the same shape, so one split cannot read both. A single capital starts its word under both splits, so {"Spin": 1200} stays unlabelled. cvv_code, cvv_number, cvc_code and cvc_number keys count with the cvv / cvc label. A card number is found under any key, so there is no card key. Prefixes and any case or separator are accepted (badge_pin, badgePin, PIN, security-code). Any other key still labels nothing: a {"password": ...} key does not label its value. A connector pin in a config ({"pin": 115}) reads as a PIN, as GPIO pin: 115 does.
  • reads_high reads the same "key": value pairs in raw JSON text (a chunk of an object value) when the value is digits and dashes. A quoted value must be the whole string, with spaces allowed around the digits, so "4471 abc" is not one. A bare number ends where its digits do, so 4471.5 and a 20-digit run are not read as a shorter number. The key is a quoted string, escapes included ("pin\"", "door\\pin"), of at most 200 characters, so the scan stays linear. Before that bound, a run of escaped quotes (\" repeated) took 0.45 s for 5,000, 1.76 s for 10,000 and 7.17 s for 20,000, which is quadratic. With the bound it takes 158 ms for 20,000 and 791 ms for 100,000. The pattern's whitespace runs each have their own anchor. The previous form (\s*"?\s*) took 1.75 s on 20,000 spaces after "pin": and 6.7 s on 40,000, so it grew quadratically. The current one reads 200,000 spaces after "pin": or "pin": " in about 30 ms each.
  • The sweep's prefilter builds its key alternatives from the detector's own key list (KEYED_SECRET_WORDS), so the two cannot drift. Between a key's words it allows any run of characters that are neither letters nor digits nor a quote, as the detector splits a key; pin\/code, ClickHouse's form of pin/code, fits. It also reads the SSN key words (SSN_KEYS) and the free-text PIN labels from the detector. The prefilter's contract for keys is a superset, not a copy: it selects a key that ends in a label, whatever comes before it, and the detector decides. So it may select a few non-secret rows (spin, unpin, Spin, ATMPIN), which the detector, comparing whole key words, leaves unlabelled. Each costs a re-check on the sweep's passes within its window. security.md and the sweep comment say so. Between a key's words and after its last word it allows a run of characters that are neither letters nor digits, read in JSON text, where one may be an escape such as \n, \/, \", \\ or \u00e9 ("CVV:", "pin ", "Security Code (CVV)", "pin\n"), and the value may start with JSON's \t or \n escapes, so {"pin": "\t4471"} is selected; pin_count is not. A keyed value is stripped of ASCII whitespace only, the whitespace the patterns read, so {"pin": " 4471"} gives one answer from value_reads_high, reads_high on a raw chunk and the prefilter. A word stated as pin is selected only with a 3-5 digit value, so {"pin": "560001"} and {"address": {"pincode": "560001"}} are not. Every other key is selected with a value starting with three digits, after an optional quote and spaces. The sweep matches and detects on both the writer's bytes in value, where a dotted key such as {"security.code": "5512"} keeps its words, and toString(value_json), which an import may fill with more than value holds, so a dotted key is labelled as the write path labels it.
  • A caller's explicit level sets the stored label, but the readers that send a value to a model still check the value itself (value_reads_high): consolidation, the profile fold, the structured profile, the existing memories an extraction prompt shows, observe_extract and the entity extractor. A value that reads as high is left out of their prompts even when its writer labelled it low, so this fails closed by design. security.md says so in its own paragraph, the five call sites' comments say "whatever its label", and tests pin it on observe_extract, on the profile fold and on the structured profile build. The fold test is parametrized over an unlabelled credential and a low row holding badge PIN is 4471, the build test over an unlabelled and a low row holding it; neither reaches the model.
  • Sweep (server/memory/app/sensitivity_sweep.py): The coarse filter (coarse_shape_re, every shape when none is named) gains the four shapes, so the ClickHouse prefilter still selects everything the detector labels. match() runs on value and on toString(value_json), which hold JSON text for an object value, so a control character there is an escape (\n, \f, \u000b) and a non-ASCII character is \uXXXX (json.dumps escapes it). The PIN and IBAN branches take any such escape as a word boundary, and the card branches take one as the character before the number (the escape's last hex digit can be a digit, as in 番号4111111111111111 or a card after a no-break space), and take \f, \n, \r, \t and \u000b as whitespace, as the detector's ASCII \s reads them decoded (a backspace is not whitespace). The PIN branch follows the detector's grammar: every label after is/was/:/=, and every label but a bare pin directly. The IBAN branch needs a word boundary and two groups. The phone branch takes the same escape-aware whitespace between its groups as the assignment branch, so 415\n555\n0123 and a number grouped by no-break spaces, which the detector labels medium, are selected by the full filter and by --only-shape phone. Ordinary uses of pin (pin 128 rows, GPIO pin 115, pin the base image before the 2025 release) and strings like SHA256SUMS therefore do not take places under the scheduled pass's row limit. The pin and pin code alternatives take a 3-5 digit value followed by a non-digit, as the detector reads them, so the postal codes PIN: 560001, PIN is 560001 and PIN code 560001 are not selected either, while PIN number 560001 is. Some rows still are: those the coarse filter cannot rule out (passcode 100 of the batch, since RE2 has no lookahead). The pass cursor below keeps them from hiding later rows. I checked the filter against ClickHouse match() on a local server, on json.dumps text, the form the value column holds for every non-object value, and on toString(value_json) for object values holding \n, \f, \b, \v and \u201c before or inside a stated PIN. Every new shape matched, and the negatives did not. Every high row stays the credential probe shape, so the scheduled pass's default filter (credential,email) labels cards, SSNs and stated PINs with no settings change. An IBAN-only row is other, like any other medium shape outside email, and the operator applies it with loom sensitivity-sweep --apply. I did not add a new probe shape name because it would change the CLI's --only-shape choices and the setting's default for a medium label. Renaming the credential shape, which now covers cards, SSNs and PINs too, is left for a follow-up.
  • A sweep pass now pages its scan. It reads its window in the table's sort key order (org, namespace, agent, user_id, session_id, memory_key), in pages of LOOM_SENSITIVITY_SWEEP_MAX_ROWS_PER_PASS distinct keys (SELECT DISTINCT, so a key with several unmerged versions takes one place), each page starting after the last key of the one before, until that many candidates are found, LOOM_SENSITIVITY_SWEEP_PAGES_PER_PASS pages are read, or half the pass deadline (450 s at the default daily interval) has passed. A page takes two reads. The first reads the page's keys from any row version that matches, without FINAL, so the window prunes partitions, every thread reads, and a read in key order stops at the LIMIT. The second reads with FINAL the current version of each key from just after the page before's last key up to this page's last key (upto_<column> parameters from the first read's last key) and keeps the ones that still match. It filters on (org, namespace, agent, user_id, session_id, memory_key) IN (<the keys in that range>) as a subquery with no LIMIT, so a key written into the range between the two reads is read too and no key is read on two pages, and it binds no key list (a list of 20,000 keys as one array parameter would be longer than the request URL allows) and reads only the granules of the page's keys. Both statements are in server/memory/store/sensitivity_sweep_sql.py. The current version of a matching row is itself a matching row version, so the first read cannot miss one. The cursor is spelled as a > x OR (a = x AND ...). LOOM_SENSITIVITY_SWEEP_PAGES_PER_PASS is a new live setting (default 10, from 1 to 1000), in the settings catalog. scan takes a time budget (seconds), and the worker passes half the pass deadline the supervisor enforces (pass_deadline_seconds in the worker registry), a value derived from that deadline rather than a new setting. Once it is spent the scan reads no more pages: the pass applies what it found, stores its cursor and reports truncated, so pages that cost more than the deadline allows (large pages, many pages or a short interval) cannot have the supervisor cancel every pass at the same place before its cursor is written. The worker reads it on every pass, so a runtime override reaches the next pass without a restart. The ClickHouse filter is built from the coarse alternatives of the shapes in the shape filter only: the scheduled pass (credential,email) selects the credential, card, SSN, PIN and keyed alternatives and email, not the phone or IBAN ones. A ten-digit run the detector reads as a phone number (epoch seconds such as "ts": 1760000000, a run id) is therefore not selected. The card alternative selects only what the detector can read as a card: a lone 15- or 16-digit group with a network's leading digit (2-6), or a printed grouping that starts with a 4-digit group with one. Epoch milliseconds (1760000000123) and 19-digit ids are therefore not selected either. Before, the alternative matched any run of 13 or more digits. The credential-word alternative selects only an assignment, as the detector labels one: a word from the detector's own list (ASSIGNMENT_WORDS, shared by both), at a word boundary or after a JSON escape, then : or = after any whitespace the detector's Unicode \s reads or its escape, then eight characters of a value, after an optional quote. Before, it matched the bare words (password, secret, pwd, bearer) anywhere, so prose such as I forgot my password or cd $(pwd) was selected and left unlabelled on every pass. So these prose and epoch-digit rows are not selected at all. The operator's run with no --only-shape keeps the full filter. A selected row the detector leaves unlabelled stays unlabelled and is selected again on every pass. Before, the first page of such rows was re-read every pass, so a later high row could age out of the window unlabelled. Inside a pass, a full page whose first and last keys are in one agent, whose FINAL read gives back a current unlabelled row for each of its keys, and that gives no candidate moves the scan past that agent: the next page bounds on (org, namespace, agent) alone (past_agent), so it starts after every key of that agent and skips no stored agent name, whatever bytes it holds (an identity column takes any string, a\x00b included). One pass therefore crosses up to LOOM_SENSITIVITY_SWEEP_PAGES_PER_PASS such agents. A key whose only matching version is an older one gives no row on the FINAL read: apply labels a row by inserting a new version, and a delete writes a tombstone version, so until the parts merge the old unlabelled version still matches the key read. A page of such keys does not move the scan past its agent; the scan reads on to the next page, so the agent's rows after the ones labelled or deleted are still read and labelled. Until the merge, each such page costs the pass one of its pages, and a pass that finds no candidate and runs out of pages on such a page (its FINAL read gave no current row for one of the page's keys in the agent of its last key; a key like that in an earlier agent on the page sorts before the cursor, so it leaves the cursor at the agent the pass stopped in; the check compares the page's keys with the rows' keys, not their counts, since that read also returns a key written into the range between the two reads) leaves the cursor past that agent, so the next pass does not read the same pages again; the rest of that agent is read when the sweep comes back round to it. A pass whose last page was an ordinary one, even one whose keys cross into the next agent, leaves the cursor at the agent it stopped in: the next pass reads that agent again, and a full page inside it moves the scan past it. The operator's run does not skip. The pass keeps the last key it read in each agent it moved past, in memory for that pass only, and once it has read every other key (the keys before its cursor too) with pages left, it reads the rest of each such agent in order, without the skip, until the pages run out. So a row more than one page (LOOM_SENSITIVITY_SWEEP_MAX_ROWS_PER_PASS selected keys) into such an agent is reached in the same pass when the pages left cover the keys ahead of it. The cursor names no key inside an agent, so every pass reads the same pages of that agent: a row behind more than LOOM_SENSITIVITY_SWEEP_PAGES_PER_PASS x LOOM_SENSITIVITY_SWEEP_MAX_ROWS_PER_PASS selected-but-unlabelled keys of its own agent is not reached by the worker until those keys leave the window, and loom sensitivity-sweep --apply reaches it. security.md and the worker docstring say so. The pass outcome's truncated is true when any of these reads (the range after the cursor, the range before it, or the rest of an agent moved past) stopped before its end, or the candidates were cut to the limit; the cursor decision reads only the read that set the resume key. A pass starts at the agent the previous pass stopped in: the worker stores (org, namespace, agent) of the scan's resume key as its cursor in loom.worker_status (pass_context.set_cursor, written after apply): a JSON list [org, namespace, agent] for the agent the pass stopped in, or {"past": [org, namespace, agent]} for the place past it, bounded on those columns alone. The cursor holds no user id or memory key: loom.worker_status has a 30-day TTL and no erasure step, so a full sort key there would outlive the user's erasure. The erasure census reason for the table says the cursor names an org, a namespace and an agent. A pass that labels rows leaves the cursor at its agent, so the next pass reads that agent again and its remaining rows are labelled on the following passes. A pass that labels nothing because its candidates fail in apply leaves the cursor past its agent when every failed candidate is in that agent, so a row that fails on every pass is retried when the sweep comes back round to it and cannot hold every later pass in that agent. Failures in an earlier agent than the one the scan stopped in leave the cursor at the agent it stopped in, so that agent's unread rows are not skipped. A pass that started at a cursor and reaches the window's last key with pages left goes on from the first key up to the cursor (a third bound on the key read, stop_<column>), so rows that sort before the cursor are read in the same pass instead of waiting for a later one and possibly leaving the window; when it reads that whole range the cursor stays where the pass started. When a pass that started at the first key reads the window's last row the cursor is [] and the next pass starts again at the first key. When the candidates are cut to the limit, scan reports the last kept candidate's key as stored as its resume key (each candidate keeps the scanned row's sort key, since its own fields write an empty agent, user or session as -); the worker's next pass starts at that candidate's agent, and the rows the pass labelled are no longer selected. The cursor's JSON keeps non-ASCII characters as they are (ensure_ascii=False), so its length is the length the store keeps. A cursor that does not fit the store's 512 characters names the place past its namespace instead (or past the org, or the first key when even that does not fit), so an agent name that does not fit cannot stall the sweep; the agents after it in that namespace wait for the sweep to come back round. So selected rows the detector leaves unlabelled in other agents (for example {"spin": ...} keys, invalid-range ddd-dd-dddd strings, or Luhn-failing 16-digit order ids) cost one page each and do not keep a pass from reaching a later agent's or org's credential, unless more such agents than the page cap sit ahead of it. loom sensitivity-sweep --limit takes a positive integer. The operator's loom sensitivity-sweep pages through its whole scope until --limit candidates are found or the rows run out. scan takes the page size apart from the candidate cap: the worker passes LOOM_SENSITIVITY_SWEEP_MAX_ROWS_PER_PASS for both, and the CLI reads pages of max(--limit, LOOM_SENSITIVITY_SWEEP_MAX_ROWS_PER_PASS) keys, so a small --limit preview does not read the scope a few keys at a time. Its --limit help says it caps the candidates found, which are labelled with --apply, and names the default of 20000. A value that is not a positive integer, abc or 0, is refused with one message. The prefilter reads the key prefixes sk-, pk-lf-, AKIA, eyJ, AIza and gh[opusr]_ at a word boundary, as the detector does, so rows holding task- or disk- no longer take places in a page. The settings' comments and security.md say so.
  • Measured on a local ClickHouse server, from system.query_log: loom.memory with 2,000,000 rows over 90 days (four monthly partitions, merged), 40 orgs x 5 namespaces x 4 users, every fourth row holding a ten-digit epoch, 44,463 rows in the two-day window, on 32 cores. Pages of 500 keys.
    • The scheduled pass's filter matches no row (the sparse case). The previous single read with max_threads = 1: 1,400 ms, 2,000,000 rows. The same read at the default thread count: 152 ms; at 3 threads, the cap the background traffic class sets for workers and operator CLIs: 510 ms. Both read 2,000,000 rows, because FINAL turns off partition pruning on created_at. The two reads now: 78 ms for the key read (443,560 rows, one partition) and no second read, at the default thread count and at 3 threads alike.
    • The full filter, where every page is full (the dense case), re-measured on the shipped subquery form of the second read, on a fresh table of the same shape (2,000,000 rows, four merged monthly partitions, 40 orgs x 5 namespaces x 4 users, every fourth row an epoch, 44,433 rows and 11,107 matching keys in the window), three runs each. The previous single read, at the default thread count and with this PR's full filter: 115-136 ms, about 2,000,000 rows read, 212-277 MiB. Pages of 500 keys now: the key read 40-52 ms, 330,752-355,072 rows, 9 MiB; the FINAL read 58-75 ms, 38,912-72,576 rows, 15-24 MiB, on pages 1 to 3. One page of 20,000 keys, which holds all 11,107: the key read 58-60 ms, 445,546 rows, 9 MiB; the FINAL read 672-708 ms, 953,984 rows, 96-106 MiB. So a 500-key page costs about what the old read cost for a fifth of its memory, and a page that spans the whole window costs about five times the old read's time with less than half its memory.
    • A few matching rows spread across the key space (measured with clickhouse-local's profile events, since it has no system.query_log): 2,000,040 rows over 40 orgs in 23 monthly partitions, one matching row per org in the window, so one page holds keys from every org. The key-range form of the second read, which an earlier head of this PR had, selected 2,085,760 rows (418 MB peak): the range spans almost the whole table and FINAL prunes no partition. The subquery form selected 122,888 rows (804 marks, 76 MB peak); the key read itself selected 40.
    • A single key read that keeps only keys whose current version matches (GROUP BY the sort key, HAVING argMax(<the conditions>, version), LIMIT the page), which would make a short page impossible, measured with clickhouse-local on 2,000,000 rows of the same shape, two runs: in a two-day window (172,800 rows) 76-129 ms and 126 MiB against 71-104 ms and 4-39 MiB for the key read, and with no window 122-159 ms and 523 MiB against 98-200 ms and 4-44 MiB, with optimize_aggregation_in_order no better (161-707 ms, 86-231 MiB). The coarse filter moves from WHERE into HAVING, so the read groups every key in scope before the LIMIT and its memory grows with the scope, not the page. The two reads stay.
    • With no window, as the operator's run reads, pages of 20,000 keys: 45 ms for a full key page (983,424 rows) and 125 ms for a key read that matches nothing (2,000,000 rows), against 69 ms and 1,379 ms for the previous single read with max_threads = 1.
  • The detector's docstring said its high patterns mirror scripts/gates/check_no_secrets.py. It now says that only the key and token patterns do. Card numbers, SSNs and PINs are not repo-secret shapes, and the repo gate is unchanged.
  • No stored data changes on deploy. An unlabelled row written before this change stays unlabelled until a sweep labels it. The sweep reads only unlabelled rows, so a row already labelled medium (say, an email address next to an SSN) stays medium. The sweep cannot tell a detected medium from a caller's explicit one, and a caller's level wins, so I left that alone. security.md says so, and setting the row again with sensitivity: "high" relabels it.

Compatibility, rollout and rollback

  • Wire: no op or field changes. A memory.set / memory.bulk_set / memory.update with sensitivity unset and a value holding one of these shapes now gets high or medium where it got ''. A caller that sets sensitivity explicitly is unaffected.
  • Operator steps: none required. loom sensitivity-sweep --limit now caps the candidates found (labelled with --apply), not the rows read, so a run reads its whole scope until that many are found, and it refuses 0 or a negative value. LOOM_SENSITIVITY_SWEEP_MAX_ROWS_PER_PASS now also sets the sweep's page size, and the new LOOM_SENSITIVITY_SWEEP_PAGES_PER_PASS caps the pages per pass. The worker stores its cursor, an org, a namespace and an agent, in loom.worker_status. Backlog rows (older than the sweep's two-day window) are labelled by loom sensitivity-sweep --apply. During a rolling upgrade, a row written through build N-1 stays unlabelled until the daily sweep on build N labels it.
  • Rollback: reverting stops detecting the new shapes and returns the sweep to one read per pass. Rows already labelled high keep their label and stay unembedded. The sweep's cursor row in loom.worker_status stays and is not read.

Tests

  • tests/unit/test_memory_sensitivity.py: positive and negative cases for each shape.
    • Sweep paging (tests/unit/test_pipeline_actor_sensitivity_gauges.py, clickhouse-local): five selected-but-unlabelled rows sit ahead of a PIN row in the same agent with a page size of two. One page finds no candidate, a scan of ten pages labels the PIN row, and the worker pass with ten pages moves past the agent after its first page, comes back to it once the rest of the window is read and labels the PIN row; with one page it leaves the cursor past the agent. A scan capped at two pages stops there and reports itself truncated. Three passes of three pages of two over seven {"spin": ...} rows ahead of a PIN row in one agent leave the PIN row unlabelled and the cursor at [] on each pass, and the operator's scan with no page cap finds it, and the CLI's dry run, with its page size lowered to two keys, reaches the PIN row behind the same rows in more than one page. loom sensitivity-sweep --limit parses 1 and refuses abc, 0 and -1, each with the message that it is not a positive integer. Pages of two rows that end inside a user, at a user boundary and at a namespace boundary return each selected row exactly once and reach the PIN row. Eighteen rows in org acme (six epoch seconds, six epoch milliseconds and six 19-digit ids), more than a pass's two pages of two, do not keep the pass from labelling a ghp_ token in org zeta, and neither do six prose rows in org acme that name a credential word without an assignment (I forgot my password, the secret of a good stew is time, cd $(pwd) && make). A page of three keys over six row versions holds all three keys (gone, whose current version is tombstoned; vault_door, whose current version is labelled high, as apply writes it; twice, with two unlabelled versions), and the FINAL read yields only twice, once. Three passes capped at one page of two, over two pages of {"spin": ...} rows in agent a and a PIN row in agent b: the first finds nothing in its page of a, so its cursor is past a; the second labels the PIN row and leaves the cursor at []; the third starts again at the first key; every cursor holds the org, namespace and agent only. One pass of three pages of two over more than a page of {"spin": ...} rows in each of agents a and b, ahead of a PIN row in agent c, labels the PIN row. A pass of four pages of two over three {"spin": ...} rows in each of agents a and b moves past both, reads the rest of a on its last page and none of b, and reports itself truncated. With a limit of two and three pages over [spin, PIN, PIN, PIN] under an empty user id, the first page gives one candidate and the second two, so the third is cut: the scan applies two, resumes after the second's stored key (user id '', not -), and the next scan labels the third. The pass tests write the rows a pass labels as a new high version in a part of their own, keeping the old unlabelled version, as apply does before a merge. Three passes of three pages of two over five PIN rows in one agent: the second pass's first page holds only the keys the first pass labelled and gives back no row, the pass reads on and labels the next two, and the third labels the last; the cursor stays at the agent until the last row is read. Four passes of three pages of two over six PIN rows in one agent, with the second pass failing in apply: a pass that labels rows leaves the cursor at that agent, the failed pass leaves it past the agent, and the next reaches the last row with pages left, goes back to the first key and labels the rows that failed; all six are labelled. A pass that finds a PIN row in agent a, reads on to agent d and fails to apply it leaves the cursor at d, and the next pass labels the PIN row in d. A pass with its cursor at agent b and a PIN row in agent a labels the row with two pages and leaves the cursor at b; with one page it does not read it. Two passes of two pages of two over five PIN rows in agent a already labelled high whose unlabelled versions stay until a merge, and a PIN row in agent b: the first pass reads both pages inside a, finds nothing and leaves the cursor past a, and the second labels the PIN row in b. Two passes of one page of two over a {"spin": ...} row in agent a, and a {"spin": ...} row then a PIN row in agent b: the first pass's only page spans a and b, gives a row for each key and nothing to label, so its cursor stays at b, and the second labels the PIN row. The same two passes with the row in agent a already labelled high and its unlabelled version kept until a merge: the page's only stale key is in a, so the cursor still stays at b and the second pass labels the PIN row. Three passes over more than a page of PIN rows in agent a and one in agent b, with apply failing on every pass: the cursor moves past a, the next pass reaches the last row, and the third starts again at the first key. Three passes over more than a page of {"spin": ...} rows in an agent whose name does not fit the cursor, ahead of a PIN row in another namespace: the first leaves the cursor past the namespace and the second labels the PIN row. A cursor keeps the agent, decodes with the user, session and memory key emptied, names the place past the agent when asked to or when the scan stopped past it, decodes a past cursor to its columns alone, names the place past the namespace for an agent longer than the store holds, keeps a 200-character CJK agent name whose cursor fits, and reads a cursor that is not one of its forms as none. A page past agent a, on clickhouse-local, reads the next agent a\x00b. The pass tests share one helper that records apply's candidates. ApplyResult.failed holds each failed candidate with its error, and errors is read from it. sensitivity_sweep_max_rows_per_pass and sensitivity_sweep_pages_per_pass are on the settings ratchet's list of caps that refuse 0 (tests/unit/test_call_site_knobs.py, through the live-override path), and a pages-per-pass value of 1000 is accepted and 1001 refused. A pass whose time runs out after its first page, over two PIN rows in agent a with selected-but-unlabelled rows between them and one in agent b, applies the PIN row it found, reports itself truncated and stores its cursor at a (the test's clock moves past the pass's time after the first page's FINAL read); given the time, the same pass labels all three. sweep.scan takes limit, page_size and pages as required keywords, so a caller names its candidate cap, page size and page cap: the worker passes the settings, the CLI passes --limit, its page size and None, and the analyzer drive passes a limit and a page of 10. A SweepCandidate requires its sort key, which scan resumes from. The defaults snapshot pins sensitivity_sweep_pages_per_pass at 10.
    • Free-text PIN positives: BADGE_PIN=4471, atm_pin: 4471, PIN_CODE=4471, CARD_CVV=123, security_code: 5512, cvv code: 123, CVV number is 123, cvc code 123, pass code: 4471, PIN for the front door is 4471 and passcode for the garage: 908712. Negatives: spin: 4471, PIN for the front door 4471, PIN for one two three four is 4471, and the versions and dates above.
    • Card positives: Visa, Mastercard (51-55 and 2221), Amex (grouped and ungrouped), Diners and Discover cards; a 19-digit Visa whose first 16 digits fail Luhn; a card followed by its expiry and CVV, or after a date or another number; an IBAN before EUR, and one after an IBAN-shaped token.
    • Negatives: Luhn-failing card runs, Luhn-valid 19-digit hashes (one with a Visa prefix), a yyyymmdd run, a 20-digit run, two phone numbers side by side, a row of ports, tables of eight and nine 4-digit numbers, an IMEI, every invalid SSN range, dates, "PIN 3 of the header", "pinned 4471 rows", pin as a verb and as a connector pin (pin 115, pin #115), a 6-digit Indian PIN code (PIN: 560001, PIN code 560001, also not selected by the sweep's filter), fullwidth digits, a valid spaced IBAN whose groups read as a Luhn-valid Visa number (medium), an IBAN failing mod-97, and two mod-97-valid tokens, one with an unregistered country code (XY54 ...) and one with the wrong length for its country (a 20-character DE86 ...).
    • Phone numbers stay medium, including a 13-digit +49 number, the same number written without its +, and epoch milliseconds.
    • Keyed secrets: {"cvv_code": "123"}, {"cvcNumber": "987"}, {"ssn_number": "123456789"}, {"ssn_no": "123-45-6789"}, {"social_security_number": "123-45-6789"}, {"pin": "4471"}, {"pin_code": "4471"}, {"pin__code": "4471"}, {"pin/code": "4471"}, {"pincode": "4471"}, {"badge_pin": "4471"}, {"badgePin": 9087}, {"pin_number": "4471"}, {"pinNumber": "908712"}, {"PIN": "4471"}, {"CVV2": "123"}, {"cvv_2": "123"}, {"pass_code": "4471"}, a nested security-code, {"ssn": "123-45-6789"}, {"ssn": "123456789"}, a card under any key, and a connector pin {"pin": 115} are high. These are not: {"pin": "560001"}, {"zip_pin": "560001"}, {"address": {"pincode": "560001"}}, {"pin_count": 4}, {"pin": "A1"}, {"pin": "12"}, {"pin": true}, {"spin": "4471"}, an SSN in a never-issued range, and a Luhn-failing or short pan.
    • reads_high on raw chunk text (human_text) reads {"badge_pin": "4471"} and {"ssn": 123456789} as high, and {"pin_count": 4471}, {"pin": "560001"}, {"pin": "4471abc"}, {"pin": 4471.5} and a 20-digit pin as not.
    • An explicitly low row whose value reads as high is left out by observe_extract, by the profile fold (tests/unit/test_profile_consolidation.py) and by the structured profile build (tests/unit/test_profile_schema.py).
    • {"security.code": "5512"} is pinned as selected and labelled high by the sweep: ClickHouse stores it as {"security":{"code":"5512"}} in value_json, and the sweep also reads value, which keeps the key whole.
    • A key written between a page's two reads, sorting before the page's last key, is read once and the page's last key is not skipped (clickhouse-local).
    • The cross-path test asserts the superset: a value that reads as high is selected by the credential filter alone, the part of the scheduled pass's filter that selects high rows. The other superset tests (new shapes, stored JSON text, clickhouse-local) check every high case against that filter too and keep the full filter for medium cases.
    • The sweep's prefilter is pinned on clickhouse-local, using the repository's skip-if-missing helper. RE2 match() runs on the json.dumps text and on toString(CAST(... AS JSON)) for 56 object values (ATMPin, Spin and ATMPIN among them, spin and unpin as negatives, cvvcode, ssnno, securitycode and PINcode as positives, {'pin"': ...}, {"door\\pin": ...}, "pin\n", p_in as a negative, "CVV:", "pin ", "SSN:", "Security Code (CVV)", {"pin": " 4471"}, pass_code, cvv_2, cvv_code, pin_code, pin__code, pin/code, pincode, ssn_no, social_security_number, {"pin": "\t4471"}, BADGE_PIN=4471 and PIN for the front door is 4471 among them, and the postal codes {"pin": "560001"} and {"address": {"pincode": "560001"}} as negatives) and on the raw text of 22 strings (CARD_CVV=123, atm_pin: 4471 and cvv number is 123 among them). Both lists hold credential-word assignments (db password: Tr0ub4dor&3xyz, client_secret = 9f8e7d6c5b4a3210ffee, {"note": "deploy:\npassword=hunter2222"}, {"note": "api_key = abcdefgh12345678"}) and lone card numbers (mastercard 5500000000000004, amex 378282246310005, {"card": 4111111111111111}, and lone and grouped cards after 番号, a no-break space and an ideographic space), so the assignment alternative's Unicode whitespace class and the lone-card alternative are checked in RE2 with the class bound as a parameter. Every fake credential is also checked against the credential filter, as written and as json.dumps text. The objects include keyed PINs and SSNs, a dotted badge.pin, a \u000B, curly quotes, a \/, a \n a grouped 19-digit Visa, and phone numbers grouped by \n and by no-break spaces. Every case the detector labels is selected. The unlabelled cases it selects are pinned as exactly {"spin": ...}, {"unpin": ...}, {"Spin": ...} and {"ATMPIN": ...}; the other unlabelled ones ({"pin_count": 4}, {"pin": "A1"}, pin 128 rows, GPIO pin 115, SHA256SUMS, the postal codes) are not selected.
    • JSON values are read by scalar. A 200,000-character digit run reads in one pass, and so do 200,000 spaces or newlines after pin, PIN is or cvv, and 200,000 spaces after "pin": or "pin": " in raw JSON text, and after PIN for or PIN for the. So do 20,000 IBANs in one value. Escaped quotes are timed on their own, at 5,000 and 20,000, the sizes that took 0.45 s and 7.17 s before the key bound. The test (test_long_runs_are_read_in_linear_time) times each group at a quarter of its size and at its full size, the fastest of three reads each, and asserts the full size takes less than 8 times as long: a linear read grows about 4 times and a quadratic one 16 times, so a slow runner does not fail it.
    • The coarse sweep filter selects every new shape, including in stored JSON text with \n, \f, \b, \u000b and \u201c escapes. It does not select a bare pin or passcode word, pin 128 rows, GPIO pin 115 or SHA256SUMS.
    • high rows carry the credential probe shape, and an IBAN or bank-account question, plural or not, counts as contact intent.
  • tests/integration/test_sensitivity_high_canary.py: a PIN, a card, an SSN and an object with a badge_pin key written by memory.set read back as high with no embedding row and no search hit. An IBAN reads back as medium and is embedded. On read-back the test compares the value, level, tags, memory_type, agent, actor, source_class, expires_at, on_expire, expire_reason, pinned, status and lock_mode against the expected row, and reads the stored row's identity tuple (org, namespace, agent, user_id, session_id) from ClickHouse. The test also writes a plain row afterwards and waits until it is embedded, so the "no embedding row" check runs after the labelled row's embedding would have landed.
  • At this head: make format and make lint pass and every generator is current. CI runs make typecheck, the unit suite (the clickhouse-local tests included) and the integration suite; none of them has run on this head yet.
  • History, on heads before the settings-catalog merge: at bf37e8e, make format lint typecheck was clean and the sensitivity, sweep, CLI, package-contract, public-copy and doc-link unit tests passed; at 4c02c2f, make test-unit passed (tests/unit 21469 passed, 20 skipped, 1 xfailed; bench 191 passed) and tests/integration/test_sensitivity_high_canary.py passed against a local server and ClickHouse (13 passed). The key read, the prose and card prefilter tests and the FINAL read test came after those heads.

AI assistance in the code (leave one; writing this description with AI is fine):

  • AI-generated (an agent wrote most of the diff): Claude Code. The patterns, the Luhn and mod-97 checks and the coarse filter were checked against the cases above and against ClickHouse match().

  • I can explain every line of this diff and how it interacts with the rest of Loom.

Checklist

  • make format-check, make lint, make typecheck and make test-unit pass; the integration suite passes if server behaviour changed. (make format and make lint pass on this head; CI runs the others.)
  • Generated files are regenerated in this PR, not by hand: the SDK op tables, docs/reference/configuration.md and the docs/reference/ tables (python scripts/codegen/docs_reference.py), the reach manifest, schemas/schema.sql (make schema-dump) and the Codex plugin copies (python3 scripts/codegen/agent_plugin_sync.py).
  • A new migration is additive and numbered after the latest on main; no merged migration is edited.
  • A behaviour change to any file a plugin ships (hooks/, lib/, bin/, skills/, .mcp.json, the Codex plugin-defaults.json) bumps both plugin manifests' version, and no other open PR uses that version.
  • The frontend builds (npm --prefix frontend run build) and its tests pass, if frontend/ changed.
  • Docs under docs/ describe the system as it now is, and this description names any operator steps and wire changes.
  • Repository text has no dates, people, host names, internal namespaces, ticket or decision numbers; the history goes in this description (tests/unit/test_public_copy.py).
  • Commits are signed off (git commit -s), as CONTRIBUTING.md asks.

🤖 Generated with Claude Code

zlareb1 and others added 30 commits October 20, 2026 15:25
…gh, and IBANs medium

A payment card number (13-19 digits with a network's leading digits and a
passing Luhn check), a US Social Security number outside the never-issued
ranges, and a PIN, passcode, CVV/CVC or security code stated with its 3-8
digit value now read as high: never embedded, read by key and audited. An
IBAN that passes the ISO 13616 mod-97 check reads as medium.

The sweep's coarse ClickHouse filter selects the new shapes; every high row
stays the `credential` probe shape, so the scheduled pass labels them by
default.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: zlareb1 <[email protected]>
…s a stated value

A card number is now 13-19 digits on group boundaries of a digit run, so
"4111 1111 1111 1111 12/29" and a card after another number are found. A
bare `pin` takes its value only after `is`, `was`, `:`, `=` or `#`, so
"pin 128 rows" and "GPIO pin 115" stay unlabelled; each whitespace run in
the PIN pattern has its own anchor, so a long run of spaces is read once.
A spaced IBAN followed by an uppercase word is checked without the word.
The docs list the high shapes one per bullet and say that the sweep
leaves a `medium` row as it is.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: zlareb1 <[email protected]>
… needs a value

Grouped digits count as a card only in a card's grouping (4-4-4-4,
4-4-4-4-3, 4-6-5, 4-6-4) or as one 13-19 digit group, so two phone
numbers side by side are not read as one card. A bare `pin` no longer
takes its value after `#` (a connector pin), an IBAN after an IBAN-shaped
token is found, and the sweep's coarse filter selects a PIN label only
when digits follow it, so ordinary uses of the word do not fill the pass's
row limit.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: zlareb1 <[email protected]>
… postal code

A card's leading digits now fix its length (Visa 13/16/19, Mastercard 16,
Amex 15, Diners 14, JCB and Discover 16-19), so a row of port numbers or a
15-digit IMEI is not a card, and a grouped window counts with at most one
other group on each side. A `PIN code` takes 3-5 digits, since a 6-digit
one is an Indian postal code. The new patterns are ASCII-only like the
sweep's RE2 filter, an IBAN's check digits must be digits, the coarse IBAN
branch needs a word boundary and two groups, and a question naming an
IBAN or bank account counts as contact intent. The security page says
`high` where its readers now leave out more than credentials.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: zlareb1 <[email protected]>
…s 3-5 digits

`match()` runs on the stored column, where an object value's line break
is the two characters `\n`: the PIN and IBAN branches now take an escape
as a word boundary and as whitespace, and the PIN branch follows the
detector's grammar instead of any run of letters. A bare `PIN` takes 3-5
digits like `PIN code`, since `PIN: 560001` is an Indian postal code. The
IBAN pattern has room for an IBAN-shaped token before a 32-character IBAN,
and the contact-intent terms take plurals.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: zlareb1 <[email protected]>
… \u escapes reach the sweep

A grouped card may have up to three short groups around it, two of them
after it, so "card, MMYY, CVV" and "date, card" are labelled while a table
of eight or more numbers is not. The sweep's coarse PIN and IBAN branches
take a `\uXXXX` escape as a word boundary, since `json.dumps` writes
non-ASCII characters that way. Only a bank account number is contact
intent, not any account number. A connector pin written as an assignment
reading as a PIN is documented and pinned by a test.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: zlareb1 <[email protected]>
…ry JSON control escape counts

A bare `pin` needs `is`, `was`, `:` or `=` before its digits in the coarse
filter too, so `pin 128 rows` and `GPIO pin 115` no longer take places
under the pass's row limit. `\b`, `\f` and `\u000b` count as a boundary
and as whitespace beside `\n`, `\r` and `\t`, so a PIN after any control
character the detector reads is selected.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: zlareb1 <[email protected]>
… to the sweep

JSON writes a control character such as a vertical tab as `\u000b` even
with `ensure_ascii=False`, so a raw chunk holding "PIN is\v4471" now reads
as high. The sweep's coarse filter no longer takes `\b` as whitespace,
which the detector does not either, so such a row is not selected on
every pass.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: zlareb1 <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: zlareb1 <[email protected]>
…e their real ranges

A single ungrouped digit group counts as a card only at 15 digits (Amex)
or 16; 14 and 19 come only from a printed grouping. So a 19-digit
decimal hash or a 13-digit phone number written without its `+` no
longer reads as a card. The network table uses the real leading digits:
Mastercard 51-55 and 2221-2720, Diners 300-305, 3095, 36, 38-39, JCB
3528-3589, Discover/UnionPay 6011, 62, 644-649, 65.

The security page lists the turns conversation search ranks among the
raw text served as it is, and the knobs and stack docstrings say
contact intent covers a bank account.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: zlareb1 <[email protected]>
`{"pin": "4471"}`, `{"badge_pin": "4471"}` and `{"ssn": "123456789"}`
now read as high: `detector_text` adds the stated form of a value held
under a key whose last word is pin, passcode, cvv, cvc, security code,
ssn, card number or pan, when the value has that secret's shape. Other
keys still label nothing. The sweep's coarse filter selects such keys.

JCB and Discover/UnionPay take 16 or 19 digits, the lengths a card can
be read at; a Luhn-valid 19-digit hash with a Visa prefix, an ungrouped
Amex number, a 19-digit Visa whose first 16 digits fail Luhn, and epoch
milliseconds have tests; the grouped-window loop does its cheap checks
first; the canary reuses `_live_vectors`.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: zlareb1 <[email protected]>
…eads JSON key pairs

`{"pin": "4471"}` is read as `pin is 4471`, `pin_number` as `pin number
is`, and passcode, cvv, cvc and security code as `passcode is`, so the
free-text rules decide the length and `{"pin": "560001"}`, a postal code,
stays unlabelled. A card number is found under any key, so there is no
card key. `reads_high` reads the same `"key": value` pairs in raw JSON
text, and value_reads_high and reads_high share one high-only check.

security.md says a caller's explicit level sets the stored label while
the readers that send a value to a model still leave out one that reads
as high, and a test pins it. The sweep's prefilter takes a space before
the digits, and its RE2 behaviour on ClickHouse's own JSON text is pinned
by a clickhouse-local test.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: zlareb1 <[email protected]>
… from the detector's

`KEYED_SECRET_WORDS` lists each key word split where a key may put a
separator, with the label its value is stated under (`cvv is 123`,
`security code is 5512`, `pin is 4471` for `pin_code`), and the sweep's
prefilter builds its key alternatives from it, so `pass_code` and
`cvv_2` are selected and the two lists cannot drift. A raw `"key": value`
pair's value must end where the number does, so `4471abc`, `4471.5` and
a 20-digit run are not read as a shorter number.

The four readers that drop a high-reading value say "whatever its label",
and a test pins it on the profile fold; security.md puts the fail-closed
rule in its own paragraph and says a `security.code` row is not labelled
by the sweep.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: zlareb1 <[email protected]>
…lter skips 6-digit pin values

`_KEYED_PAIR` puts the spaces inside a quoted value after its quote, so
200,000 spaces after `"pin":` read in about 30 ms instead of growing with
the square of the run. The sweep's prefilter selects a key stated as
`pin` only with a 3-5 digit value, so postal codes are not re-selected on
every pass, and allows any run of non-alphanumeric characters between a
key's words, as the detector splits a key (`pin__code`, `pin/code`). The
SSN key word is one constant both modules read; `reads_high` runs the
cheap check before the key pairs; the two fold tests are one
parametrized test.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: zlareb1 <[email protected]>
…ad, and the detector says it is a lower bound

A label starts after anything but a letter or digit, so `BADGE_PIN=4471`,
`atm_pin: 4471` and `CARD_CVV=123` read as high and `spin: 4471` does not;
two-word labels take `_` or a space, `cvv code`, `cvc number` and
`pass code` count, and "PIN for the front door is 4471" reads with `for`
and up to three words. The label strings are shared with the sweep's
prefilter. SSN keys include `ssn_number`, `ssn_no` and
`social_security_number`, read by their last three words, and the
prefilter takes JSON's whitespace escapes before a keyed value.

The module docstring and security.md state that the detector is a
deterministic lower bound over the listed label forms, with an operator's
extraction policy as the catch-all, and security.md names the double-space
and dotted card gap.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: zlareb1 <[email protected]>
…ar is one function

The sweep's prefilter allows any run of characters that are neither
letters, digits nor a quote after a key's last word, so `"CVV:"`,
`"pin "`, `"SSN:"` and `"Security Code (CVV)"` are selected and
`pin_count` is not. A keyed value is stripped of ASCII whitespace only,
so the stored value, a raw chunk and the prefilter give one answer.
`pin_grammar(space)` builds the qualifier and separator for both the
detector and the prefilter; the label strings are named by the value
lengths they take; `GPIO pin number 115` is named as a trade-off.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: zlareb1 <[email protected]>
…be the whole string

`_keyed_secret` looks up a key's last one, two and three words as tuples
in `KEYED_SECRET_WORDS` and `SSN_KEYS`, with one-word forms (`pincode`,
`passcode`, `cvv2`, ...) as their own entries, so `p_in` is not `pin`.
`_KEYED_PAIR` requires a quoted value to close after its digits, so
`"4471 abc"` is not a PIN, and reads any quoted key. The sweep's prefilter
reads JSON escapes in a key's separators (`"pin\n"`), names the direct
`pin code` label the detector also uses, and a test pins that a dotted
`security.code` row is not selected.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: zlareb1 <[email protected]>
… an escaped quote

`KEYED_SECRET_WORDS` and `SSN_KEYS` add each multi-word entry written as
one word (`cvvcode`, `ssnno`, `SOCIALSECURITYNUMBER`) instead of listing
them by hand. `_KEYED_PAIR` and the sweep's key separator read an
escaped quote or backslash inside a key (`pin\"`, `door\\pin`). The direct
`pin code` form skips a position (`PIN code 100 of the batch`), and the
postcode-like label is built from `PIN_CODE_LABEL`.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: zlareb1 <[email protected]>
…y word where the detector does

`_KEYED_PAIR` bounds a key to 200 characters, so a run of escaped quotes
reads in linear time (100,000 in under a second; 20,000 took 7 s
before). The sweep's prefilter starts a key's first word after a
character that is neither a letter nor a digit, a JSON escape, or a
capital after a lowercase letter (`badgePin`), so `spin` and `unpin` are
not selected. The detector also splits a key at every change of case, so
`PINcode`, `CVVcode` and `SSNno` read as their words.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: zlareb1 <[email protected]>
…nd `Spin` is one word

The detector reads a key with the camelCase split, and reads a run of two
or more capitals before a lowercase word a second way (`ATMPin` is `ATM`,
`Pin`; `PINcode` is `PIN`, `code`), so `Spin` and `ATMPIN` are one word
and are not labelled. The sweep's prefilter no longer copies that rule:
it selects any key that ends in a label, a superset, and the detector
decides. The few non-secret rows it selects (`spin`, `unpin`, `ATMPIN`)
are pinned by the clickhouse-local test and documented.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: zlareb1 <[email protected]>
…ate is not a PIN

The scan reads its window oldest first on a (created_at, memory_key,
memory_id) cursor, up to ten pages of the pass's row limit or until that
many rows are labelled, so selected rows the detector leaves unlabelled
can no longer hide a later high row from every pass. A stated PIN's
value ends where its number does, so `the tzdata pin is 2024.1` and
`base image pin is 2024-01-15` are not PINs. Comments are cut to the
fact each carries, with the label forms listed in security.md only.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: zlareb1 <[email protected]>
…ord boundary in the prefilter

The CLI sweep reads pages until --limit candidates are found or the rows run
out, so a high row behind a page of selected-but-unlabelled rows is reached.
The prefilter reads sk-, pk-lf-, AKIA, eyJ, AIza and the GitHub prefixes at a
word boundary, as the detector does, so task- and disk- rows are not selected.
A stated PIN value must end at its number: a version, a date with slashes or a
run-on word is not a PIN. The scheduled pass's ten-page cap is documented and
pinned by a test.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: zlareb1 <[email protected]>
zlareb1 and others added 2 commits October 21, 2026 02:21
The analyzer drive and the statements test pass `page_size` to `scan`,
which requires it. `SweepCandidate.sort_key` is required, and the page
size is read from the bound `LIMIT` only. The linear-time test asserts
growth from n to 4n instead of a wall-clock bound, the canary write
test compares the whole `memory.get` answer, and security.md says the
worker selects the shapes in `LOOM_SENSITIVITY_SWEEP_SHAPES`.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: zlareb1 <[email protected]>
…agent

Pages of versions labelled before the parts merge give no row, so they never
moved the scan past their agent, and a pass spent on them left its cursor at
the same agent. Such a pass now leaves the cursor past that agent. The CLI
tests read more than one page and check that --limit refuses 0, and the
paging settings' comments are two lines.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: zlareb1 <[email protected]>
@zlareb1 zlareb1 changed the title The sensitivity detector labels card numbers, SSNs and stated PINs high, and IBANs medium The sensitivity detector labels card numbers, SSNs and stated PINs high and IBANs medium, and the sweep pages its window from a per-agent cursor Oct 21, 2026
zlareb1 and others added 22 commits October 21, 2026 02:51
…versions

A pass that found nothing and ran out of pages left its cursor past the
agent it stopped in even when its last page was an ordinary one that
crossed into the next agent, so that agent's later rows waited for the
sweep to come back round. The pass now records whether its last page's
FINAL read gave fewer rows than keys and moves past the agent only then.
ApplyResult keeps each failure once, with its error, and the module has
one name for the coarse filter, coarse_shape_re. The worker docstring
and security.md are re-wrapped.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: zlareb1 <[email protected]>
…es its default

The phone branch of the coarse filter takes the escape-aware whitespace
class between its groups, so a number grouped by `\n` or a no-break space
in stored JSON text is selected, as the detector labels it. `--limit`
refuses a non-integer with the same message as 0, and its help names the
default of 20000.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: zlareb1 <[email protected]>
…ield names every shape

- scan sets `truncated` when any of its reads stopped before its end or the
  candidates were cut, and `last_page_short` only from the read that set the
  resume key; `_read_range` returns its own result, and the worker's stuck
  check no longer reads the memory key.
- The memory.set / memory.update `sensitivity` description names card numbers,
  SSNs, PINs and IBANs; the op reference is regenerated.
- The CLI reads `--limit` as already parsed.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: zlareb1 <[email protected]>
…urrent row

The skip check compared the FINAL read's row count with the page's key count,
so a key written into the range between the two reads could stand in for a
labelled key that gave no row, and the scan moved past an agent whose later
rows were unread. It now compares the two key sets.

The cursor rules are kept in security.md only; the worker docstring, `scan`
and `_stuck` point there. The pages-per-pass setting's comment backticks the
setting it names.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: zlareb1 <[email protected]>
_resume_past_agent says what the helper decides: whether the next pass
starts past the agent this pass stopped in.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: zlareb1 <[email protected]>
…nd the sweep cursor's length counts stored characters

The okf export help, the include_high and examined field comments, the passage,
digest and evidence comments and their generated pages now say a chunk is kept
back when it holds a high shape (a credential, card number, SSN or stated PIN),
not only a credential. cursor_text writes its JSON with ensure_ascii=False, so a
non-ASCII agent name that fits the 512-character store stays the cursor.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: zlareb1 <[email protected]>
A short sweep page is one whose FINAL read gave no current row for one of its
keys, which is what the key-set comparison checks. Consolidation's `examined`
excludes rows labelled `high`, not every labelled row. The export docs say the
server audits every released item, and the CLI paragraph is rewrapped.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: zlareb1 <[email protected]>
…ts pages per pass are capped at 1000

A page cap past what a pass can read inside its 900 s deadline would cancel
every pass before it stores its cursor.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: zlareb1 <[email protected]>
…'s stale-key flag is named for what it records

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: zlareb1 <[email protected]>
…stores its cursor

The scan takes a time budget; the worker passes half the pass deadline, so a pass whose
pages cost more than the deadline allows applies what it found, stores its cursor and
reports truncated instead of being cancelled at the same place every time. The
pages-per-pass and shapes comments are two lines, the deadline detail is in security.md,
the long-agent cursor rule names the cursor at such an agent too, and the pages-per-pass
ceiling is tested.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: zlareb1 <[email protected]>
…or enforces

The worker reads the deadline from its registry spec instead of working it
out again from the interval, and the worker test pins 450 s at the default
daily interval.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: zlareb1 <[email protected]>
…ry, and its stale-key check reads as a set difference

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: zlareb1 <[email protected]>
…ch a test now names

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: zlareb1 <[email protected]>
… agent

A page that crosses from an agent with a key waiting for a merge into the
next agent leaves the cursor at the next agent, so its later rows are read.
The export-okf --include-high help in cli_tree.json matches the CLI, and the
readers' comments name every high shape, not only credentials.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: zlareb1 <[email protected]>
… before the earlier-agent case

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: zlareb1 <[email protected]>
…INAL read

The test used a counted sequence of clock reads, which pinned how often scan
reads the clock. It now uses ManualClock and moves it past the pass's time
once the first page's FINAL read returns. scan no longer guards against a
limit below 1, which no caller passes, and its test is gone. The CLI limit
test also refuses `abc` and checks the message for each bad value.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: zlareb1 <[email protected]>
The structured profile's filter comment and security.md's list of what reads
as high cover every high shape, not credentials only.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: zlareb1 <[email protected]>
A page past an agent now bounds on (org, namespace, agent) alone, so it
skips no stored agent name such as `a\x00b`; the cursor writes that place
as {"past": [...]}. The structured profile build is listed among the
readers that leave out a value reading as high whatever its label, with a
test for a low-labelled PIN.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: zlareb1 <[email protected]>
The cursor names no key inside an agent, so each pass reads the same
pages of it: a row behind more than pages-per-pass x rows-per-pass
selected-but-unlabelled keys of its own agent waits until they leave
the window, and the operator's run reaches it. security.md, the worker
docstring and the scan comment say so; a clickhouse-local test pins it.
The resume_after comment names both cases that leave it None.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: zlareb1 <[email protected]>
`AGENT_KEY` holds the sort key's agent columns and `past_agent` the place
past an agent, replacing `past_key(key, "agent")`, the `[:3]` slices and
`_agent`'s own column list. The `scan` docstring says `only_shapes` narrows
the ClickHouse filter and that `value_json` is read too, and the
`sensitivity_sweep_shapes` comment names `other` (IBAN-only rows) as left
to `--only-shape` with `phone`.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: zlareb1 <[email protected]>
…applies phone and IBAN rows

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: zlareb1 <[email protected]>
@zlareb1
zlareb1 merged commit 74ca3e3 into main Oct 21, 2026
20 of 22 checks passed
@zlareb1
zlareb1 deleted the feat/sensitivity-pii-shapes branch October 21, 2026 07:55
zlareb1 added a commit that referenced this pull request Oct 21, 2026
…ercise (#120)

* The tests #95 left red follow the code they exercise

- test_memory_sensitivity calls _set_prepare_value with the write alone: #95 moved
  restated onto _SetWrite.
- test_memory_webhooks builds its SweepCandidate with the sort_key #89 made required.
- test_settings_env_contract probes memory_webhook_backoff_steps_seconds with a valid
  list of steps, as it does other validated strings.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: zlareb1 <[email protected]>

* The sweep candidate's sort key comes from its own identity tuple

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: zlareb1 <[email protected]>

---------

Signed-off-by: zlareb1 <[email protected]>
Co-authored-by: Claude Opus 5.5 <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant