Repository navigation
Under Postgres, each revision's key, status and redaction live in typed columns that every journal reader but the profile reach matches on - #445
Merged
Conversation
9 tasks done
This was referenced Nov 9, 2026
Closed
…ed columns that every journal reader but the profile reach matches on 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
This was referenced Nov 9, 2026
Merged
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.
Follows #433 (merged). The second half, clearing delivered revisions' payloads, follows in the next release.
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=postgres, the revision journal keeps each revision's key, status and redaction in typed columns, and every journal reader but the profile reach matches on them and reads a revision's content only from its payload, falling back to ClickHouse's history when the payload is gone. The next release clears delivered revisions' payloads.Why
loom.memory_revisions.rowkeeps every version's full row for good, while ClickHouse'smemory_versionsholds the same. Long term only the metadata is needed: version, content hash, status, redaction. This PR does the reader half: readers stop depending onrowfor anything but content. Clearing payloads after delivery is the follow-up, for the next release. That split is what the rolling-upgrade rules require (rule 4, rolling upgrades): build N-1 readsrow->>'agent'and friends, and would mismatch or fail on a NULLrow. So only a build after one that tolerates it may write it.Design
003_revision_metadata.sqladdsagent,session_id,memory_key,status,redacted_atandredaction_reasontoloom.memory_revisions, and letsrowbe NULL.memory_revisions_metadata,BEFORE INSERT OR UPDATE OF row, sets them fromrowwhenever a writer sets it, whatever build it is. Each falls back to theloom.memorycolumn's default for a fieldrowleaves out, and whenrowis cleared the trigger keeps them, filling any still NULL (a revision written before the file) from the payload being cleared. N-1's inserts, which name none of these columns, get them filled.rowdrops itsNOT NULL: catalog changes only, so the file holds the table's lock for milliseconds, whatever the journal's size. A revision written before the file keeps the columns NULL, and every reader takes each field from its column or, when that is NULL, fromrow(pg_memory._meta,coalesce(col, row->>'col', default)). No backfill, noNOT NULL, no index build in the migration's transaction, as migrations requires for a large table._PROFILE_REVISIONS, the journal's profile arm of_REDACTED) keeps matching onrow, which the partial indexmemory_revisions_profileserves, so a profile revision keeps its payload for good (the follow-up's clearing leaves it). Every other journal predicate keeps itsmemory_idequality, served bymemory_revisions_by_id.history_target,status_before, the search validation's journal lookup, the redaction's history read,_refuse_moved_sources, the key arm of the redaction's statements (_REDACTED,_REDACTED_EVER), all match on the metadata (_meta); the idempotency replay'smemory_keyand the erasure's consolidated-dependents query read the column, falling back torow, inline (their packages cannot import the memory store).pg_memory.revisions_at(rollback's reinstated versions) takes ClickHouse's history rows. For a revision without a payload it serves ClickHouse's row of the same key, scrubbed (_scrubbed) when the columns say it is redacted, so a redaction whose ClickHouse scrub has not run is never served. A revision the journal no longer holds (erased) is not served._gap_cleared,revisions_since) does not clear a gap with a cleared payload; the write reaches its verdict on peers read anew.row, so the fallbacks have nothing to act on until the follow-up ships.Scope and risk
ALTER TABLEtakesACCESS EXCLUSIVEonloom.memory_revisionsfor catalog changes only (the boot'slock_timeoutbounds the wait for it), and the file rewrites no row.(org, namespace)oruser_id, so the census and the saga are unchanged.loom.memory_current), the deliveries, the ClickHouse authority.Compatibility, rollout and rollback
rowstays set by every writer.Tests
test_pg_authority.py::test_a_revisions_metadata_is_kept_from_its_row_and_outlives_it(integration; fails onmain, where the columns do not exist): a commit fills the columns; a revision inserted naming none of them (as build N-1 writes one) gets them from itsrow; a scrub sets the redaction columns; a clearedrowleaves every column as it was, and a revision without the columns (written before the file) takes them from the payload it loses.test_pg_authority.py::test_a_redact_reaches_a_revision_by_its_metadata(integration; fails on the previous head, whose columns wereNOT NULL): a redaction finds and scrubs a revision written before the columns existed through its payload, and marks the columns of a revision whose payload is cleared.tests/unit/test_pg_authority.py:test_a_gap_with_a_cleared_payload_is_not_read(the admission reaches its verdict anew instead of clearing a gap from a NULL payload) andtest_a_version_whose_payload_was_cleared_serves_clickhouses_row_as_redacted(revisions_atserves ClickHouse's row of the key, scrubbed when the columns say redacted, and nothing for an erased revision);test_redact_scrubs_every_value_column.py::test_a_version_served_from_clickhouse_for_a_cleared_payload_is_scrubbed_alike(that scrub clears every column the authority's scrub clears); the readers' tests follow the typed columns (test_namespace_rollback_unembedded.py);test_a_commits_gap_with_a_cleared_payload_is_not_cleared_from_the_journal(the commit-time gap check does not clear a gap with a cleared payload).HistoryTarget.tombstoned_at, which nothing read, is dropped, with the column fromfind_history_target's ClickHouse statement (the profile tests' target no longer sets it).pytest tests/analyzer(the statement-shape corpus, regenerated forfind_history_target's statement);make format-check lint typecheck; the unit tests for the Postgres authority, rollback, redaction, erasure, idempotency, profiles and migrations (2,441 passed).test_cross_principal_leakage.py::test_positive_control_a_reader_of_the_repository_reads_its_decisionfails in every local run: it needs the code-index fixture CI sets up.test_a_write_made_unembedded_over_an_embedded_key_retires_its_vectors[memory.update-change3]failed once under host load and passed twice alone.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: every reader of the journal, the trigger against inserts that name no metadata column, the migration against a journal written by the build before it, and the suites below.
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.docs/reference/configuration.mdand thedocs/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).main; no merged migration is edited.hooks/,lib/,bin/,skills/,.mcp.json, the Codexplugin-defaults.json) bumps both plugin manifests' version, and no other open PR uses that version.npm --prefix frontend run build) and its tests pass, iffrontend/changed.docs/describe the system as it now is, and this description names any operator steps and wire changes.tests/unit/test_public_copy.py).git commit -s), as CONTRIBUTING.md asks.🤖 Generated with Claude Code