Repository navigation
Under Postgres, a revision every usable ClickHouse backup holds can lose its payload, past a horizon no shorter than the backup interval plus 60 minutes - #453
Closed
zlareb1 wants to merge 9 commits into
Conversation
…edaction live in typed columns that every journal reader matches on Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: zlareb1 <[email protected]>
…nal written before it, and readers take the field from row then Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: zlareb1 <[email protected]>
…index serves, and a profile revision keeps its payload; the unread tombstone column is gone 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]>
…r clears; the journal keeps no column nothing reads 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 cleared payload Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: zlareb1 <[email protected]>
…gap test's check reads like its neighbour's Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: zlareb1 <[email protected]>
…ad when it sweeps its settled delivery, past LOOM_PG_REVISION_PAYLOAD_MINUTES Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: zlareb1 <[email protected]>
zlareb1
force-pushed
the
feat/pg-revision-metadata
branch
from
November 9, 2026 19:06
ba5f06e to
982d7e0
Compare
8 of 9 tasks
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.
Migration
004_revision_delivered_at.sqlbuilds its index inside the migration's transaction. That is safe only whileloom.memory_revisionsis small. No released build writes the Postgres journal, and every known deployment runs the ClickHouse authority, so it is small wherever 004 runs. This PR therefore has to ship in the same release as 003. If a release carrying 003 is cut first, the index moves toCREATE INDEX CONCURRENTLYbefore this PR merges.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
LOOM_STORAGE_AUTHORITY=postgreswithLOOM_PG_PAYLOAD_CLEAR_ENABLED, a memory revision keeps only its metadata in Postgres once every usable ClickHouse backup holds it. That happens past a horizon that is never shorter thanLOOM_CLICKHOUSE_BACKUP_INTERVAL_MINUTESplus 60. Before restoring a ClickHouse backup, turn the switch off; the steps are in backup and recovery.Why
loom.memory_revisions.rowkeeps every version's full row, and ClickHouse'smemory_versionsholds the same. Since the previous change, the journal keeps a revision's metadata in typed columns, and every reader tolerates a cleared payload. The payload is still needed to write a version back into ClickHouse after a backup restore. So it may go only once every backup a restore may use holds the version.Design
Delivery time. A completion that empties a delivery more than 15 minutes after its revision's commit sets
delivered_aton the revision (pg_memory._STAMP_LATE). The stamp is a data-modifying CTE fed from the RETURNING of the existing DELETE and settle UPDATE. A completion sends no more statements than before, and an on-time write never touches the journal. So a revision's delivery time is at mostcoalesce(delivered_at, committed_at)plus 15 minutes.The pass. It is a worker of its own,
pg_payload_clear, off by default (LOOM_PG_PAYLOAD_CLEAR_ENABLED, not LIVE, so a restore ofloom.runtime_overridescannot turn it on). Each pass works in three steps:LOOM_PG_DELIVERY_BATCH_ROWScandidates through the new partial indexmemory_revisions_payload(its predicate ispg_memory.CLEARABLE, word for word). A candidate is past the horizon, owes no delivery, and is not a profile revision.loom.memory_versionswith sequential consistency: same key and version, samememory_id, same content hash. A redaction keeps the hash.FOR NO KEY UPDATE SKIP LOCKED, so a row held by a redaction or an erasure is skipped.A version ClickHouse lacks is kept and counted (
missing_in_clickhouse). A dropped ClickHouse connection is retried within half the pass deadline. The pass resumes from the last pass's position in the process and starts over at the end. It clears nothing until the process has adopted the deployment's overrides (settings_overrides.adopted()).Horizon. The horizon is
LOOM_PG_PAYLOAD_RESTORE_HORIZON_MINUTES(LIVE; 0, the default, means twice the backup interval plus 60). It is never underLOOM_CLICKHOUSE_BACKUP_INTERVAL_MINUTES(LIVE, default 1440) plus 60, nor under the insert bound plus 60. The 60 minutes cover a late backup, replica lag and clock skew. The arithmetic and the restore runbook are indocs/operations/backup-and-recovery.md.No new state. There is no new table and no stored high-water mark:
row IS NULLalready means cleared by this pass, because a redaction scrubs the payload rather than nulling it.Scope and risk
delivered_atholds no content.Compatibility, rollout and rollback
LOOM_PG_PAYLOAD_CLEAR_ENABLED,LOOM_PG_PAYLOAD_CLEAR_INTERVAL_SECONDS,LOOM_CLICKHOUSE_BACKUP_INTERVAL_MINUTESandLOOM_PG_PAYLOAD_RESTORE_HORIZON_MINUTES. Wire: none. Operator steps: none until the switch is turned on.Tests
tests/unit/test_pg_payload_clear.py:CLEARABLE;test_pg_authority.py::test_a_revision_delivered_late_is_stamped_and_one_delivered_at_once_is_not(integration): a delivery taken over from a writer that stopped an hour ago is stamped; on-time ones are not.test_pg_authority.py::test_a_revision_past_the_horizon_that_clickhouse_holds_loses_its_payload(integration): past the horizon, both versions of a key are cleared, the redacted one included. Their metadata stays, andmemory.historyandmemory.getanswer as before. A revision ClickHouse lacks keeps its payload.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. Checked: the delivery-time bound on every completion path, the lock order against redaction and erasure, and the restore runbook against the compose deployment.
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.main; no merged migration is edited.frontend/changed.docs/describe the system as it now is, and this description names any operator steps and wire changes.git commit -s), as CONTRIBUTING.md asks.🤖 Generated with Claude Code