Repository navigation
loom knowledge migrate-originals moves the originals held in ClickHouse to the bucket, hash-verified - #285
Merged
Conversation
zlareb1
force-pushed
the
feat/knowledge-migrate-originals
branch
2 times, most recently
from
November 6, 2026 14:25
778f97e to
b9ea889
Compare
…se to the bucket Each original whose latest catalog row holds its bytes is checked against its sha256, written to its own object with the store's SHA-256 check, read back and hashed, and then switched by a new catalog row naming the object. Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: zlareb1 <[email protected]>
… and refuse short bytes A move does not start under an unfinished erasure of its namespace or an uploader, ends before its row when one registers during the copy, and waits out a namespace erasure that registers as the row lands; a user erasure there is named to run again. Bytes that do not fill their size are refused, an object gone before its read-back is not switched, and each page of the walk reads its own key range. The help and docs say the ClickHouse copy stays until a merge. Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: zlareb1 <[email protected]>
… an erasure kept A user erasure is matched by upload records and by the writers of documents that name the original. An original an erasure kept during the copy is reported, not counted as gone; a switch under an uploader's erasure is listed to run that erasure again; the move deletes an object no row will name; the messages name the erasure; an empty page is told by its row count. parse_namespace_list moves to server/erasure/domain so the knowledge store can read the ledger's scopes. Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: zlareb1 <[email protected]>
…ides A namespace erasure there takes the move back at once; a user erasure is waited for and decided by whether the moved object survived it, the erasure deleting every object of an original it takes. Uploaders are read once per page, the row is written within the upload budget of the copy, an object gone before its read-back is an error, and the ledger query no longer shadows status. Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: zlareb1 <[email protected]>
…witch is reported Whose an original is can change with any write, so a move no longer reads its uploaders: every unfinished, or just finished, user erasure of the org holds it back. A failure after the row is switched lands in left_to_erasure rather than stopping the walk; the clock is _cutoff_ms's; the docs name the bucket walk's min-age setting. Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: zlareb1 <[email protected]>
…ed erasure's fix An original no live document, upload or ingestion names is counted and left to the sweep, so a move cannot re-create one the sweep just took. A failed erasure's fence points at loom erasure-re-verify --resume; a namespace erasure that overtook the copy counts as erased; only the reads after the switch are caught, and a failed object delete when taking a row back says what is left. Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: zlareb1 <[email protected]>
…, not a stop An erasure that started during the copy is reported as started, one that just finished asks for a minute, and a switch it could not confirm is listed as unconfirmed. A key too long for the bucket is a per-original error, so the walk goes on. Originals nothing needs are counted as left to the sweep after its min age; _settle reads in one pass; the docs are reflowed. Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: zlareb1 <[email protected]>
A failed erasure, else an unfinished one, else one that just finished names the refusal, at the start and after the copy alike; the help lists both reasons a switched original exits 1. Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: zlareb1 <[email protected]>
…ce once per page After its row lands, a move whose original nothing needs any more is taken back, so it cannot outlive the upload records the sweep took. A failed erasure that raced the switch is not waited out. The upload budget starts with the write, as an upload's does. The clock and the first ledger read are one per page (blobs.fence), coverage depending on the namespace alone. Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: zlareb1 <[email protected]>
…weep Taking it back deleted a row with no age bound; after a merge that row can be the only one left for a racing writer's original. The sweep's own age bound takes it instead. A namespace erasure that overtook the copy while the original is still held is reported, an erasure that held one back makes the walk read the fence again for the rest of the page, and a failed take-back is reported. Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: zlareb1 <[email protected]>
…wn start The walk reads the fence per namespace and, after an erasure held an original back or raced its switch, again; a refusal ends the namespace with one line. Each move takes its own start for the ledger checks, so an erasure that ended before its copy is not reported as racing it. A failed take-back names the row to delete, and a failed object delete there is left to the bucket walk. Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: zlareb1 <[email protected]>
…e fence is a string The advice names the worker before the re-verify, an erasure that finished just now reads right in either phrase, and the docs say a namespace is not started under an open erasure while one registered later ends a move after its copy. Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: zlareb1 <[email protected]>
…arted in it move_to_bucket takes fenced=True from the walk instead of a refusal string, the wait constant is private like its siblings, the module and walk docstrings name the needed-only rule and the namespace-wide refusal, and a test loop reads plainly. Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: zlareb1 <[email protected]>
The fenced switch had one caller, which always set it. The live tests that checked a refusal now go through the walk and its one error line. Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: zlareb1 <[email protected]>
A namespace erasure that took a move back, or one that took the original during its copy, came back as a plain skip, so the next original was copied before the fence stopped it. A raced user erasure's outcome is read by listing the moved object, not downloading it; the ClickHouse clock read has its own name; the test stubs and phrases match the code. Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: zlareb1 <[email protected]>
…es its namespace An unreadable list or an unknown scope fences a move but is waited for and decided by the moved object, not guessed. A failed insert is reported as an unconfirmed switch, and an erased original whose take-back failed counts as skipped, not moved. Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: zlareb1 <[email protected]>
…that object When a user erasure that raced the switch leaves the moved object but no row names it (a replica without the bucket set deletes rows only), the object goes and the original counts as erased. _covers and deletes_namespace share one namespace helper, a mid-namespace refusal speaks of the rest of its originals, and the walk's comment names every case that reads the fence again. Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: zlareb1 <[email protected]>
…amed so _settle reads its three outcomes in one guarded pass, so a failed row check or object delete there is reported rather than stopping the walk. A failed insert of the switching row no longer counts as moved. SwitchUnconfirmed and Migrated.unconfirmed name what they hold, as the CLI line already did. Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: zlareb1 <[email protected]>
…chable branch goes A row-only take by a user erasure cannot happen: a replica without the bucket fails its erasure closed. The wait no longer holds a move for an unrelated erasure registered after the row landed; a failed read-back deletes the object it wrote; an unconfirmed switch whose row may not stand counts as neither moved nor skipped; the docs say the bucket then needs its own backup. Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: zlareb1 <[email protected]>
…the run stops A switched row is not walked again, so its line is its only record: it is logged when caught, and the CLI prints what the walk gathered before an error leaves it. Refused namespaces and unconfirmed switches have their own counts; a dry run sizes the move before the store is switched; a failed cleanup after a failed read-back no longer hides the read's error. Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: zlareb1 <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: zlareb1 <[email protected]>
…ts run the real erasure A user erasure on a replica without the bucket that read the scope's rows before the switch landed deletes the row and leaves the object: the move deletes it. The race tests now run erase_blobs_by_user and delete_document_blobs_by_namespace themselves, kept by a second writer's document where it should be. The docs name every replica on s3 as part of the fence; the move's docstring is its contract. Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: zlareb1 <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: zlareb1 <[email protected]>
… read The move builds its location before reading the original, and the walk checks the key length once per namespace, refusing it in one line. The copy-time test runs the namespace erasure's own blob step. Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: zlareb1 <[email protected]>
…each the take-back The fence, copy, settle and wait move to server/knowledge/app/originals.py; the knowledge store keeps its statements (the clock, the switching insert, the row check, the take-back), and the ledger read moves to server/erasure/store/ledger.py behind server/erasure/app/ledger_reads.py, so no plane runs SQL on another's table. The race hooks register the erasure and run its blob step before the switching insert, so the switched row lands alone and the take-back is what removes it. The refusal test names the covering erasure and shows the others let the move through; a failed delete on the copy-time path no longer hides the refusal; the CLI help points at the docs. Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: zlareb1 <[email protected]>
A refused delete there is logged and left to the bucket walk, so the move's outcome stands: a replaced row still reads as skipped, a corrupt read-back still as corrupt. The per-original key-length case is gone, as the walk refuses such a namespace whole before any read. Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: zlareb1 <[email protected]>
blobs.unwrite deletes the row alone and _settle drops the object, as every other cleanup does. The summary counts refused namespaces whatever refused them, the ledger docstring names the statuses that exist, and move_to_bucket's client is typed and its reach stated. Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: zlareb1 <[email protected]>
…refuses it Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: zlareb1 <[email protected]>
…bucket walk Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: zlareb1 <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: zlareb1 <[email protected]>
…_location uses Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: zlareb1 <[email protected]>
A stop during the wait would otherwise leave no line naming a switched row the walk never reads again. The write id's length is a named constant, and _one says it returns False for what an erasure may explain. Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: zlareb1 <[email protected]>
A document's extraction artifact and an original an unexpired upload holds both move. The store's docstring says what the move deletes, a test is named for what it checks, and _covers reads plainly. Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: zlareb1 <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: zlareb1 <[email protected]>
A take-back after a merge could delete the only row of a same-bytes re-upload that landed between an erasure and the switch: the switch, stamped now, outranked it. The switch now carries the read row's created_at plus one millisecond, so any later write wins the merge. A dry run that lists a refused namespace exits 1. Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: zlareb1 <[email protected]>
The re-read before the switch compares the latest row's version with the walk's, so a later ClickHouse-store write of the same sha is not counted as moved. The docs say a moved original keeps its age for the sweep, and a live test checks it under a 1 s bound. The race tests finish their erasures only after the switch registered them. Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: zlareb1 <[email protected]>
The race tests' finisher waits for the switching insert itself, and the replaced-row test covers a re-upload on the ClickHouse store, which only the version check catches. The command's doc paragraph is rewrapped. Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: zlareb1 <[email protected]>
With no erasure raced, the switch stands only while the latest row names its object; a write between the re-read and the switching insert outranks it, and the move counts as skipped, its object left to the bucket walk once the rows merge. Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: zlareb1 <[email protected]>
The check that a later write outranked the switch has its own unconfirmed message, the settle summary and the docs describe the case, and the tests pin the object left behind and the settle branch. Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: zlareb1 <[email protected]>
The kept branch judges the switch by the same latest-row rule as the unraced one, and one store read (blobs.latest, with its location and version under sequential consistency) serves the re-read and that rule. The settle tests check an outranked switch deletes nothing. Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: zlareb1 <[email protected]>
The two remaining checks after a failed read and an overtaken copy read the latest row through blobs.latest as the re-read does, and the docstring names both cases SwitchUnconfirmed covers. Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: zlareb1 <[email protected]>
A replica behind the walk's could answer the byte read with nothing while the sequential check after it found the row held, reporting a sound original as corrupt. Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: zlareb1 <[email protected]>
When the byte read finds nothing, the move reports the original corrupt only while the latest row is still the version the walk read; a newer one was written since and the move is skipped. Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: zlareb1 <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: zlareb1 <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: zlareb1 <[email protected]>
held_in_clickhouse answers after='' when its page reached the namespace's last key, as its field says, so the walk no longer reads one empty page per namespace. Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: zlareb1 <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: zlareb1 <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: zlareb1 <[email protected]>
zlareb1
force-pushed
the
feat/knowledge-migrate-originals
branch
from
November 6, 2026 18:49
5f438a4 to
c2a676c
Compare
Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: zlareb1 <[email protected]>
The switched row carries the original's age, so the sweep's age-bound delete can take it as it lands. With no row left, the move deletes its own object, which no row can name again, rather than leave bytes no erasure finds until the bucket walk's age. Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: zlareb1 <[email protected]>
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.
Related: #157
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):
loom knowledge migrate-originalsmoves the document originals still stored in ClickHouse to the S3-compatible bucket. Each one is hash-verified before and after the copy, and only then switched to the object.Why
Since #167,
LOOM_DOCUMENT_OBJECT_STORE=s3writes new originals to a bucket. Originals uploaded before the switch stayed inloom.document_blobs.data, with no way to move them. The issue's plan calls for moving those originals with a copy that is verified before each document is switched. After this command runs and the table merges (orOPTIMIZE TABLE loom.document_blobs FINAL), ClickHouse holds only the catalog rows and the originals nothing needs, which the sweep deletes, and the bytes are in the bucket.Design
The walk: it goes one namespace at a time (
blobs.namespaces, which takes an optionalorg), and through each namespace in key order (blobs.held_in_clickhouse). It moves only the originals the namespace still needs (blobs.needed, one read per page): those a live document names, as its original or its extraction artifact, or that an unexpired upload or an open ingestion holds. The rest are counted as left to thedocument_blob_gcsweep, which deletes each once it is older thandocument_blob_min_age_seconds(itsunreferencedpredicate); one that is needed again by then moves on a later run. Moving them would waste a transfer, and could re-create an original the sweep had just deleted along with its upload records, out of reach of its uploader's erasure until the next sweep. The per-page read narrows that window, but does not close it: a document deleted after the page's read, with the sweep taking the original in the instant before the move's row lands, leaves a switched row with no upload record until the sweep takes it once it is older than its min age, counted from its last upload (the switch keeps the moved row's age).blobs.neededreads the namespace's documents once per page, as the sweep'sunreferenceddoes: measured on a namespace of 300,000 documents, a page takes 300,000 rows, 22.6 MiB and 36 ms. A whole walk is pages × documents, about 5,000 pages of 1,000,000 rows for a million originals and as many documents, which suits a one-off operator command.limit-th row after the cursor, in key order on one thread.argMax(location, created_at)) has no location, which means the bytes are still in ClickHouse. It reads nodata.system.query_log, a page of 200 in a namespace of 1,000,000 originals reads 15,104 rows for the bound and 256 for the range. An aggregate over the rest of the namespace with aLIMITread all 1,000,000 rows and 137 MB of memory. A(org, namespace, sha256) >cursor across namespaces read the whole table on every page.originals.move_to_bucket(inserver/knowledge/app/originals.py, which holds the orchestration; the knowledge store keeps the statements it uses) moves one original:<prefix>/<org>/<namespace>/<sha256>/<write id>, with the store's SHA-256 check, as an upload does.blobs.latest, its location and version). If it is no longer the ClickHouse-held version the walk read (an erasure, the sweep or any re-upload changed it since the walk, before this read), the move deletes its own object, which no row will name, and stops.DOCUMENT_UPLOAD_BUDGET_Shas passed since the object write began (counted from the write, after the transfer slot is taken, as an upload's is). The bucket walk may delete an object no row names once it is older thandocument_blob_min_age_seconds, so a late row could name a deleted object. Past the budget, the move deletes its object and reports the original.created_atis the read row's plus one millisecond, not the time it lands, so a write of the same bytes after the walk's read outranks it in every merge, and a take-back (by the location only the switching row names) can only remove the move's own version.blobs.latestnames it); a user's erasure that kept the original is judged by the same rule: a write landing between the re-read and the switch outranks it, and the move is counted as skipped, its object left to the bucket walk once the rows merge. A failed read there is reported as its own unconfirmed switch, naming the row to check. When that read finds no row holding the original (the sweep's age-bound delete took it with the switched row, which carries the original's age), the move deletes its own object at once, since no row can name it again; a sweep delete landing after that read leaves the object to the bucket walk, the same window as the document-deleted race above. An original nothing needs any more by now (its last document went as it moved) keeps its switched row, and the sweep deletes it once it is older than its min age, counted from its last upload since the switch keeps the moved row's age, as any original nothing names. A take-back here would be a delete with no age bound, and after a merge the moved row can be the only row left for a racing writer's original.Documents name an original by its sha, so that one row switches every document with those bytes. The ClickHouse copy stays until the ReplacingMergeTree merges the two versions. The upload records (
loom.blob_uploads) are keyed by the sha and stay as they are, so a user erasure still finds a moved original.The erasure fence: a move copies bytes an erasure may be deleting, so
loom.erasure_requests(read with sequential consistency) fences it.server/erasure/store/ledger.py::unfinished_since, called throughserver/erasure/app/ledger_reads.py, so the knowledge plane runs no SQL onloom.erasure_requests.namespacescope, or anamespace_listthat holds it) or any user's of the org. A user's erasure finds that user's originals through their upload records and their documents, and any write can add to either, so the move does not guess whose an original is. Erasures are rare, and a fenced original moves on a later run. An earlier version read the original's uploaders. It missed authors known only from documents, and then a writer added after its read.namespace_listparser moves fromserver/erasure/apitoserver/erasure/domain/scopes.py, so the knowledge app (originals.py) reads scopes with the erasure plane's own parser; the erasure plane's imports change with it.originals.fence), since coverage depends on the namespace alone, and again after any original that was not switched cleanly (an erasure may have held it back, raced its switch or taken it). A refusal ends the namespace with onerefusedline, not one per original. Each move takes its own start on the ClickHouse clock for steps 6 and 9, so an erasure that ended more than the 60 s margin before its copy began is not taken for one that raced it; one that ended within the margin is reported as having overlapped the copy. The ledger read scansloom.erasure_requests FINALfor the org (keyed by id), measured at 200,000 ledger rows, 6.1 MiB and 6 ms, twice per moved original: small beside the transfer.loom erasure-re-verify --resume, as the message says._erase_user_objects), and the move's object is there. Every build that reads bucket rows erases this way: prefix deletion arrived with the bucket store itself (Document originals can be kept in an S3-compatible bucket #167). So the move waits for the erasure to finish, up to 600 s. If the object is gone (listed, not downloaded), the erasure took the original and the move deletes its row. If the object and its row are still there, the erasure kept the original and the switch stands. If only the row went, the move deletes the object: a user's erasure on a replica without the bucket set that read the scope's rows before the switch landed deletes rows only. The wait covers only the erasures that raced the switch; one registered later reads the row.LOOM_DOCUMENT_OBJECT_STORE=s3, as the rollout already requires. A bucket-less replica's user erasure can also keep a moved row it never saw, which no check can tell from an erasure that kept the original; the user-scope census has nodocument_blobscheck to catch it. The docs say so.knowledge.app.originals.migrate_originalsreads the namespace's fence (the walk alone does;move_to_bucketdoes not), pages through the walk and moves each original. An original that fails is reported inerrors; a namespace refused for the rest of the walk (by an erasure, or because its object keys would be too long forobjects.MAX_KEY, checked before any read) is reported once inrefused, and one switched but unconfirmed (left to an erasure, or a failed check) inunconfirmed, printed asswitched, unconfirmed:; the walk goes on. A ClickHouse error stops the run, and the next run goes on from what is still held. A dry run counts the originals and their bytes, and reports each namespace a run would refuse (an erasure's fence, or object keys too long): it reads the ledger as a run does.loom knowledge migrate-originals [--org] [--namespace] [--dry-run]refuses to move anything unlessLOOM_DOCUMENT_OBJECT_STORE=s3(a dry run, which only reads ClickHouse, sizes the move before the store is switched), which should be set on every replica first so no new original lands in ClickHouse behind the walk. It exits 1 when an original was not moved; a dry run exits 1 when it lists a namespace a run would refuse. It is idempotent, so running it again picks up after a stop or a failure. After a move it prints that the ClickHouse copies stay until a merge, and namesOPTIMIZE TABLE loom.document_blobs FINAL.Docs: "Where originals are stored" in
docs/features/knowledge.md, a pointer from the originals step indocs/features/memory/retention-and-erasure.md, and the regenerated CLI reference.Alternatives considered:
An
INSERT … SELECTthat rewrites the rows in one statement cannot write the objects. The bytes have to leave ClickHouse through the client either way.A background worker that migrates on its own. The move is a one-off operator step that spends bucket transfers, so a command the operator runs and watches fits it better, and it records its own result.
Deleting the ClickHouse row's
datawith a mutation after the switch. The new row version supersedes it, and a merge (orOPTIMIZE … FINAL, which the operator chooses when to pay for) drops the old bytes without a mutation.Taking back a move whose original stopped being needed as it moved. The delete would have no age bound, so the sweep's own bound handles it instead.
Undoing a move after any racing erasure, which was this PR's first version. It can drop an original a user's erasure kept for another writer once the rows have merged.
Naming a user erasure that raced the switch to "run again". A completed saga does not run again, and a new one finds nothing, since the first deleted the user's records and documents. The moved object's survival decides the case instead.
Broad excepts: four handlers (around the switching insert, the checks in
_settle, the latest-row read in_stands, and the take-back) turn any failure after the object is written into a reportedSwitchUnconfirmed, raisedfromthe cause. Each carries its reason as a comment rather than# noqa: BLE001: ruff reports thatnoqaas unused (RUF100) on a handler that re-raises.Reporting: the summary counts originals moved, skipped, left to the sweep, not moved, switched but unconfirmed, and namespaces refused (by an erasure, or because their object keys would be too long). A switched row is not walked again, so each unconfirmed switch is logged as it is caught, and the CLI prints everything the walk gathered even when a ClickHouse error stops the run.
Scope and risk
LOOM_KNOWLEDGE_UPLOAD_MAX_BYTES), and writes through the process's bucket transfer slots.Compatibility, rollout and rollback
LOOM_DOCUMENT_OBJECT_STORE=s3writes. Run it only once every replica runs a build that reads bucket rows, which is the same condition as switching the store (upgrades).docs/operations/backup-and-recovery.mddescribes, and the knowledge page now says so.Tests
tests/integration/test_document_object_store_live.py(live ClickHouse and an S3-compatible store):unreferencedlists it under a 1 s age bound at once, since the switch keeps the original's age.loom erasure-re-verify --resume;erase_blobs_by_user,delete_document_blobs_by_namespace) after the move's last ledger read and before its switching insert, so the switched row lands alone and the take-back is what removes it (the tests fail with the take-back made a no-op);OPTIMIZE TABLE … FINAL.SwitchUnconfirmedand the switched row stands (the unit walk test checks that such an original is counted as moved, listed as unconfirmed, and the walk goes on).tests/unit/test_blob_move_fence.py: which erasures fence a move: its namespace's; a namespace list naming it (a bare array and stripped names included; an unreadable one counts); any user's; and not another namespace's.tests/unit/test_migrate_originals_walk.py: that the walk follows each page's cursor and stops on a short page; how the walk counts each original of a page (left to the sweep, moved, skipped, an error, or switched but unconfirmed); that a refused cleanup delete leaves the move's outcome as it is; that an erasure holding one back makes it read the fence again and a refusal then ends the namespace in one line; that a namespace refused up front is reported once and not walked; that a namespace whose object keys would be too long is refused before any read, in a run and in a dry run; that an erased original whose take-back failed is not counted as moved; and that the bytes are read with sequential consistency, as the checks after them are, so a lagging replica does not make a sound original read as corrupt; that missing bytes are corrupt only while the row the walk read is still the latest (a newer row, or none, skips the original); that a switch the sweep took, row and all, deletes its object at once; that a switch a later write outranked does not stand, with a failed read of the latest row reported on its own terms.tests/unit/test_knowledge_migrate_originals_cli.py: the command refuses to move while new originals go to ClickHouse and refuses--namespacewithout--org, both before connecting; a dry run sizes the move before the store is switched, and exits 1 when it lists a refused namespace; and every unconfirmed switch is printed when an error stops the run.-n 8): 27,594 passed. The 4 failures are the four parametrized cases oftest_the_delimiter_is_sniffed_in_bounded_time, a CSV timing bound that fails the same way on main on this loaded host (checked on a detached main checkout); this diff does not touch CSV extraction.make format lint typecheckpass, and so do 2,626 unit tests for package contracts, public copy, doc links, CLI, blobs, object store, RMT write paths, mutations, erasure, alias shadowing and tunable constants. The full unit suite runs on the rebased head before the merge.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 move's order against how an upload writes an original (object first, then row), the race cases in the live test, and a review at every push.
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 (apart from the known timing cases above); 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. (Not applicable: no migration.)hooks/,lib/,bin/,skills/,.mcp.json, the Codexplugin-defaults.json) bumps both plugin manifests' version, and no other open PR uses that version. (Not applicable: no plugin file changes.)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