Skip to content

Erasure runs on replicated tables, search serves each session's row of a key, and the write gates read values, JSON credentials and long names right - #146

Merged
zlareb1 merged 166 commits into
mainfrom
fix/same-key-search-and-replicated-erasure
Nov 2, 2026
Merged

zlareb1 merged 166 commits into
mainfrom
fix/same-key-search-and-replicated-erasure

Conversation

@zlareb1

@zlareb1 zlareb1 commented Oct 23, 2026 •

Copy link
Copy Markdown
Member

Changelog category (leave one):

  • Bug Fix (user-visible misbehavior in a release)

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):

User erasure and memory.clear run on replicated and shared ClickHouse tables. Search serves each session's row of a shared key with its own text. A value update is no longer filed as a duplicate, a credential inside a JSON value is labelled high, and entity names over 256 characters are dropped, so a long name no longer fails a search. memory.apply's min_score compares a hit's similarity, where any value above 0 matched nothing. A memory.bulk_set entry that repeats a stored value with a new ttl_seconds sets the expiry.

Why

Six defects, each also on main, found while reviewing the conflict-resolver work:

  1. Erasure on replicated tables. ReplicatedMergeTree and SharedMergeTree refuse a mutation whose WHERE holds a subquery (Code: 36 … statement with subquery may be nondeterministic) or calls now(). 17 erasure and memory.clear call sites (22 statements) did one or both, so a user erasure failed at its first such step. On a replicated loom database seeded for two users, the base commit ends failed with 16 residue rows.
  2. Search and one key in several rows. A row is (org, namespace, agent, user_id, session_id, memory_key), so extraction writes the same key once per session and two users may write one key, but several search stages keyed hits on (namespace, memory_key):
    • bodies="unit" gave both hits the same session's text;
    • the BM25 merge, the cross-plane dedup and chunk-prefix drop, the anchor pool, the key-match and digest-descent arms, the unmatched and recency legs and the paging tail dropped the second session's row (the dedup and the anchor pool even when the rows' excerpts only opened alike);
    • the duplicate and superseded lookups answered for a key across rows, so a duplicate row was served whenever another row held the key active.
  3. The duplicate gate swallowed value updates. "my PB is 27:10" → "beat my PB, 26:30" shares no content word after canonicalisation. same_content_words read the low overlap as a paraphrase, so the update was stored duplicate and the old value kept answering.
  4. Credentials inside JSON values. detector_text puts each key and scalar on its own line, so {"password": "hunter2xyz123"} never met the password: <token> pattern. The raw-text path (reads_high) and the sweep's prefilter missed the quoted form too.
  5. Entity names over 128 KiB. A bound parameter travels as one HTTP form field, which ClickHouse caps at 128 KiB. Nothing bounded a name, so a row declaring or mining a long one made every later read that bound it answer 500.
  6. The bulk in-batch replay. A key repeated within one memory.bulk_set was handled by two entry streams merged by a sort and four later patch-up passes over six parallel structures. A repeat also inherited its level and expiry at build time from a batch row that might not land.

They ship as one change because they were found together and are checked by one replicated-table run and one same-key search suite; the search fixes share the row key (hit_row_key) and the erasure and clear fixes share the bound-slice helpers (ch_params.chunks). Reverting one of them means reverting this PR.

