Repository navigation
A source sync reads an address's owner again just before it writes, so a document a person wrote during the fetch is left alone - #353
Merged
Conversation
…o a document a person wrote during the fetch is left alone sync_item checked that no other writer held the address before fetching and converting the file, seconds earlier; a knowledge.add or knowledge.upsert at that address in between was then superseded by the worker's copy, its author replaced by worker:knowledge-source-sync. write_document now reads the live document again after the pass's stop check and writes nothing when another writer holds it; each kind counts that file skipped, as the check before the fetch does. Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: zlareb1 <[email protected]>
…eck runs right before the write; each kind tests the skip Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: zlareb1 <[email protected]>
zlareb1
force-pushed
the
fix/source-sync-write-time-owner
branch
from
November 7, 2026 12:40
b2c67d1 to
cf8ccb3
Compare
… checks the write step leaves it The Linear, Notion and recording tests no longer stub write_document: the fetch answer saves a person's document at the address, and each test checks that nothing is upserted, the person's document stays and the file is counted skipped. The recording harness answers a transcript's entries from a callable too. The recording _fetch_and_write docstring is refilled. Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: zlareb1 <[email protected]>
…istency On replicated ClickHouse the read just before a write could land on a replica that has not seen a person's write during the fetch and answer that the address is free. write_document now makes that read inside sequential_reads(), as require_current does; the check before the fetch stays a plain read. The module docstring says the address is read again before each write and names counted among the helpers kind modules use. Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: zlareb1 <[email protected]>
…fore it retires the document there retire read the owner with a plain read, so a replica that has not seen a person's write at the address could answer that the document is still the source's, and a retirement of an absent or moved item would delete the person's document. The read now runs inside sequential_reads(), as the write-time read does. The knowledge feature page and the module docstring split the re-read sentence and state the skip rule once. 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.
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):
A knowledge source's sync no longer overwrites a document a person writes at the same address while the sync is fetching and converting that file.
Why
source_sync.pypromises that "a document another writer or another source holds is never written or retired".sync_itemkept that promise only at the start: it called_may_write(src, uri)before the fetch, then_fetch_and_writedownloaded the file and sent it to the extractor (tens of seconds for a large PDF) and wrote withwrites.handle_knowledge_upsert, which has no ownership guard (_require_source_tags_keptreturns early when the prior row's actor is not the sync worker). Aknowledge.addorknowledge.upsertat that address in between was superseded by the worker's copy, and the document's actor becameworker:knowledge-source-sync. The same write step is shared by the Linear, Notion and recording kinds.retirealready re-checks right before its delete; the write did not.Just before each write the turn reads the source again (as before), then
write_documentreads the address's owner again with_may_writeundersequential_reads()(so a replica that has not seen the person's write cannot answer that the address is free), then runs the pass's stop check, then upserts; it returns False, writing nothing, when another writer holds the address. A retirement reads the address's owner with sequential consistency too, so a person's document that replaced the worker's copy is not deleted when its item drops out of a full listing or moves. Each kind's write step passes that tocounted, which counts the fileskipped(as the check before the fetch does) orchanged.Scope and risk
loom.documentsper written file.Compatibility, rollout and rollback
skipped.Tests
test_an_address_a_writer_takes_during_the_fetch_is_not_overwritten(folder): a person writes at the address while the file is downloaded; onmainthe worker's upsert goes through, here nothing is upserted, the person's document keeps its actor, andskipped == 1.test_an_address_taken_during_the_fetch_is_counted_skipped(Linear): the same race during the document fetch.test_a_page_whose_address_is_taken_during_the_fetch_is_counted_skipped(Notion): the same race while a page's blocks are read; the two database pages are still written.test_a_transcript_whose_address_is_taken_during_the_fetch_is_counted_skipped(recordings): the same race while a transcript's entries are read.test_the_write_time_owner_read_reads_with_sequential_consistency: the check before the fetch is a plain read, the one just before the write runs undersequential_reads().test_the_retire_owner_read_reads_with_sequential_consistency: a retirement's read of the address runs undersequential_reads().sequential_reads()scope removed.test_knowledge_source_sync.py,test_knowledge_source_sync_linear.py,test_notion_source_sync.py,test_knowledge_source_recordings.py: 298 passed.ruff: pass.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; the failing case and the four write paths were checked against the code.
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