Skip to content

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
zlareb1 merged 1 commit into
mainfrom
feat/pg-revision-metadata
Nov 9, 2026
Merged

zlareb1 merged 1 commit into
mainfrom
feat/pg-revision-metadata

Conversation

@zlareb1

@zlareb1 zlareb1 commented Nov 9, 2026 •

Copy link
Copy Markdown
Member

Follows #433 (merged). The second half, clearing delivered revisions' payloads, follows in the next release.

Changelog category (leave one):

  • Improvement

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.row keeps every version's full row for good, while ClickHouse's memory_versions holds the same. Long term only the metadata is needed: version, content hash, status, redaction. This PR does the reader half: readers stop depending on row for 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 reads row->>'agent' and friends, and would mismatch or fail on a NULL row. So only a build after one that tolerates it may write it.

Design

  • Migration 003_revision_metadata.sql adds agent, session_id, memory_key, status, redacted_at and redaction_reason to loom.memory_revisions, and lets row be NULL.
  • A trigger keeps them. memory_revisions_metadata, BEFORE INSERT OR UPDATE OF row, sets them from row whenever a writer sets it, whatever build it is. Each falls back to the loom.memory column's default for a field row leaves out, and when row is 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.
  • No rewrite of the journal. The columns are added nullable and row drops its NOT 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, from row (pg_memory._meta, coalesce(col, row->>'col', default)). No backfill, no NOT NULL, no index build in the migration's transaction, as migrations requires for a large table.
  • No new index; a profile revision keeps its payload. The redaction's reach into the profiles folded from the memory (_PROFILE_REVISIONS, the journal's profile arm of _REDACTED) keeps matching on row, which the partial index memory_revisions_profile serves, so a profile revision keeps its payload for good (the follow-up's clearing leaves it). Every other journal predicate keeps its memory_id equality, served by memory_revisions_by_id.
  • Readers on the columns.
    • 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's memory_key and the erasure's consolidated-dependents query read the column, falling back to row, inline (their packages cannot import the memory store).
  • Content when the payload is gone.
    • 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.
    • The admission's gap read (_gap_cleared, revisions_since) does not clear a gap with a cleared payload; the write reaches its verdict on peers read anew.
    • A redaction sets the typed columns too, so a revision without a payload is marked.
  • In this build every commit still writes row, so the fallbacks have nothing to act on until the follow-up ships.

Scope and risk

  • The migration's ALTER TABLE takes ACCESS EXCLUSIVE on loom.memory_revisions for catalog changes only (the boot's lock_timeout bounds the wait for it), and the file rewrites no row.
  • Erasure: the columns hold the key, status and redaction facts the authority already held. The erasure step deletes revisions by (org, namespace) or user_id, so the census and the saga are unchanged.
  • Untouched: the heads (loom.memory_current), the deliveries, the ClickHouse authority.

Compatibility, rollout and rollback

  • Wire: none.
  • Operator steps: none; the migration runs at boot.
  • Rollback: the migration is additive. N-1 ignores the columns and the trigger keeps filling them; row stays set by every writer.

Tests

  • test_pg_authority.py::test_a_revisions_metadata_is_kept_from_its_row_and_outlives_it (integration; fails on main, 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 its row; a scrub sets the redaction columns; a cleared row leaves 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 were NOT 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) and test_a_version_whose_payload_was_cleared_serves_clickhouses_row_as_redacted (revisions_at serves 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 from find_history_target's ClickHouse statement (the profile tests' target no longer sets it).
  • pytest tests/analyzer (the statement-shape corpus, regenerated for find_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).
  • Integration, Postgres authority (the 35 files of CI's Postgres job, against this branch's server with migration 003 applied to a fresh Postgres): 369 passed, then, at this head against a Postgres with migration 003 as it now stands, the 24 redaction, metadata and rollback tests passed (the trigger's clearing branch among them). test_cross_principal_leakage.py::test_positive_control_a_reader_of_the_repository_reads_its_decision fails 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 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 (hooks/, lib/, bin/, skills/, .mcp.json, the Codex plugin-defaults.json) 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

@zlareb1 zlareb1 changed the title Under Postgres, each revision's key, type, status, source trace and redaction live in typed columns that every journal reader matches on Under Postgres, each revision's key, status and redaction live in typed columns that every journal reader matches on Nov 9, 2026
@zlareb1 zlareb1 changed the title Under Postgres, each revision's key, status and redaction live in typed columns that every journal reader matches on Under Postgres, each revision's key, status and redaction live in typed columns that every journal reader but the profile reach matches on Nov 9, 2026
…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
zlareb1 force-pushed the feat/pg-revision-metadata branch from ba5f06e to 982d7e0 Compare November 9, 2026 19:06
@zlareb1
zlareb1 merged commit 68c8444 into main Nov 9, 2026
71 of 72 checks passed
@zlareb1
zlareb1 deleted the feat/pg-revision-metadata branch November 9, 2026 20:20
@zlareb1
zlareb1 restored the feat/pg-revision-metadata branch November 9, 2026 20:21
@zlareb1
zlareb1 deleted the feat/pg-revision-metadata branch November 9, 2026 20:22
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