Repository navigation
A changed document is mined for decisions on the next sync pass - #239
Merged
Merged
Conversation
zlareb1
force-pushed
the
feat/knowledge-source-extract
branch
3 times, most recently
from
November 4, 2026 03:06
af85415 to
4cb2f34
Compare
9 tasks done
zlareb1
force-pushed
the
feat/knowledge-source-extract
branch
3 times, most recently
from
November 4, 2026 04:45
16bb66d to
72d7839
Compare
After every source's turn the knowledge_source_sync pass mines, with decision_extract.extract_document, each of the source's documents whose stored revision is not the one recorded as mined for it in the source's sync state; the revision is recorded only once that document's extraction settled. Rows go to the trunk code namespace as agent loom-decisions under the worker's actor, each write whole with its audit row, and the run stops writing once the pass stops or the source's lease is lost. The leg reads the cap share (knowledge_source_sync_cap_share, fail closed) before each document and the org switch once per pass, waits out holds without counting a try, bills each document's spend to its namespace, stops model reads before the pass's deadline, settles permanent refusals and documents too large for a pass, and gives a document up after three failed tries until it is written again. knowledge.source.list and inspect show the pending count and the last mining turn's counts. Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: zlareb1 <[email protected]>
…rite a cancel left running A lease seen lost by may_write ends that source's turn like LeaseLost from the lease itself, and the leg goes on to the next source; only a stopped pass ends the leg. A document's spend is emitted after the write units it started finish, so a unit a cancel left running is billed in its row. The pass bound inside a turn is the source's reason to wait, and the reason clears once nothing waits. knowledge_source_sync_max_pass_seconds has a floor of 180 s: 90 for the sync, 60 of read time and 30 for the writes. The full-pass read share is its own constant, and reads_stopped names what it checks. Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: zlareb1 <[email protected]>
…write is that source's error extract_document holds its write units in a TaskSet the caller passes (writes=), and finish_writes waits only for those, so the sync worker bills a unit a cancel left running without waiting for, or billing, a concurrent run's. An empty TaskSet is falsy, so the set is compared with None. The cost row is emitted in a finally after the wait. A failed state write for a source that waits, and a failed read of a source's documents, are that source's error and the leg goes on. Comments and the extract help are reworded. Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: zlareb1 <[email protected]>
A recording source's transcript documents are read through store.source_revisions like any other source's, so the leg mines them; a test runs it over a meeting source. The knowledge page says the sync mines transcripts too. Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: zlareb1 <[email protected]>
extract_document passes `writes` to the write and retire steps as it passes may_write, so the context variable and the split of the function are gone. Tests cover a cancelled run's pending unit held in its own set while another run's is still pending, and a failed read of a source's documents as that source's error. Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: zlareb1 <[email protected]>
Sources with nothing to mine and no stale count are left out while the queues are built, the deferred reasons name pass_bound, and the lease comment says a removed source has nothing to record. The pass-budget test runs at the setting's 180 s floor with no share left to start a source, instead of a value the setting refuses. 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-source-extract
branch
from
November 4, 2026 05:15
a018fc3 to
9d7bfc5
Compare
8 of 9 tasks
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):
The document-source sync now mines each document it writes into decision rows in the same pass, as
loom decisions extract --applydoes, withinLOOM_KNOWLEDGE_SOURCE_SYNC_CAP_SHAREof the namespace's daily cost cap.knowledge.source.listandinspectshow each source's pending, mined and given-up documents and the decision rows it taggedsource-changedrather than rewriting them.Why
A synced design document only reaches an agent before an edit once its decisions are rows in the repository's trunk code namespace. Until now an operator had to run
loom decisions extractper document after each change. The sync worker already knows which documents changed, so it runs the same extraction on them: nobody has to remember a command or confirm a row, an unpinned extracted row is served as it is, and a pinned or attested row stays frozen (the extractor's existing rule: taggedsource-changed, never rewritten).Design
source_revision(inloom.documents, read bystore.source_revisions, for every source kind) differs from the revision recorded as mined for it:mined: {source_uri: revision}in the source's sync state (loom.code_index_state,knowledge_source:<name>). The leg writes a revision there only once that document is settled (below), under the namespace's sources lease. A turn that raises, is stopped or is cancelled after writing files records nothing in the map, so the next pass finds those documents unmined. Why the sync state and not the document's metadata: a metadata write is a new document version (re-chunk, re-embed) racing the sync's own writes, while the state row is already the source's, written under its lease. Keyed by address, not file id, since a file that moves address is a new document whose rows cite the new address. Entries for documents no longer the source's are dropped on each write.pending_extractis the reported count.decision_extract.extract_document(org, namespace, uri, dry_run=False, read_deadline=..., may_write=...)under the source's lease,customer.for_org(org, namespace=ns)andpipeline_actor("worker:knowledge-source-sync"). Rows go to the trunk code namespace as agentloom-decisions,source_class=derived,source_resource_idciting the document;decision.recordandmemory.delete_versionaudit rows go throughaudit.emitwith the worker as the actor.decision.recordwith its audit row, or a tags write) and each retire-step row run as one unit throughasyncio.shield, held in the run's ownTaskSet(passed asextract_document(..., writes=)and on through the write and retire steps, a fresh one when none is given; every unit is also registered for shutdown): a cancel never cuts a record from its audit row, and shutdown'sdrain_task_setswaits for an in-flight unit. Before each unit the run asksmay_write, which the worker answers from the source lease'sheldandpass_context.stop_requested(); when it says no the run stops there (report.write_stopped), keeps what it wrote and retires nothing. No unit outlives the lease by more than one record.stop_requested, orPassStoppedfromcheck_stop) and a cancel end the leg with no state written. A lost source lease, seen bymay_writeor asLeaseLostfromcluster_lease, ends that source's turn with nothing recorded and the leg goes on to the next source. A turn that fails with an exception records what it settled first. A failed read of a source's documents, or a failed state write for a source that waits, is that source's error (result.errors,note_failure) and the leg goes on.namespace_over_cap(org, ns, operation="worker.knowledge_source_sync", share=knowledge_source_sync_cap_share, fail_open=False)after flushing the emitter, the conflict resolver's shape. Acustomer.GROUP_HOLDShold pauses its namespace in aHeldregistry forhold_seconds(e); any other hold stops the leg. A hold, on a model read or on an embedding a write needs, is a wait, never a try, and a turn that tried nothing keeps the last mining turn's counts.read_deadline, 30 s before the pass deadline, with nothing written (out_of_time). A document is not started with under 60 s of read time left; the pass counts as cut and the source's reason ispass_bound.knowledge_source_sync_max_pass_secondsnow has a floor of 180: 90 s for the sync, then 60 s of read time and 30 s for the writes.cost_accumulator.begin_op(); itsemit_worker_cost_event_for(org, ns, "worker.knowledge_source_sync")runs in afinallyafterfinish_writes(writes), which waits only for this run's units, so a write unit a cancel left running (its task copied the accumulator's context) is billed in the same row, and a concurrent run (a CLI extraction, say) neither blocks this row nor is billed in it. The pass's own accumulator (the sync's embedding spend in the.passrow) is untouched.extract_documentstops at the firstcustomer.HOLDShold, on a model read or on an embedding a write needs (the restatement search,decision.record), setsreport.heldand retires nothing; before, a held read was a dropped window and a held embedding a refused candidate. It takesread_deadline(report.out_of_time) andmay_write(report.write_stopped), and marks permanent refusals (Dropped.permanent).loom decisions extractexits 1 on a hold._no_model_erroris nowno_model_error.knowledge_source_sync_cap_share(LIVE, default 0.25,(0, 1]), thememory_conflict_resolver_cap_shareshape.Settle rules. A document is settled at its revision, and so not mined again until the sync writes a new one, when:
extract_errorBLACKLISTED,PINNED_CONFLICT,VALIDATION_FAILED)extracted''unextractedwhen given upnot_run,refused,failed:<error>out_of_timeunextractedtoo_large_for_passextract_deferredheld:<code>,held,over_cap,switched_off,switch_unread,no_model,pass_bound; cleared once nothing waitsAlternatives: a separate extraction worker would need its own cursor, lease and status row for work the sync pass already orders and bounds; running the leg inside each source's sync turn would let one source's extraction delay every other source's sync; a list of addresses appended by the sync turn (the first version of this PR) loses a write whenever the turn fails after it; one shielded task per document (the second version) could outlive the lease by a whole document's writes.
Scope and risk
server/knowledge/app/source_sync.py(the leg),server/memory/app/decision_extract.py(holds, the read deadline,may_write, whole write units, permanent refusals), the sync-state wire model, two settings (one new, one floor raised), the CLI help ofloom knowledge syncandloom decisions extract, docs.knowledge.source.add(a namespace admin registered the source). Model calls carry the source's org and namespace. The state row's error is a code (table above); the extractor's messages and document addresses go to the worker log only, andlistshows the pending count, never the mined map.Compatibility, rollout and rollback
KnowledgeSourceSync(inknowledge.source.listandinspect) gainspending_extract,last_extracted_at,extracted,flagged_pinned,unextracted,extract_error. Output only.loom decisions extractexits 1 on a held model call where it used to report dropped windows.LOOM_KNOWLEDGE_SOURCE_SYNC_MAX_PASS_SECONDSbelow 180 is now refused at startup. Otherwise none. The leg runs whereverLOOM_KNOWLEDGE_SOURCE_SYNC_ENABLEDis on and a model is configured, and spends model calls on each changed document;LOOM_KNOWLEDGE_SOURCE_SYNC_CAP_SHAREbounds it.memory.delete); the extra state keys are ignored.Tests
tests/unit/test_knowledge_source_sync.py:LeaseLost(the lease's loss cancelling the body),PassStoppedfromcheck_stopin the leg and a cancel during_minewrite no state and are mined next pass; a lease lost mid-write ends that source and the leg goes on to the next; a stopped pass ends the leg with nothing recorded;OverloadedErrorfrom the sources lease) and a failed read of a source's documents are that source's error (errors,failed,note_failure), and the next source is still mined;too_large_for_pass, with less it goes first next pass; the time floor; a document no longer the source's leaves the map; the shared pass bound;sync_ofshows the count, never the map.tests/unit/test_knowledge_source_sync_linear.pyandtests/unit/test_knowledge_source_recordings.py: a project's documents and a meeting's transcript are mined by the same leg (every kind's documents are read throughstore.source_revisions).tests/unit/test_decision_extract.py: a held model read stops the run before any write; a hold on a write's embedding (ModelCallsDisabled,ModelCallRefused) is a hold, not a refused candidate; a hold on a later write keeps the record already written with its audit row and retires nothing;may_writeturning false stops after the current record with no audit gap; a cancelled run finishes its current write anddrain_task_setscovers it; a cancelled run's pending unit stays in its own set andfinish_writeson it completes while another run's unit is still pending; a read deadline passed mid-read writes nothing and no audit row; a blacklisted candidate is a permanent refusal; the worker's writes are audited as the worker.tests/integration/test_knowledge_sources.py, private ClickHouse and server, auth off, fake providers): a seeded source over a mocked folder store syncs one document and mines it into onedecisionrow in the trunk namespace (agentloom-decisions, actorworker:knowledge-source-sync,derived, confidence 0.5, unpinned,source_resource_id=knowledge:<ns>/<uri>#<section>), onedecision.recordaudit row with the worker actor,listshowingextracted: 1, and nothing mined on the next pass. The folder store's responses are written in the test; no vendor credential or real content is used. Withtest_decision_extract_repo.pyandtest_decision_record_source.py: 18 passed on the head rebased after Uploaded files are ingested: the extractor service extracts them and a job publishes the next revision #229 and A recording source syncs a meeting's transcript as timestamped sections #248.make format lint typecheck;sdk_py_gen,sdk_py_client_gen,sdk_ts_gen,docs_reference,op_reach_census,settings_reference,settings_schema,settings_example; the LIVE, defaults and CLI snapshots; the full unit suite (26673 passed, 20 skipped, 1 xfailed) on72d78398e; the last head,a018fc39e, changes comments, the queue filter and one test's setup, and its touched tests 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; checked against the sync and extractor code paths and the tests above.
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).main; no merged migration is edited.hooks/,lib/,bin/,skills/,.mcp.json, the Codexplugin-defaults.json) bumps both plugin manifests' version, and no other open PR uses that version.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