Skip to content

erasure.status returns the erasure's receipt: every substrate its latest census counted, and the purge it applied - #462

Merged
zlareb1 merged 11 commits into
mainfrom
feat/erasure-receipt
Nov 10, 2026
Merged

zlareb1 merged 11 commits into
mainfrom
feat/erasure-receipt

Conversation

@zlareb1

@zlareb1 zlareb1 commented Nov 10, 2026 •

Copy link
Copy Markdown
Member

Related: #450

Changelog category (leave one):

  • New Feature

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

erasure.status and erasure.request return the erasure's receipt: census, every substrate the final residue census counted with its count (zeros included), and purge, whether the saga deleted or tombstoned. The retention and erasure page shows how to re-count the memory and conversation tables through the SQL surface.

Why

An erasure ends with a residue census over every substrate Loom reads, but the ledger kept only the non-zero counts. A completed saga stored residue = {}, so the list of what was checked was lost. A receipt the requester can keep, and partly check themselves, needs the whole census: each table and its zero, and when the census ran.

Design

Receipt shape. Two fields on ErasureStatusOutput and ErasureRequestOutput:

  • census: dict[str, int] | None
  • purge: bool

The subject and the time are already there (org, scope_type, scope_value, verified_at), so the receipt adds no copy of them.

  • Census keys: table names, pg:<table> for the Postgres authority, objects.document_originals, and provider_rebuild_copies. The last sums a provider rebuild's per-rebuild copy tables, so the keys stay stable from one rebuild to the next.
  • census is the latest ledger row's: null while a run is in progress, when its census could not run or left a store uncounted, or on a row an older build wrote.
  • A count means "rows the census counts as residue in this scope": live rows, or every row under purge or for a table with no tombstone. The receipt section of the retention and erasure page says so; the field description names the census only.

Storage. Migration 091 adds loom.erasure_requests.census (a JSON string).

  • The verify step writes every count with the other verify columns, and only for a complete census.
  • census is in VerifyColumns, so every terminal and failed checkpoint writes it.
  • The recovery worker's re-checkpoint reads it back (list_unabandoned_exhausted → _ledger_verify), and so does verify_columns_from_output.
  • A unit test holds that read to every VerifyColumns key.

Correctness fixes the receipt depends on.

  • Census always re-runs on resume. run_saga drops verify.residue from the completed set on every resume. Before, a crash between the census and the terminal row wrote a completed row with no verified_at, because the in-progress checkpoint carries no verify columns. The resume then skipped the census.
  • One purge rule. applied_purge(scope_type, scope_value, requested) in server/erasure/domain/scopes.py is the rule the saga runs by: a user's as requested, a namespace list's from its scope, a single namespace's never.
    • It replaces three copies: ledger_reads.purges, the saga's inline branches and hygiene._re_verify_scope.
    • parse_purge_flag and parse_external_flag move there with it.
    • The ledger's purge column now records the applied purge, so a single-namespace saga that was asked to purge says false.
    • The status computes purge with the same rule, so rows written before this change read right too.
  • Ledger TTL edge. The ledger's TTL drops a saga's rows part by part 90 days after requested_at, which every checkpoint repeats. Near the end, an older checkpoint can outlive the terminal row.
    • Every ledger.py read now carries LIVE_LEDGER (requested_at > now() - INTERVAL 89 DAY): status, list, stuck, failed, completed and exhausted.
    • The two erasure fences (unfinished_since, unfinished_reaching) do not, because a stale unfinished row keeps fencing, which fails closed.
    • A unit test holds both rules.
    • This also stops the recovery worker resuming a saga whose terminal row expired first.

Durable copy. The erasure.completed audit subject carries the census, counts only. Audit outlives the ledger row. The write is best effort and happens after the completed checkpoint, so the docs say the answer itself is the copy to keep.

Self-check. A new docs section, "Checking an erasure yourself", covers:

  • the SQL an operator with the org's * SQL grant runs against the SQL surface's views to re-count loom.memory, loom.memory_versions and loom.conversations;
  • binding the id and time as parameters, and running the statements from clickhouse-client;
  • how the views differ from the census;
  • what the receipt does not cover: backups, PITR, WAL, standbys, copies outside Loom, post-census worker writes, a namespace.restore from an older snapshot, and user-scope bucket objects;
  • where the erased id stays as proof.

Alternatives rejected.

  • A signed receipt: the requester cannot verify a Loom-held key, and the independent check is the re-count.
  • Storing every count in residue: that changes an existing field's meaning.
  • A receipts table: new state for data the ledger row already scopes.
  • Counting reversals on the receipt: under the Postgres authority memory.restore cannot reach an erased row, because the first saga step deletes its head.
    • The reversal write in restore.py is not gated by authority, so under Postgres it can only record a row written after the erasure. erasure.list's reversals_count shows those.
    • That needs its own change, which is not made here.

The design went through a principal-architect review to zero findings before coding.

