Repository navigation
Uploaded files are ingested: the extractor service extracts them and a job publishes the next revision - #229
Merged
Merged
Conversation
zlareb1
force-pushed
the
feat/knowledge-ingest-jobs
branch
14 times, most recently
from
November 4, 2026 02:40
1b602ed to
89c13a9
Compare
…r service, publish it as a document revision Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: zlareb1 <[email protected]>
… row ends published, fence a later text write 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]>
…source; the retry delay stops at an hour Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: zlareb1 <[email protected]>
…hing; count the job's own chunks Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: zlareb1 <[email protected]>
…its does not fail it Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: zlareb1 <[email protected]>
…ry keeps its chunk version Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: zlareb1 <[email protected]>
…blished only with live chunks, else publish again Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: zlareb1 <[email protected]>
… or text write after its publish stands Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: zlareb1 <[email protected]>
…uld; re-read the job before the document row Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: zlareb1 <[email protected]>
… run like a timeout Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: zlareb1 <[email protected]>
…e row Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: zlareb1 <[email protected]>
…er version first, own row included Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: zlareb1 <[email protected]>
… slots is transient Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: zlareb1 <[email protected]>
…it makes unreachable; typed 429s on upload Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: zlareb1 <[email protected]>
…s past the insert's bound Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: zlareb1 <[email protected]>
…t (Lease.let_expire) Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: zlareb1 <[email protected]>
…test that it sits inside the claim Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: zlareb1 <[email protected]>
…s TTL 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-ingest-jobs
branch
from
November 4, 2026 03:09
2e5095f to
8f85566
Compare
This was referenced Nov 4, 2026
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):
A file can be uploaded (
POST /v1/knowledge.upload) and ingested (knowledge.ingest,knowledge.ingest_status,knowledge.ingest_cancel): a background job sends the original to the document extractor service, checks what it returns, and publishes the next revision of the source with chunks that cite their lines, keys and sections. The server parses no file itself.Why
knowledge.addtakes text the caller already extracted. The previous steps of the related issue added the extractor service and its wire contract (the server sends bytes, gets an artifact back and checks it as untrusted input) and its image beside the server; nothing called it. This adds the path that does: a stored upload, a job that extracts, chunks, embeds and publishes it, and revisions of a source so a re-ingest replaces the earlier one only once it is complete.Scope and risk
server/knowledge/app/upload_routes.py):POST /v1/knowledge.upload?org=&namespace=&filename=with the file as the raw body (writer role;sha256=andcontent_type=optional), admitted as an op is (after authorization it drawsknowledge.add's rate-limit buckets and holds one of the org's in-flight slots). The authorship helpers inwrites.pybecome public (authorship,authorship_of), since the upload route and the ingest ops use them. The in-flight counter and the fail-open counter move fromserver/transport/gates.pytoserver/core/tenant_slots.pyandserver/core/fail_open.py, so a route below the transport shares them; a limiter that fails admits the upload and is counted and logged as an op's is. Its 429s are raised asRateLimitedError, so they carryRetry-Afterandretry_after_sas an op's do. An upload is drawn as interactive traffic: it is not classified as an op is. The body is copied tobytesonce (the ClickHouse client writes onlybytesinto a String column), so an upload holds up to twice its size while it is stored, and the org's in-flight slots bound how many do. The request-body cap (LOOM_MAX_REQUEST_BYTES) passes this one path through, since the route streams the body against its own limit and refuses one that ends before itsContent-Length. The file is stored as an original (in ClickHouse or the document bucket, asLOOM_DOCUMENT_OBJECT_STOREsays) and recorded inloom.knowledge_uploadswith a scopedupload_idandexpires_at(LOOM_KNOWLEDGE_UPLOAD_TTL_SECONDS, a day). OverLOOM_KNOWLEDGE_UPLOAD_MAX_BYTES(64 MiB) is413, a wrongsha256422 CHECKSUM_MISMATCH, a legacy Office name415 UNSUPPORTED_FILE, all before anything is stored. The format comes from the file name and media type (server.core.document_formats.format_of); the server does not read the bytes to type them, so content that is another format is refused by the extractor at ingest (format_mismatch).server/knowledge/app/ingest.py,ingest_run.py, workerknowledge_ingest,loom.knowledge_ingestions):knowledge.ingestnames an upload the caller made in the same namespace and thesource_urito publish under (title, description, tags, metadata as forknowledge.add; optionsformat,encoding,sql_dialect;expected_revision;allow_partial) and answers a pending job. A pass of the worker runs one job (so it has the whole pass deadline,LOOM_KNOWLEDGE_INGEST_MAX_PASS_SECONDS, 15 minutes), one source's jobs one at a time in the order asked (only the oldest open job of a source is offered, so a later ingest of it waits while an earlier one runs, and a job a crashed pass leftprocessingruns again before any later one of its source), and namespaces in turn (each offers one due job, a stale processing one first, and the namespace served longest ago goes first), so one namespace's backlog does not hold up every other's. The job is taken under a deployment-wide lease on its id, then:blobs.locate, thenblobs.read) and sends the bytes to the extractor its format is routed to throughserver/knowledge/app/extractors.py, which checks the artifact; stores the artifact JSON as an original of its own;knowledge.addgives its chunks (chunk_context: title, description, section breadcrumb), and reuses the stored vector of every embedding input this namespace already embedded under the same model;doc_version) and inserts the chunks; then, under the source's claim, checks a cancel andexpected_revisionagain, writes the document row (revision, format, artifact, parser, coverage) and retires the earlier version's chunks. The claim covers those few statements only, so its time limits hold for a source atLOOM_KNOWLEDGE_INGEST_MAX_CHUNKS.Every slow step runs before anything is published, so a failed or cancelled job leaves the earlier revision serving. The job row records the chunk version a publish inserts before its document row (
doc_version); when a run stops between the two, those chunks are retired before the job goes back to pending or ends, or by its next run after a crash, so a pending or ended job leaves none live, except a job stopped at an uncertain document insert, whose chunks stay live until its next run settles it. An erasure that lands after the chunk insert stops the document row (the job's row is read again first); chunk rows inserted after the erasure's delete are left to the residue census, which fails the saga closed. The document row names the job that wrote it (ingestion_id, which a metadata edit and a delete keep), and a rerun looks for any version row of the source naming it (documents.revision_by_ingestion, read without FINAL, so a text write since does not hide it; a run that stopped mid-publish (stillprocessingat the publish stage, saved with its chunk version), when a later write of the source has landed since and the job's row is not found because a merge may have folded it away, failsrevision_conflictinstead of perhaps publishing its older file over that write; a job a retry put back to pending is not judged so). A document insert that fails transiently (a client-side timeout, or the source claim's deadline cutting it off) may still land, so the run stops there as a crash would: the job staysprocessingat its publish stage with its chunks live, a cancel of it answersprocessing, and the run leaves the job's lease to expire rather than release it (a newLease.let_expire: stop renewing, keep the key), and a pass deadline or shutdown that cancels the run with the insert in flight does the same. The run's lastlease.heldcheck is inside the source claim's block (the lease renewed within 60 s before it), and the send comes within that block's 24 s bound of the check, so no worker can take the job until at least 36 s after the send, judged on the server's clock; the insert's own bound is 29 s (a carried send may start up to 15 s after it was sent, run 9 s under the source claim, and commit within 5 s more), so by then it has landed or been stopped; the next run finishes it published when its row landed, whatever was written after it (a delete stays a delete, a text write stands), and otherwise retires the chunks before it publishes or fails, so a rerun of a job that published (it stopped before its last save) finishes without publishing again, retiring the chunks it published, or bringing back a document deleted since; it retires the earlier revision's chunks in case the first run stopped before it did, and it is checked before a cancel, so a published revision is reported as published. A failure of any kind after this run's own document insert returned (the retire of the earlier chunks, the claim's release), on any attempt, ends the job published rather than failed or pending; a failure before it retires the run's own chunks. The run knows which from its own steps; only a run that crashed is judged from the stored rows.knowledge.ingest_cancelwrites a row of its own inloom.knowledge_ingest_cancels, never a version of the job's row, which only the worker holding the job's lease writes (a version built from the caller's read would replace what the worker saved after it). The op reads the job again after writing the cancel: still pending, no worker has started it, so it answerscancelled, and the status op reports a pending job with a cancel ascancelled; the worker that takes it ends it without running it. A running job reads the cancel before its chunk insert and under the claim before the document row. A run cut off at the pass deadline, or by a stopped process, writes no failure, so a job whose attempts are spent failsretries_exhaustedbefore it extracts again.ExtractionFailed) fails the job at once with the extractor's code (format_mismatch,encoding,corrupt, ...). A format no configured extractor takes (none routed, the service does not declare it, or it answersformat_unavailable) is a newFormatUnavailable, a subclass ofExtractorUnavailable, and fails the job withformat_unavailable, since retrying does not change a deployment's extractors. An artifact that breaks the contract fails the job at once (invalid_artifact), as does a4xxwith no contract code (refused). An extractor that cannot be reached, times out, or answers a status that is neither a result nor a refusal (ExtractorUnavailable), and store and provider outages (a store down, past its deadline or out of slots:BACKEND_NOT_NOW), put the job back with a doubling delay (at most an hour) untilLOOM_KNOWLEDGE_INGEST_MAX_ATTEMPTS(retries_exhausted). Other codes:incomplete_extraction(unlessallow_partial),no_text,too_large(more thanLOOM_KNOWLEDGE_INGEST_MAX_CHUNKS),revision_conflict,original_gone,cancelled,internal.knowledge.add,upsert,bulk_add,ingest) numbers the next revision, one past the latest, deleted or not. Ingests of a source publish under its claim, one at a time, soexpected_revisionguards an ingest against another (0 expects no live document, so it also refuses a live document still at revision 0: one written before this change or by an older build); text writes take no claim (as before), so a text write racing another write of the same source can reuse a revision number and the later version row wins; an ingest whose document row a later write of the source (a text write, a metadata edit or a delete) would outrank failsrevision_conflictinstead of reporting a revision no reader sees. Taking the claim on text writes too means moving their embedding and original upload out of the claimed section, which is left for a follow-up. Document rows gainrevision,format,parser,coverage,artifact_sha256and theingestion_idthat published them; chunk rows gainkeys(the exact names a block defines or reads) andembed_input_sha256(what the reuse matches on).knowledge.getreturns the new document fields.knowledge.update_metadatawithreindex=truerefuses an ingested document (422): its chunks come from the artifact, and re-cutting the rendered text would make it a text document; ingesting it again re-indexes it.expires_at, a job's 30 days after its last change). The blob sweep keeps an original a live upload or job still holds (HELD_SQL).knowledge_upload_max_bytes(live),knowledge_upload_ttl_seconds,knowledge_ingest_enabled,knowledge_ingest_interval_seconds,knowledge_ingest_idle_interval_seconds,knowledge_ingest_max_pass_seconds,knowledge_ingest_max_attempts,knowledge_ingest_max_chunks(live).082_knowledge_ingestion.sql: three new tables (uploads, jobs, cancels), the new document and chunk columns, all additive with defaults, and bloom-filter skip indexes on the chunks'keysandembed_input_sha256(the vector-reuse lookup).Search, outline and synthesis read the published chunks as they read any document's; the revision-qualified citations and the structural search filters are the next step.
Compatibility, rollout and rollback
knowledge.ingest,knowledge.ingest_status,knowledge.ingest_cancel), one new HTTP route (POST /v1/knowledge.upload), new optional output fields onknowledge.get(revision,format,parser,coverage). No field is removed or changed.LOOM_DOCUMENT_EXTRACTOR_URLandLOOM_DOCUMENT_EXTRACTOR_TOKEN, or every job failsformat_unavailable.loom.documentsis now carried (rmt_carry, rule 2), which protects later upgrades but not this one: an N-1knowledge.update_metadataordeleteof a document N ingested writes a version row without the new columns, so that document'srevisionreads 0 and itsformat,parser,coverageandartifact_sha256empty until it is written again, and the sweep may collect its artifact (a re-ingest stores it again). Nothing N-1 serves ingests, so this touches only documents ingested during the rollout window and edited by an N-1 replica before it is replaced. While an N-1 process holds the originals sweep's lease, the sweep knows neither the upload and job holds norartifact_sha256: an upload that waits longer than the sweep's minimum age (an hour) for an N worker can be collected, and its job failsoriginal_gone(upload it again).Tests
tests/unit/test_knowledge_ingest.py(68),test_leases.py(a lease left to expire keeps its key): the reference extractor served in process (httpx.ASGITransport), the stores faked; ingest naming its upload, options and authorship; a job publishing chunks, then the document, then retiring older versions; the artifact stored and the text rendered from it; a second ingest the next revision reusing identical vectors; each failure code; an unreachable extractor leaving the job pending withretrying; a job erased mid-run, a lost lease and a crash after publishing each leaving nothing half-written; a publish that fails after its chunks retiring them, when the job fails and when it goes back to pending (a cancel of that pending job leaves none live); a rerun after its document row retiring the earlier revision's chunks;expected_revision=0refusing a live document at revision 0; a cancel writing no version of the job; a job that published ending ready after a later cancel; a rerun of a published job after a metadata edit or a delete keeping its chunks and publishing nothing more; a failure after the document row ending the job published on the last attempt and before it; an ingest a later write overtook failingrevision_conflictand retiring its chunks; a rerun of a published job after a text write publishing nothing more, with its own row still there (ready) or merged away (revision_conflict); a document deleted after a late-landing insert staying deleted, with the job's own row merged away or not; a document insert cut off by the source claim's deadline stopping the run like a timeout; the lease left to expire after an uncertain insert or a cancel mid-insert, and the earliest takeover outlasting the insert's bound; a lease lost once the claim is taken stopping the publish before its document row; a store out of slots putting the job back; a cancel after an uncertain insert answeringprocessingand the job ending published once its row landed; an erasure between the chunk insert and the document row writing no document row; the test fakes retiring every chunk version a publish, a text write or a delete retires; a retry publishing over a metadata edit that landed while it waited; a document insert that timed out keeping its chunks, then ending the job published (its own chunks live) when the row landed or failed and retired when it did not; the retry delay stopping at an hour; a job whose runs never finished failingretries_exhaustedbefore it extracts again; a pass running one job and passing over one another process holds; the worker's settings; an upload named by its name without reading the bytes, stored whole above the request-body cap, refused 429 at the org's in-flight cap or rate limit, admitted and counted when the limiter fails;reindexof an ingested document refused.test_body_limit.py: a path that bounds its own body passes through.test_knowledge_extractors.py:FormatUnavailablefor an undeclared format. Erasure order, census, schema baseline, RMT write paths, read-scope admission, SDK surface and settings snapshots updated.pytest tests/uniton the rebased tree (after the sources and erasure-actor changes took migrations 080 and 081, so this one is now 082): 26,277 passed, 20 skipped, 1 xfailed; the affected tests again at this head (knowledge, ingest, erasure, census, schema, generators, the document-source sync): 4,992 passed, and after the last change 2,068 focused (ingest, erasure, leases, claims, admission) (one host-load timing failure,test_workers_child.py::test_the_child_dies_with_its_parent, fails the same on main here and is untouched by this change), andtests/analyzer12 passed. An earlier run found 4 failures from this branch, since fixed: the job stage names the LLM-stage scan read as stages, a SELECT alias shadowing a filtered column, the SDK surface snapshot, and settings no test named.tests/integration/test_knowledge_ingest_queue.pyon a real ClickHouse: two namespaces' due jobs, the one with a backlog offering only its oldest and going after the other; one source's later job not offered while the earlier one runs, and the earlier one offered first once it is stale.python -m loom_extractor):test_knowledge_ingest_live.py(now with a cancelled pending job read as cancelled over HTTP and ended by the worker) andtest_erasure_user_originals_shared.py,test_knowledge_ingest_queue.pyandtest_knowledge_sources.pyrerun after the rebase (9 passed, 6 skipped);pytest tests/integration -k "knowledge or document or erasure or ingest or blob or upload"135 passed, 44 skipped (settings this server does not set). The store's upload, job and cancel reads checked against the same ClickHouse.make format,make lint(generators current),make typecheck: 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.
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.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).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