Repository navigation
A bulk_set batch writing a key twice owes a search document only for the row it embedded, and identity dedup finds a keeper ClickHouse is still owed - #446
Merged
Conversation
…the row it embedded Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: zlareb1 <[email protected]>
…wice owes one, and a test pins both cases Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: zlareb1 <[email protected]>
… on their own lines Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: zlareb1 <[email protected]>
…ads, so a keeper written a moment ago is found Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: zlareb1 <[email protected]>
…till owed to it from the authority's undelivered revisions Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: zlareb1 <[email protected]>
…ecks every keeper either read found against its head Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: zlareb1 <[email protected]>
…t bounds it; a test pins the read order 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.
Fixes the Postgres memory-authority CI jobs on
main, red since #433.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, amemory.bulk_setthat writes one key twice no longer holds the namespace's searches at their barrier (503PROJECTION_BEHIND) until the batch's lease runs out, and a bulk write or import of a value the same identity wrote a moment ago is held by it as an exact duplicate.Why
test_sensitivity_high_canary.py::test_one_bulk_batch_with_a_key_twice_keeps_a_vector_only_if_its_last_row_is_embedded(and, by the same cause, other writes into that shared namespace) failed in both Postgres memory-authority jobs from #433 on: the search after the batch answered 503PROJECTION_BEHIND.A batch that writes a key twice commits two revisions of the key; when only the last is embedded (the earlier row is 'high' or of an unembedded type), only the last has a search document.
bulk_set._commit_batchgave the search-document target (SEARCH_DOC) by key, so both revisions owed a document. Before #433 the writer cleared that target by key too, so the earlier revision's target was cleared with the last's. The publication batch (pg_batch._landed) clears it only for the version a document was built from, which is right, so the earlier revision kept owing a document nobody sends, and every search of the namespace waited at its barrier for it until the batch's lease ran out and the delivery worker settled it.Reproduced locally: right after such a batch,
loom.memory_deliveriesholds the first revision owing onlySEARCH_DOC(targets = 2) under the writer's lease.A second regression of the same kind showed on this PR's own Postgres 18 job:
test_memory_import.py::test_a_pinned_memorys_own_text_is_held_by_it_and_competes_with_nothingheld the imported copy as amergeinstead of anidentity_duplicate.memory.bulk_set's identity dedup (_bulk_identity_dupes) found its keepers in ClickHouse'sloom.memoryand then dropped the ones the authority no longer holds; since #433 a first write answers at its commit, before ClickHouse holds it, so a keeper written a moment ago was not found.Design
content_sha256narrows, and under Postgres first reads the keepers ClickHouse is still owed: the identity's revisions of the batch's hashes whose delivery still owes the memory row (pg_memory.unpublished_keepers, through the namespace's deliveries still owing the row, parked ones left out, in the caller's read scope; the connection's statement timeout bounds it). Read first, so a delivery that clears between the two reads was in ClickHouse before its read. Every keeper either read found is checked against its head on the authority (_keepers_on_the_authority), in ClickHouse's order, so one rewritten or deleted since is not one and a key rewritten a moment ago keeps its new bytes. Reading every head of the identity on the authority instead would scan them all (no index onmemory_current.content_sha256, and a migration builds none on a large table)._commit_batchgivesSEARCH_DOConly to a row whose(identity key, version)has a search document in the batch, matching what the publication clears. An earlier row of a key written twice owes none unless it was embedded too (then both own a document and both owe one).Scope and risk
bulk_set._commit_batch, and one Postgres read in identity dedup over the namespace's deliveries still owing the memory row (parked ones left out; the statement timeout bounds it). The delivery worker builds a document only for a revision that owes one, so an earlier, unembedded revision of a key written twice now gets none built, as its head never serves it.Compatibility, rollout and rollback
Tests
tests/unit/test_pg_authority.py::test_a_bulk_batch_writing_a_key_twice_owes_a_document_only_for_its_embedded_rows(its first case fails onmain): a batch of[k, k]with only the last row embedded commitsMEMORY_ROW | AUDIT_ROWfor the first revision and addsSEARCH_DOConly for the last; with both embedded, both owe one.tests/integration/test_sensitivity_high_canary.pyagainst a Postgres-authority server: fails onmain(test_one_bulk_batch_with_a_key_twice_keeps_a_vector_only_if_its_last_row_is_embedded[False], 503PROJECTION_BEHIND); 14 passed, three runs in a row, with this change.tests/unit/test_bulk_identity_dedup.py::test_under_postgres_a_keeper_clickhouse_does_not_hold_yet_is_found: a keeper only the authority's undelivered revisions hold is found, read in the caller's scope, and a rewritten one is dropped by the head check.test_pg_authority.py::test_a_bulk_write_of_bytes_another_key_holds_is_judged_on_the_authority(integration, 3 passed): an entry whose bytes a key holds whose delivery is staged undelivered for an hour (so ClickHouse shows its old value) is held; one whose keeper was deleted or rewritten since is written. The undelivered case fails onmain.test_bulk_identity_dedup.py::test_under_postgres_a_keeper_delivered_between_the_two_reads_is_found: the undelivered keepers are read before ClickHouse, so a delivery landing in between is found by one of the two reads.test_bulk_identity_dedup.py::test_under_postgres_a_key_rewritten_a_moment_ago_keeps_its_new_bytes: ClickHouse shows a key's old bytes, its undelivered rewrite holds the new; the batch carrying both finds the key for the new bytes.test_memory_import.py,test_sensitivity_high_canary.py,test_memory_bulk.pyandtest_bulk_conflicts.pyagainst a Postgres-authority server: 43 passed, twice in a row.make format-check lint, mypy on the changed files, and the whole unit suite (32,182 passed). The full Postgres-authority integration list is this PR's CI jobs: a local run was stopped by the host's memory pressure.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 failing CI job's log, a local reproduction against
main, 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.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