Scope and risk

  • Touches: the erasure plane (domain, app, store, recovery worker), migration 091, the two output models, the generated SDKs and the operations reference, docs/features/memory/retention-and-erasure.md and docs/architecture/rolling-upgrades.md (rule 41).
  • run_saga reached the 200-line function gate with the receipt's lines, so the webhook's erased-namespaces list moved into _erased_namespaces unchanged.
  • loom erasure-re-verify --resume of an older namespace_list row whose scope is a bare array now takes the ledger's purge column, as the saga does, where it took false.
  • Behaviour change: the status and the stuck, failed and completed reads ignore ledger rows older than 89 days.
  • Behaviour change: a single-namespace saga's purge column reads false. Nothing reads that column for a namespace scope except the status.

Compatibility, rollout and rollback

  • Wire: two fields added to erasure.status and erasure.request outputs, census (nullable) and purge. Nothing is removed.
  • Rolling upgrades (rule 41): N-1 neither writes nor reads census. A row N-1 checkpoints reads '', which N answers as census: null.
  • Operator steps: none. The migration is additive.
  • Rollback: the column stays, unread.

Tests

  • Unit, tests/unit/test_erasure_receipt.py:
    • the applied-purge rule for each scope;
    • the census fold, over the keys copy_residue emits;
    • a complete census kept whole, and an incomplete one kept as residue without a receipt;
    • the recovery worker carrying the census;
    • the exhausted read selecting every verify column;
    • every ledger read but the fences applying LIVE_LEDGER, and the status statement sent carrying it;
    • erasure.status answering no receipt for an empty census, and purge: false for a single-namespace row that asked to purge.
  • Unit, tests/unit/test_erasure_resume_reopens_steps.py: a resume always re-runs the census.
  • Unit: the census-tail tests updated for the new column. The erasure and knowledge-restore unit files pass (437).
  • Integration, tests/integration/test_erasure.py against a local ClickHouse 26.10 and a server from this branch:
    • a user erasure returns a full census, every count 0 and purge: false, and the status agrees;
    • the erasure.completed audit row carries the same census;
    • a single-namespace erasure requested with purge: true reports purge: false, with a zero census;
    • a ledger row 88 days old is served, one 89 days and 1 hour old is not.
  • The "Checking an erasure yourself" statements, run as written from clickhouse-client as a granted SQL user: 0 on all four for an erased user, 1 on memories, history and request ledger for a kept one. system.query_log showed ClickHouse writes bound parameter values into the logged text (HTTP and native), so the page says so instead of claiming binding keeps them out.
  • Full unit suite on the rebased head: 32476 passed, 25 skipped.
  • make format lint typecheck pass. schemas/schema.sql was re-dumped after migrate.

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 design was reviewed to zero findings by an architect subagent before coding, and the integration tests were run against a live ClickHouse.

  • 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.
  • 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 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

…est census counted, and the purge it applied

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: zlareb1 <[email protected]>
@zlareb1
zlareb1 force-pushed the feat/erasure-receipt branch from c9ffbd0 to f55beee Compare November 10, 2026 03:50
zlareb1 and others added 4 commits November 10, 2026 03:58
The integration module lists the receipt's behaviours; a unit test pins the hygiene
re-verify of a bare-array namespace list to the purge its saga ran.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: zlareb1 <[email protected]>
The census fields and the receipt section name every case it is None; the self-check
reads the erased id at a prompt, out of the shell history; tests cover a failed census's
receipt and tie the read window to the ledger's TTL.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: zlareb1 <[email protected]>
A complete census always carries provider_rebuild_copies, 0 when no copy exists, so
every receipt has the same keys; the receipt section says when a failed run has one.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: zlareb1 <[email protected]>
The self-check says each statement reads the grant's whole scope and which caps can stop
it, and how to check a namespace_list erasure.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: zlareb1 <[email protected]>
@zlareb1 zlareb1 changed the title erasure.status returns the erasure's receipt: every substrate its last complete census counted, and the purge it applied erasure.status returns the erasure's receipt: every substrate its latest census counted, and the purge it applied Nov 10, 2026
zlareb1 and others added 6 commits November 10, 2026 04:38
The migration and the test module say the column holds the latest row's census; the
self-check names its fourth statement as the request ledger check; a test pins a step
checkpoint writing no census.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: zlareb1 <[email protected]>
The completed path works out the census once, and one helper writes the ledger's
census text.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: zlareb1 <[email protected]>
Each path works out the census once and passes it to the ledger columns, the audit row
and the answer; the erased-namespaces list moves out of run_saga.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: zlareb1 <[email protected]>
The self-check says the request ledger view confirms a scrub only for rows inside its
window.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: zlareb1 <[email protected]>
The self-check names the rejected versions the history view leaves out.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: zlareb1 <[email protected]>
_verify_columns works out the census from its holder again, so no caller can pass one
that disagrees with the counts; the receipt section says census is null, and purge is
always served.

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