Skip to content

Diagnostic reports read memory at the Postgres authority's barrier and cite only the heads it serves - #391

Merged
zlareb1 merged 13 commits into
mainfrom
feat/i160-pg-reports
Nov 7, 2026
Merged

zlareb1 merged 13 commits into
mainfrom
feat/i160-pg-reports

Conversation

@zlareb1

@zlareb1 zlareb1 commented Nov 7, 2026 •

Copy link
Copy Markdown
Member

Related: #160

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 the Postgres storage authority, namespace.audit, namespace.validate, namespace.tune, memory.inspect and knowledge.inspect's decision counts and memory findings read memory once ClickHouse holds every write the namespace committed, and say so in skipped when it does not; a finding cites a row only while the authority still serves that version.

Why

Under LOOM_STORAGE_AUTHORITY=postgres the diagnostic reports read ClickHouse alone. A write committed to Postgres and not yet published was missing from their counts, and a finding could cite a ClickHouse row that the authority had already rewritten, deleted or redacted. Before this change such a row was cited at the old version with an empty hash. docs/architecture/storage-authority.md listed memory.inspect's counts and the cited revisions of namespace.audit and namespace.validate as open against the isolation gate. namespace.inventory already waited at the search barrier.

What changes

  • One barrier for every report. pg_validation.published_reads(org, namespaces, skip) waits for ClickHouse to hold every revision committed so far in the namespace, using the same admit a search and namespace.inventory use. If anything was behind, the reads that follow are sequential. A parked delivery is not waited for. namespace.inventory now uses this helper and behaves as before: past the wait it answers 503 PROJECTION_BEHIND.
  • The reports do not fail on it. Audit, validate, tune and inspect already promise that a section they cannot read lands in skipped. When the wait runs out (PROJECTION_BEHIND) or Postgres does not answer (POSTGRES_UNAVAILABLE), they read what ClickHouse holds and add projection: <code>: <why> to skipped. Audit and validate also list projection in coverage.rules_skipped, so coverage.complete is false.
    • memory.inspect then reports both views with complete: false, since they may miss committed writes.
    • knowledge.inspect waits once, around its decision tally and the audit it runs for its memory findings, the sections that read memory rows; its documents are not part of the memory authority.
  • No second wait. A report run inside another's reads does not wait again: tune and knowledge.inspect run the audit inside their own wait.
  • Citations are the authority's heads. reads.live_revisions keeps a ClickHouse row only while the authority's head of its key has the same version and the same redaction state. The row is hashed from that head's value, which is what memory.get serves. A rewritten, deleted or redacted row is not cited.
    • The Postgres heads are now read once per report instead of once inside _served_hashes.
    • The citation read selects redacted_at IS NOT NULL as well (tests/analyzer/shapes.txt regenerated).
  • docs/architecture/storage-authority.md describes the reports' barrier and citations, and drops them from the list of reads that are still open; docs/features/namespaces-and-sharing.md names projection in coverage, in memory.inspect's complete, and the Postgres rule for which rows are cited.

On the ClickHouse authority (the default) nothing changes: admit returns at once, and the citation read takes the same path as on main plus the one column.

Scope and risk

  • No memory is written by the reports. Under Postgres each report makes one more Postgres query, for the owed namespaces. When ClickHouse is behind, the report waits up to LOOM_PG_PROJECTION_WAIT_MS (2 s by default). As with a search's wait, the report may publish another writer's lapsed deliveries while it waits (wait_searchable calls deliver_namespace), which inserts their ClickHouse rows and embeds their search documents.
  • If Postgres does not answer the citation read, every finding is left uncited and evidence appears in skipped; the report still answers (test_a_postgres_down_at_the_citation_read_leaves_the_findings_uncited).
  • Wire: no field added or removed. skipped and coverage can name projection.
  • A row whose newer version is parked stays counted by the ClickHouse checks. It is not cited, because the authority serves another version.

Tests

  • Unit (tests/unit/test_pg_authority.py):
    • A report waits once and reads sequentially when the projection was behind.
    • A caller without skip gets the 503; a caller with one is told the code.
    • A citation is kept only for the head the authority serves: rewritten, deleted and redacted rows are dropped, and the hash is the head's.
  • Unit: a projection wait that runs out still produces each report and names projection in skipped:
    • audit and validate, whose coverage is then not complete (test_namespace_audit.py, test_namespace_validate.py);
    • memory.inspect with Postgres down (test_memory_inspect.py);
    • knowledge.inspect, which reads its decisions and the audit's findings in one wait the audit does not repeat (test_knowledge_inspect.py);
    • tune, which waits once (its audit does not wait again) and builds the same drafts (test_namespace_tune.py).
  • Unit: the existing report tests run with the new column.
  • Integration (tests/integration/test_pg_authority.py, which runs in CI's integration-postgres job): after a newer version is committed with its delivery parked, the audit still raises ClickHouse's finding but cites no row for it, coverage stays complete, and memory.get serves the newer version.
  • Local runs: the touched unit files, tests/analyzer, doc links, public copy, settings reference and package contracts pass. The Postgres integration test was not run locally (the host had too little memory for ClickHouse, Postgres and a server); CI's Postgres 16 and 18 jobs run it and pass.

🤖 Generated with Claude Code

@zlareb1
zlareb1 force-pushed the feat/i160-pg-reports branch 6 times, most recently from 5c56be9 to 548743c Compare November 7, 2026 23:07
zlareb1 and others added 13 commits November 7, 2026 23:50
…d cite only the heads it serves

namespace.audit, namespace.validate, namespace.tune, memory.inspect and
knowledge.inspect's decision counts start once ClickHouse holds what the
namespace committed. A wait that runs out, or a Postgres that does not answer,
reads on and names `projection` in `skipped` and `coverage`. A finding cites a
sampled row only while it is its key's live head at the version read.

Related: #160

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: zlareb1 <[email protected]>
…ings say they read on, and each report's skip path is tested

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: zlareb1 <[email protected]>
…ion hash reads the head it kept; a Postgres outage at the citation read is tested

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: zlareb1 <[email protected]>
… projection wait

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: zlareb1 <[email protected]>
….inspect's docstring names the wait's side effect and parked writes

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: zlareb1 <[email protected]>
…is main's again; the evidence and wait-setting comments name the reports

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: zlareb1 <[email protected]>
… come from _row_key; the report_rules imports are one line again

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: zlareb1 <[email protected]>
…flag's comment says what it means

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: zlareb1 <[email protected]>
… with fenced_until set

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: zlareb1 <[email protected]>
…amespace committed

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: zlareb1 <[email protected]>
…ry.inspect's complete

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: zlareb1 <[email protected]>
…ect's incomplete views

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: zlareb1 <[email protected]>
…s is not cited

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: zlareb1 <[email protected]>
@zlareb1
zlareb1 force-pushed the feat/i160-pg-reports branch from 548743c to 6cf2da1 Compare November 7, 2026 23:52
@zlareb1
zlareb1 merged commit 85ce3ea into main Nov 7, 2026
23 checks passed
@zlareb1
zlareb1 deleted the feat/i160-pg-reports branch November 7, 2026 23:52
@zlareb1 zlareb1 mentioned this pull request Nov 12, 2026
3 tasks done
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