What changed

  • Erasure (server/erasure/store/, server/memory/store/lifecycle.py):
    • Each user-scope step reads its predicate's subquery first, using the constant the residue census counts with. It then mutates by bound arrays, one 64 KiB slice at a time (ch_params.chunks, which sizes tuples as the driver renders them). The reads are in scope_reads.py.
    • The census still reads the subquery predicates, so a live row still fails the saga.
    • now() in a mutation is bound from Python, or read from the ClickHouse clock first for the blob sweep cutoff.
    • The mutation tag hashes the bound values, so each slice waits on its own mutation and a re-run finds its own pending ones.
    • Blob and learnings deletes re-read what must survive right before each slice.
    • Graph triples, edges and communities, and a purged document's source_uri, are bound as cityHash64 of their key columns, computed by ClickHouse on the read and in the mutation. So a stored name over 128 KiB, which older builds could write, never travels as a parameter. A 64-bit collision inside one org could delete an unrelated graph row, or supersede another writer's unrelated document version during a purge.
    • memory.clear with locked rows reads only the hashes of the locked identities and runs one embeddings mutation that excludes them. Past 2,500 locked identities the scope is split into hash buckets, one mutation each, so a mutation's command (kept in Keeper on a replicated table) stays small.
  • Other mutations that called now(): the blacklist hit counter (server/memory/app/blacklist_guard.py), mark_projection_failures_resolved and mark_message_saved bind the time from Python, so they also run on replicated tables.
  • Search:
    • hit_row_key (server/memory/domain/search_types.py) names a hit's row as (namespace, agent, user_id, session_id, memory_key), and every stage above keys on it. A hit whose leg read no identity has only its session.
    • Conversation-chunk hits carry the row's identity and session_id. A record hit carries its session_id but names no memory row, and gives way to a stronger fact of its key from any writer, as before. A memory.set chunk is written under memory.set:<key>, and its hit carries its own content_sha256. When a private-scope pool holds such a chunk, _set_chunk_rows reads the writer's served rows of the key with the newest vectors, with their versions and tags, from loom.memory_embeddings (memory_search_set_chunk_rows of them, default 64), then those rows' values from loom.memory, a form field at a time; rows holding the same value text and type are chunked once. The chunk belongs to the first of those rows whose current value cuts it, by the write path's own rule (set_chunk_identities); a status change re-writes a vector, so it counts as newer. The chunk folds onto that row when the row is pooled, and otherwise becomes that row's hit, with its version and tags. A chunk that no served row's value cuts is dropped: a later write replaced it, or the row is lapsed, superseded or outside the hard tags. A pending or older-model vector still counts as served. A row filed duplicate writes no chunks, and a re-set too short to chunk leaves the earlier chunks in storage; the read drops a chunk no served row's value cuts. When the read fails the chunks are dropped rather than shown on another value's row. Under shared scope, where the writer's private row is never served, a chunk folds onto a pooled fact of its key, as on main, or becomes the hit of the key's promoted row (_shared, -, -), so a later leg that reads that row (key-match, digest descent) finds it pooled and does not serve it twice. Every fact leg reads its row's identity.
    • A conversation chunk whose opening matches a pooled fact is dropped only beside a fact of its own writer. Under shared scope any fact with that opening still drops it, as on main: the shared fact is the promoted row, whose writer no chunk carries.
    • The unmatched and recency legs leave out the pooled rows (exclude_pooled, bound to one form field; a row past it comes back and is collapsed), not their keys; a record leaves out nothing. Once every leg has added its hits, legs that pooled one row twice (a chunk's passage and the value's head) leave one hit of it (collapse_rows, counted in retrieval_work.rows_collapsed), with the tags a leg read of that row. A hit made from a set chunk carries its row's tags, which _set_chunk_rows reads with the row, so the hard tag belt judges it by its own row. Under shared scope the promoted row's tags are not read, so a lone such hit fails a hard tag filter, as on main.
    • hit_sort_key, the one order every ranked list uses, breaks a tie after the key by the row's namespace, writer and session, so which row of a key the window keeps depends on the hits, not on read order.
    • Key-match returns at most as many rows of one key as the final block keeps (rows_per_key: memory_search_per_key_cap, or every row up to the statement's limit when the cap is 0 or the query is aggregational or temporal_diff), so a key written in many sessions leaves room for other keys. Rows that tie are taken in row order, so which rows come back does not depend on read order: by agent, user, session and key in key-match and the anchor pool, and after their own order by key, agent, user and session in the lexical fallback, the recency backfill and the unmatched leg; by agent, user and key in digest descent, whose session is fixed; after the newest version by agent, user and session in the set-chunk read, and by agent, user, session and key in the entity follow. The arm's gate counts the pool's rows by the same rule (on main it always applied the cap), so for an aggregational or temporal_diff query every row of a key counts and the gate reports thin_pool less often.
    • status_by_rows and superseded_successors read each pooled row by its full identity.
    • context.pack labels a fact hit that names its row with that row's writer (by=), where two writers of one key in one session used to read unknown.
    • Callers that read one item per key take the best hit of each (one_per_key) and ask the search for top_k times the per-key cap (per_key_fetch), so they still fill top_k: decision.precedents, procedure.match, memory.demonstrate (one vote per example), loom_search's repository-decision pass, loom decisions extract's restatement check (each key's most similar row) and code.ask's memory lines. The decisions section of context.pack lists a decision once but shares the pack's one search, so it does not over-fetch. memory.apply over-fetches the same way, with no session filter so a long value's set chunks are found, reads one of the caller's rows past limit to report truncated (also set when the window comes back as full as the search served it: the search does not filter by writer, so more of the caller's rows may rank below it), compares min_score with each hit's similarity (it read a score field search hits do not carry, so any min_score above 0 matched nothing), and judges a hit's owner by the row it names (hit_row_key), marking its key seen only once it meets the caller's own row; a record names no row and resolves by key. memory.ask merges a compound part's, an entity follow's and a decomposed part's hits through PooledRows: a hit that names its row joins when that row is not pooled, and a record, which names none, only when no hit of its key is. The entity follow's key read (bridge_rows_by_key) reads each row's identity and tags, so it names its row and the hard tag belt judges that row, and keeps at most memory_search_per_key_cap rows of one key (up to the follow's top_k when the cap is 0), so one attribute written in many sessions leaves room for the bridge's others.
    • A hit that names its row has its unit body read under that row's writer and session; when that read finds nothing and the excerpt is a full clip, the hit is marked body_truncated with its memory.get call. A hit that names no row, and a shared (promoted) row, keep the caller-identity read; a record's body is read under the caller's session, as its own session is not its parent fact's.
  • Duplicate gate: same_content_words returns False when each side states a value the other lacks (values_differ, built on the value tokens value_updates already used, now in server/memory/domain/conflicts.py). Such a pair goes on to the conflict check. A thousands separator is not part of a value (1,000 is 1000), for this gate and for the value-update linker that shares the tokens; a currency sign is, so $40 and 40 dollars still read as two values and the pair costs one conflict check.
  • Credentials: a key whose last one or two words are an assignment word (password, db_password, dbPassword, client_secret, api.key; a bare pwd key, an environment's working directory, is not one) states its string value as password: <value> for the detector. To qualify, the value must be one token of 8 or more characters holding a letter and a digit, and not be a reference (env:NAME, vault:PATH, secret:NAME, ref:NAME, an all-caps $NAME, ${NAME}, a value that opens with /, a segment, then /, or one opening ~/, ./ or ../; a relative path without that prefix, such as src/app1, still reads as a secret; a lowercase $value, and a token with a single leading / as base64 may open, still read as a secret). Quotes, commas and semicolons in the value do not cut it short. So placeholders such as YOUR_API_KEY and <redacted> stay unlabelled, and a password made only of letters is missed, as is a base64 secret that opens with /, a segment, then / (it reads as a path; roughly half of those that open with /). A URL is never a reference, since a webhook or a presigned URL is the secret itself, so a URL that only names where a secret lives reads high, as does an ARN that names one (its secret: part reads as an assignment). reads_high reads the quoted pair in raw JSON text, escapes included, and the sweep's prefilter selects it.
  • Entities: canonical_entity drops text over 256 characters (MAX_ENTITY_CHARS, the bound a triple's subject and object already had), on write, for a file, concept or topic facet, and in an entity_filter.
  • Bulk replay:
    • One _Step per entry that reaches the replay, in entry order, and per-key state in _Held. _settle_step settles each step over what its key holds and gives its row the labels and pin it lands with. Results are written after apply_bulk_verdicts (write_step_results), except a repeat that lands an earlier row, whose result _settle_repeat writes.
    • The level and expiry come from what the key holds at that step (_labels). A row the replay makes high drops its embedding row and its verdict.

Scope and risk

  • More reads when a set chunk is pooled. _set_chunk_rows reads the writer's rows of the key from loom.memory_embeddings (bound by the pooled chunks' (agent, user_id, key), pruned by (org, namespace, agent, user_id)), then those rows' values from loom.memory by its full sort-key prefix, a form field at a time. It runs in each vector_search call (each namespace, sub-query and set-expansion pool) whose private-scope pool holds a memory.set chunk.
  • Search can now return more rows. It may serve several rows of one key, one per writer and session, where it served one. candidates_total counts rows, not keys.
  • More rows labelled high. Stored JSON values holding a credential are labelled high by the sensitivity sweep on its next passes. Their vectors are removed, so they leave semantic search and stay readable by key.
  • Fewer rows filed duplicate. A value update now gets the conflict verdict for the resolver, or links as a value update.
  • Bulk replay:
    • A repeat after a write of its key that did not land keeps the stored labels.
    • A relabel that would change a read_only row's expiry is refused as locked, as memory.set refuses it.
    • A repeat of a key's current bytes that sets ttl_seconds writes a new version, so the expiry is set, as memory.set sets it; it was dropped as unchanged, so the expiry was never set (test_a_ttl_only_repeat_of_the_stored_value_sets_its_expiry, test_a_ttl_only_repeat_of_a_batch_value_sets_its_expiry).
    • One narrow case stores no vector: a repeat the build guessed high that the replay decides is not. This happens only when a pin landed earlier in the batch refuses an earlier high row of the same key. The key's older vector retires with it, so the old text never answers for the new value.
  • Erasure:
    • A very large user costs one mutation per 64 KiB slice per table. memory.clear stays one mutation up to 2,500 locked identities; past that it runs one per bucket and waits for each (mutations_sync = 2), so 25,000 locked identities wait on 10.
    • A supporter or a shared blob reference that lands between a slice's re-read and its delete can still lose its row. Graph triples, edges and communities read their ownership once, before their slices: another user's link to one of them that lands in between loses that graph row (the subquery used to be evaluated when the mutation ran).
    • memory.clear keeps the vectors of the locked identities it reads before the embeddings mutation: a row locked after that read, while the clear runs, keeps its memory row but loses its vector. main checked the lock inside the mutation, a narrower window.
  • Search: a failed _set_chunk_rows read drops that pool's set-chunk passages (logged as a warning) rather than show one on another value's row. The match recomputes a row's chunks with the running build's chunker, so a later change to the chunk geometry leaves stored chunks unmatched until their keys are set again (and lowering the chunk cap leaves the chunks past the new cap unmatched).
  • Left alone:
    • A bulk entry that repeats a key's current bytes and changes only its tags, type, confidence, valid_at, valid_to, files or declared source_class is counted unchanged and writes nothing, where memory.set writes a new version; as on main. A re-extraction differs in most of these (a new confidence, the session's valid_at, raw tags without the stored sensitivity:/attribute: labels), so matching memory.set would write a version on nearly every one, a change of its own.
    • A bulk entry that repeats the bytes of a stored row whose status is not active is counted unchanged, as on main and as memory.import leaves such a key: a replayed extraction batch must not write a superseded or rejected row back as active, which under newest_wins would retire the value that replaced it, nor promote a proposed row without an outcome (test_a_repeat_of_a_retired_stored_value_leaves_it). memory.set writes such a restatement back. An entry that names a new level, adds a pin or sets ttl_seconds is a new assertion and writes the row as active, as memory.set does (test_a_repeat_of_a_retired_stored_value_that_changes_a_label_writes_it_active); the retention window alone does not count (test_the_retention_window_alone_leaves_a_repeat_unchanged).
    • A repeat that lands a copy of an earlier row (its merge target was rewritten in between) keeps that row's version, so under newest_wins it reads as older than the rows written between the two entries, though serially it is the later write; as on main.
    • Under shared scope the chunk leg reads loom.memory_chunks with no agent filter, and the table has no scope column, so a shared-scope search can pool a private row's chunks (memory.set and conversation chunks alike). main does the same; closing it belongs in the chunk leg, in its own change.
    • A key's set chunks are stored under one session per key (memory.set:<key>, by chunk index and hash) and replaced per user: a later long write by the same user, in any session or under any agent, replaces that user's older long-value chunks, so only a user's latest long value of a key is findable by a passage past its excerpt. Writers whose values cut the same chunk share its memory_chunks row, stamped with the last of them, and the chunk names that writer's memory row; once that writer's value no longer cuts it, the others lose the passage, though their facts still serve (as on main, where the chunk folded by key). Recording the cutting row on the chunk needs a memory_chunks key change.
    • With purge=true the memory rows are deleted before the key-based steps read their keys, so graph triples, cached answers and belief sources of a purged user can remain while the census reports 0. main does the same; it needs its own change.
    • Bulk identity dedup is still blocked by rows that are built rather than landed.
    • The entity follow's key read (bridge_rows_by_key) carries the hard tags but not the other fact-leg predicates (expires_at, valid_to, as_of, the hard memory type and the types left out of an unfiltered search, a hard category), as on main; it needs _build_where's helpers over loom.memory, in its own change.
    • The hard tag belt's point read for a hit whose leg read no tags is by (namespace, memory_key), with no writer filter, as on main. Every search fact leg and the ask pool's entity-follow key read stamp their row's tags (that read also carries the hard tags in SQL), and a hit made from a set chunk carries its row's. The point read still serves memory.ask's identifier injection and chase, its bridge completion and content fallback, and its facet completion; reading it by row is its own change.
    • make migrate does not run on a self-managed Replicated database (a refreshable view needs a replicated target), so the replicated check below converted the tables by script.

Compatibility, rollout and rollback

  • Wire:
    • No op or field is added or removed.
    • entities and entity_filter items over 256 characters are dropped rather than refused. An entity_filter whose items are all that long is treated as absent, so the search uses the entities the query parser found.
    • Conversation-chunk and record hits fill session_id, which was empty.
    • Hits from the anchor, key-match, digest-descent, recency, lexical-fallback and unmatched legs carry their row's version, which was 0.
    • With include_tags, a private-scope hit made from a set chunk returns its row's tags, which were left off.
    • memory.demonstrate returns each example's stored excerpt (the full tier) at any k; a k of 8 or more used to return the 200-character excerpt tier.
  • Settings: LOOM_MEMORY_SEARCH_SET_CHUNK_ROWS (default 64, at least 1) bounds how many of a writer's served rows of a key, those with the newest vectors, a pooled set chunk is matched against.
  • Operator steps: none.
  • Rolling upgrade: a saga started by build N-1 and resumed by N does not match N-1's mutation tags. N resubmits each step, which is guarded by a count and idempotent, so this costs repeat work only. Build N-1 still cannot finish a user erasure on replicated tables.
  • Rollback: reverting leaves no new rows, tables or migrations. Rows the sweep labelled high stay high.

Tests

  • New, each failing before its fix:
    • tests/integration/same_key/test_search_ch.py: two sessions, one key, both served with their own text, for excerpt and unit bodies.
    • test_split_tail_keeps_the_rows_one_key_holds_in_other_sessions.
    • test_a_duplicate_is_hidden_though_another_writer_holds_its_key_active.
    • The PB pair in test_duplicate_step_requires_the_same_content_words.
    • test_a_credential_under_a_credential_key_reads_high, plus the credential rows in the ClickHouse prefilter test (clickhouse-local).
    • test_text_longer_than_a_name_is_no_entity and test_a_name_too_long_to_bind_is_dropped_on_write_and_search.
    • Two bulk label-inheritance tests in test_bulk_rows_carry_labels.py.
    • test_side_legs_exclude_pooled_rows.py (the unmatched and recency legs).
    • The row cases in test_fold_set_chunks.py (a set chunk under its memory.set:<key> session folds onto the row it was cut from, and leaves an older session's row alone).
    • test_a_shared_row_is_read_under_the_callers_identity and test_an_own_user_read_never_serves_another_users_body.
    • test_a_record_gives_way_to_a_stronger_fact_of_its_key_whoever_wrote_it, test_under_private_scope_a_chunk_is_dropped_only_for_a_fact_of_its_own_writer and test_under_shared_scope_a_chunk_that_opens_like_a_fact_drops.
    • test_a_duplicate_leaves_the_keys_chunks_to_the_served_value.
    • test_two_rows_of_one_key_with_equal_scores_sort_by_their_writer and test_one_row_identity_in_two_namespaces_sorts_by_its_namespace.
    • test_a_failed_row_read_names_no_row_and_its_chunks_drop and test_the_set_chunk_row_bound_is_at_least_one.
    • test_set_chunk_rows_sql.py runs _set_chunk_rows on clickhouse-local: a hard category filter decides whether the row is served; the row whose value cuts the chunk; none when no row's value cuts it any more (a short re-set); the newest of two rows holding one value; the bound to the writer's newest memory_search_set_chunk_rows rows; none when the fact leg does not serve the row (lapsed, outside the hard tags); a row embedded under another model still names its chunks.
    • test_collapse_rows.py (one hit per row at assembly, before the duplicates are read).
    • The tie tests on clickhouse-local, each failing without its tiebreak: test_key_match_sql.py (one key's sessions, and two keys at the limit), test_anchor_and_descent_sql.py, test_side_leg_ties_sql.py (the lexical fallback, the unmatched leg and the recency backfill), and the one-version cases in test_set_chunk_rows_sql.py and test_bridge_rows_sql.py.
    • test_a_full_search_window_may_hold_more_of_the_callers_rows and test_min_score_is_a_hits_least_similarity (test_memory_apply.py).
    • test_search_scoring_one_per_key.py, test_a_procedure_served_in_two_sessions_is_one_match, test_a_decision_served_in_two_sessions_is_one_precedent, test_two_rows_of_one_decision_key_count_as_one_decision, test_a_confirmed_restatement_below_keys_of_many_rows_still_blocks, test_a_key_served_in_many_sessions_is_one_memory_line, test_a_part_adds_another_sessions_row_of_a_pooled_key, and the two-row cases in test_demonstrate.py, test_context_pack_decisions.py and test_memory_apply.py.
    • test_duplicate_status_sql.py runs status_by_rows on clickhouse-local against the real loom.memory.
  • test_new_mutations_bind_parameters_only.py runs whole user, namespace and namespace-list sagas, and memory.clear with and without locks, through a fake client. It fails on any mutation holding SELECT or a non-deterministic function on a non-KeeperMap table.
  • tests/integration/test_erasure_replicated_ch.py (CI's ClickHouse runs an embedded Keeper) builds a throwaway Replicated database of ReplicatedMergeTree copies of 13 tables. It runs the real chunk, source-link, entity-graph, community, graph-link and document-purge steps and a locked memory.clear there. It also asserts that the old subquery and now() forms are refused with code 36.
  • test_erasure.py erases a user whose graph holds a 160 KB entity name (written past the write cap); before the hash binding it failed with Field value too long.
  • test_a_clear_names_a_bounded_number_of_locked_identities_per_mutation: 1 lock runs 1 embeddings mutation, 25,000 locks run 10 bucket mutations.
  • test_a_clear_that_tombstones_nothing_announces_nothing, test_an_entity_filter_of_only_long_names_falls_back_to_the_parsed_entities and test_a_user_with_chunks_and_no_memory_keys_binds_an_empty_slice (replicated tables).
  • On a ClickHouse with embedded Keeper and every schema.sql table converted to a Replicated engine:
    • The bound forms are accepted, and the old subquery and now() forms are refused.
    • A two-user saga: the base commit ends failed (code 36, 16 residue); this branch ends completed, residue 0, all 26 mutations done, and the second user's rows remain.
  • The test changes are fixture updates to the new internals. No assertion was loosened:
    • one 32 KB entity case now uses a name at the limit;
    • _hit fixtures carry session_id;
    • bulk helpers use the step API;
    • the duplicate-hiding tests' hits name their row, as the fact legs' hits do;
    • about 15 erasure tests are pinned to the bound predicates.
  • tests/analyzer/shapes.txt is regenerated.
  • Run: make format-check lint typecheck test-unit; the integration files for bulk, same-key search, entity filter, erasure, export, learnings, blobs and memory.clear against a local server.

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. Each defect was reproduced by a test that failed before its fix, and the erasure change was checked against replicated tables.

  • 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, except three unit failures this branch inherits from main (its decision_extract code): test_no_call_site_caps_its_output_with_a_literal, test_tests_patch_only_real_settings and test_no_new_tunable_constant (_MIN_WINDOW_CHARS, _RESTATEMENT_TOP_K, MAX_KNOWN_DECISIONS). The restatement fix here wraps _RESTATEMENT_TOP_K in per_key_fetch and passes it to one_per_key, so a change that turns it into a setting touches those two lines; the integration suite passes if server behaviour changed.
  • Generated files are regenerated in this PR, not by hand.
  • A new migration is additive and numbered after the latest on main; no merged migration is edited. (none)
  • A behaviour change to any file a plugin ships bumps both plugin manifests' version. (none)
  • The frontend builds and its tests pass, if frontend/ changed. (unchanged)
  • 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.
  • Commits are signed off (git commit -s).

🤖 Generated with Claude Code

@zlareb1
zlareb1 force-pushed the fix/same-key-search-and-replicated-erasure branch 9 times, most recently from e512b47 to afeb5de Compare November 2, 2026 05:52
zlareb1 and others added 21 commits November 2, 2026 08:27
…ored name

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: zlareb1 <[email protected]>
…with labels taken from what the key holds

The in-batch replay is one list of steps in entry order: a step per entry that
builds a row, or per exact repeat of its key's latest built row. One decision
function settles each step over what its key holds at that point (stored row or
the last landed batch row), the rows that land or that a verdict keeps out go
through apply_bulk_verdicts once, and every other result is written once after
it. Rows are dropped by filtering the steps; the parallel row_results,
restatements, inherited_level_rows, batch_rows, batch_entries and rewritten_ids
structures and the drop/renumber, landing and copy passes are gone.

A repeat's sensitivity level and expiry are now settled at replay against the
key's landed state, not inherited at build time from a batch row that may not
land. A stored 'high' row repeated after a merged value of its key stays
unchanged (or, with a pin, lands still 'high' with its expiry and no vector),
and a repeat after a merged or refused ttl/level row takes neither. A row the
replay makes 'high' drops its embedding row and its conflict verdict.

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

ReplicatedMergeTree and SharedMergeTree refuse an ALTER UPDATE/DELETE or a
lightweight DELETE whose statement holds a subquery or a non-deterministic
function (code 36). The user-scope erasure steps matched rows through
subqueries (the user's memory keys, record ids, shared keys, the graph keys
and entities only the user's memories link, the user's documents and blobs,
supported learnings), and memory.clear compared locks with now().

Each step now reads its predicate's subquery first, the same one the residue
census counts with, and mutates by what it found, bound as an array a slice
at a time (ch_params.chunks, which measures a tuple as the driver renders
it). The blob delete and the pending-learnings delete re-read their slice
right before each delete. memory.clear binds its timestamp and names the
embedding identities it clears when a lock keeps some rows. The blacklist
hit count, the projection-failure resolve, the saved-message mark and the
blob sweep's age cutoff bind their times too.

An erasure mutation's tag now hashes its bound values, but not the stamp
it writes, so the slices of one step wait for their own mutations and a
step re-run after a crash finds its own pending ones.

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

Placeholders such as YOUR_API_KEY and <redacted> stay unlabelled, a value
starting with $ or holding a colon is read, and the raw pair and the sweep's
prefilter read JSON escapes inside the value.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: zlareb1 <[email protected]>
…ps room for other keys

Two users who write one key with no session are two rows: the duplicate and
superseded lookups, the unit bodies, the chunk fold and the key-match and
digest arms now tell them apart. Chunk and record hits carry the row's
identity. Key-match returns at most the per-key cap of one key's rows, so a key
written in many sessions no longer fills the arm.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: zlareb1 <[email protected]>
…ide in one mutation

- memory.clear with locked rows reads the locked identities and runs one
  embeddings mutation with `NOT IN` over them, one bound array per 64 KiB
  slice, instead of one mutation per slice of every unlocked identity.
- The user-scope graph, community and document steps bind
  `cityHash64(namespace, ...)` of each key, computed by ClickHouse on both
  sides: a stored entity name or URI can be longer than the 128 KiB form
  field a bound value travels in.
- One slicer: `ch_params.chunks`; `repo_base.param_slices` delegates to it,
  `scope_reads.slices` is gone and `slices_or_none` is `slices_or_one_empty`.
- `blobs.delete` raises when the clock read returns no row.
- Integration tests: a user graph with a 160 KB entity name is erased with
  no residue; the user steps and a lock-bearing clear run on
  ReplicatedMergeTree copies of their tables, which refuse the subquery and
  `now()` forms.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: zlareb1 <[email protected]>
…p, and bodies, raw pairs and slicing read one way

- memory.clear names the hashes of locked identities, at most 10,000 per
  mutation; past that the scope is split into hash buckets.
- Key-match binds the window's own rows-per-key rule: 0 or an aggregational
  query keeps up to the statement's limit instead of no rows.
- A unit body is served only for the hit's own writer and session.
- A raw JSON pair's value is decoded before the credential check.
- A bulk row the replay lands without a vector retires the key's old one.
- One slicer (ch_params.chunks); the learnings step slices every bound list;
  the analyzer renders the hash-bound erasure mutations.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: zlareb1 <[email protected]>
…writer's row, and clear buckets fit a form field

- status_by_rows and superseded_successors bind the pool's row keys instead
  of returning every writer's row of each served key.
- A unit body is read under the row the hit names, so two writers of one key
  in one session each get their own.
- memory.clear names at most 2,500 locked hashes per mutation, about 54 KB.
- The clear is straight-line: memory, announce, then embeddings.

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: Lareb Zafar <[email protected]>
… filter falls back to the parsed entities

The architecture page states the 2,500-lock bucket bound and the
supporter window of the learnings delete. A replicated test binds the
empty key slice of a user with chunks and no memory keys.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: Lareb Zafar <[email protected]>
…r entry embedded

The retire check matched the batch's embedding rows by key, so an earlier
entry's vector of the same key kept the old text answering; it now matches
the winning row's version. The sweep's credential prefilter reads a \b
escape, as the detector does.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: Lareb Zafar <[email protected]>
…a secret

`_SECRET_REFERENCE` is matched at the start of the value, so `../secrets/db1`
missed the `./` arm and `$DB_PASS1` matched nothing: both read as a password and
labelled the row `high`. An all-caps `$NAME` and a `../` path now read as
references; a lowercase `$value` still reads as a secret. Also rewraps the
`detector_text` docstring.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: zlareb1 <[email protected]>
…s test hashes unevenly

`_unlocked_parts` splits by `hash % buckets`, so a bucket can name more than
`_LOCKED_PER_MUTATION` identities; the comment called it the most one mutation
names. The test's evenly stepped hashes hid that; it now spreads hashes unevenly
and checks the bound that matters, one 128 KiB form field per list.

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

The read names another writer's identity when the hit carries one, so a test
now pins that it still passes the caller's `request_scope()`: an `own_user`
token never reads another user's body through a hit. The comment on the read
says which reads pick one row per key.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: zlareb1 <[email protected]>
`_vectors_to_retire` matches an embedding row to the winner by version, as the
row builder writes it; the fixture's rows had none and the test raised KeyError.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: zlareb1 <[email protected]>
`_BulkWriteState` already defaults `now_utc` to the current UTC time, and
`loom.memory.duplicate_of` is a non-nullable String, so `ifNull(toString(...))`
returned the column unchanged.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: zlareb1 <[email protected]>
zlareb1 and others added 15 commits November 2, 2026 08:27
…s which row it means

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: zlareb1 <[email protected]>
…e prefilter's credential keys come from the detector's word tuples

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: zlareb1 <[email protected]>
…hich fields it does not

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: zlareb1 <[email protected]>
…ack, as memory.set does

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]>
…ches the replay and asserts the outcome

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: zlareb1 <[email protected]>
…mory.set does

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: zlareb1 <[email protected]>
…changed, so a replayed extraction cannot revive it

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: zlareb1 <[email protected]>
…; a label-changing repeat of a retired row is documented and tested

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: zlareb1 <[email protected]>
…abel; the retention test reaches the skip gate too

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: zlareb1 <[email protected]>
… a reference unless it carries a password

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: zlareb1 <[email protected]>
… under a credential key reads high

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: zlareb1 <[email protected]>
…led top_k; security.md reflowed

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: zlareb1 <[email protected]>
… caller's row; merged decisions are credited in the home search's window

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: zlareb1 <[email protected]>
…s not filter by writer

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: zlareb1 <[email protected]>
@zlareb1
zlareb1 force-pushed the fix/same-key-search-and-replicated-erasure branch from 75e6319 to 5417875 Compare November 2, 2026 08:29
zlareb1 and others added 11 commits November 2, 2026 08:36
… per_key_fetch rows

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

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: zlareb1 <[email protected]>
…public; the learnings re-read uses query_all_sliced

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: zlareb1 <[email protected]>
…ps the first hit of each key

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]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: zlareb1 <[email protected]>
…; a value drops any whitespace before its unit

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]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: zlareb1 <[email protected]>
…whitespace

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: zlareb1 <[email protected]>
@zlareb1
zlareb1 merged commit 47e35c2 into main Nov 2, 2026
20 of 22 checks passed
@zlareb1
zlareb1 deleted the fix/same-key-search-and-replicated-erasure branch November 2, 2026 10:29
@pufit pufit mentioned this pull request Nov 2, 2026
9 tasks done
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