Repository navigation
Under Postgres, loom reconcile runs again in a restored store the erasures and redactions the other records past the restore point - #460
Merged
Conversation
zlareb1
force-pushed
the
feat/pg-erasure-ledger
branch
from
November 10, 2026 04:25
6228a1e to
de46d23
Compare
9 tasks done
zlareb1
force-pushed
the
feat/pg-erasure-ledger
branch
2 times, most recently
from
November 10, 2026 06:34
a069ee6 to
7dccbd9
Compare
…sures and redactions the other records past the restore point Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: zlareb1 <[email protected]>
…urnal stores Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: zlareb1 <[email protected]>
… values to restore, and the Postgres flag Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: zlareb1 <[email protected]>
zlareb1
force-pushed
the
feat/pg-erasure-ledger
branch
from
November 10, 2026 06:53
f380bfa to
91a00ab
Compare
…orts the knowledge plane once Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: zlareb1 <[email protected]>
8 of 9 tasks
…s follow the ledger reads Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: zlareb1 <[email protected]>
…open helper is named for what it does Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: zlareb1 <[email protected]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Changelog category (leave one):
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):
Under the Postgres authority,
loom reconcile --restored clickhouse|postgres --point <time>repairs a deployment after one of its stores is restored from a backup: the erasures and redactions the other store records past the restore point run again, and after a ClickHouse restore every revision and knowledge document committed since is published again, so nothing erased or redacted comes back. Knowledge chunks live in ClickHouse alone: the command names each source to re-chunk withloom rechunk(past 20 in a namespace, the namespace).Why
Under the Postgres authority a deployment has two stores, and a restore of either brings back an older state. Before this change:
loom.erasure_requests) is in ClickHouse, so the erasures themselves were forgotten, including what they removed from tables keyed by user or namespace;A restore loses what was written after its point; that is what restoring means. It must not bring back what was forgotten after it.
Design (reviewed adversarially before coding; the rounds cut it to this):
loom.erasure_ledger(Postgres migration006_erasure_ledger.sql) gets each saga's row frombegin_erasure, before its first ClickHouse checkpoint, thencompleted_atat its end orabandoned_atwhen the recovery worker gives up on it. The erasure recovery pass copies in what only ClickHouse records (erasures of a build before this one, or one a process of the previous build ran during a rollout) and the terminal states this ledger missed, a page at a time from a cursor that walks ClickHouse's ledger and starts over at its end, and sweeps rows pastLOOM_ERASURE_LEDGER_DAYS(live, default and maximum 89, the days ClickHouse's ledger reads keep inside its 90-day TTL).memory_revisions.redacted_at, ClickHouse inmemory_versions.redacted_at.loom reconcile --restored clickhouse|postgres --point <the backup's time>. A dry run is the default.failedwith "replay after a restore pending: run loom reconcile again" while the steps run (a row the recovery worker andloom erasure-re-verify --resumeskip), then the saga'scompletedrow and anerasure.completedaudit row once all ran. After a Postgres restore theloom.erasure_ledgerrow is completed once the Postgres steps ran. A step that fails is reported by name, and the reconcile is run again whole.loom erasure-re-verifyowns it.lease_untilinfinity,fenced_untilnow). An erasure waits nothing for it, and no claim takes it.memory.redactagain. That scrubs the restored rows and the cached answers and precedents quoting them; Postgres keeps its first redaction.--restored both(erasures after both points are in neither store; reconcile names the window to issue again from the audit export); a point older than the ledger keeps; a worker that reported a pass within two workers-lease terms (LOOM_SUPERVISOR_LEASE_TTL_S, a minute by default;--allow-liveoverrides).docs/operations/backup-and-recovery.md, "Under the Postgres authority".Rejected alternatives:
seqorversion. ClickHouse rows carry noseq, and copy writers draw versions before their reads.Restore detection and a quarantine refused at the Postgres commit are the follow-up. Until then the runbook says to stop the deployment and always reconcile after a restore.
Scope and risk
Touches the erasure saga (one Postgres row written before its first checkpoint, one completion), the recovery pass (backfill and sweep, Postgres only, isolated from the sagas' recovery), and a new CLI command with the memory, knowledge and erasure functions it calls. Under the ClickHouse authority nothing changes.
A replay's ClickHouse rows and its audit row carry the original erasure's id and the actor
loom-reconcile, whose rows a later reconcile trusts whatever their time. A requeued erasure's rows, and those the recovery worker writes as it resumes it, name the recovery worker, which a later reconcile trusts only before its point. The replay answers' step drops the org's whole replay cache in both stores, as in any erasure.Interaction with the payload clearing in progress (#453): once delivered payloads are cleared, a non-head revision whose payload is gone cannot be republished (the window pass selects
row IS NOT NULL; heads keep their payload). A follow-up refuses a ClickHouse backup older than #453'spayload_clearing.cleared_through, once that exists.Compatibility, rollout and rollback
LOOM_ERASURE_LEDGER_DAYS(live, 1 to 89, default 89).schemas/pg_migrations/006_erasure_ledger.sql, additive (one table, one maintenance index).docs/operations/backup-and-recovery.md.loom reconcilefirst: the previous build's recovery worker does not skip the "replay after a restore pending" row and would resume it with a census.Tests
tests/unit/test_restore_reconcile.py:still_opennever return a pending replay (clickhouse-local), andloom erasure-re-verifyneither counts nor resumes one;tests/integration/test_restore_reconcile.py, in the Postgres authority job. One org's rows are copied aside, more is written (a new memory, an update and a redaction, a user's purge erasure), the copy is put back, and the reconcile runs:memory.searchreturns the same keys, order and scores as before the restore, for four queries; a memory the erased user wrote after the erasure has its row and search document back in ClickHouse (the reconcile deletes no later write);memory.getserves no secret; search serves neither.pg_ledger.forgetdeletes an open ledger row and keeps a completed one.Local unit runs: the new file, the settings reference, the CLI snapshot (regenerated: only
loom reconcileadded), public copy, doc links and the Postgres table classification pass; the erasure-related unit files pass (7203 tests);tests/unit/test_restore_reconcile.pyhas 40.CI:
tests/integration/test_restore_reconcile.pyruns as its own step, last in the Postgres authority job (-p no:randomly):loom reconcileacts on the whole database, so it must not run before other tests that read the delivery queues.tests/analyzer/shapes.txtis regenerated. Its 10 changed shapes come from main (erasure.status returns the erasure's receipt: every substrate its latest census counted, and the purge it applied #462'serasure_requestscolumns and the schema dump), which landed after the file was last written; this PR's own ClickHouse reads (ledger.completed_since,trusted_row,still_open,redaction.redacted_since, the ledger copy, the heads-behind comparisons, the live-worker read) have no analyzer case yet.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 replay's step sets were checked against the saga's step lists and its resume path; both drills were run against real stores.
I can explain every line of this diff and how it interacts with the rest of Loom.
Checklist
make format-check,make lint,make typecheckandmake test-unitpass; the integration suite passes if server behaviour changed. Locally: format, lint, the affected unit files and the new integration file; the full suites run in CI.docs/reference/configuration.md,loom.example.yaml,schemas/loom-settings.schema.json,llms.txt, the CLI snapshots.main; no merged migration is edited.frontend/changed: not changed.docs/describe the system as it now is, and this description names any operator steps and wire changes.git commit -s).🤖 Generated with Claude Code