Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
dba6573
Owner-only snapshot and selected-refresh worker sources keep a privat…
zlareb1 Dec 4, 2026
852d620
Merge remote-tracking branch 'origin/main' into feat/mcp-worker-store…
zlareb1 Dec 4, 2026
bb02ac0
Worker copies sync in the workers process and retire only on the work…
zlareb1 Dec 4, 2026
7437654
A worker copy is retired only on the worker's named upstream denial
zlareb1 Dec 4, 2026
068feb6
Only the upstream's 403 to the read itself names an upstream access d…
zlareb1 Dec 4, 2026
7a38e9c
State that an access check confirms access only, and simplify two checks
zlareb1 Dec 4, 2026
4b219f4
A worker copy unconfirmed for the whole stale window is retired
zlareb1 Dec 4, 2026
d6320c3
Retire an unconfirmable worker copy before its confirmation lapses
zlareb1 Dec 4, 2026
09c75e6
A timeout never retires a worker copy; an unsupported one needs a con…
zlareb1 Dec 4, 2026
8a90bc6
A worker turn a refusal ended retires no lapsing copy
zlareb1 Dec 4, 2026
d648a30
Merge remote-tracking branch 'origin/main' into feat/mcp-worker-store…
zlareb1 Dec 4, 2026
9efd67f
Say an older worker never causes a retirement on a denial, and order …
zlareb1 Dec 4, 2026
7c4e18b
A resource whose refusal ends a worker turn goes last, and copy check…
zlareb1 Dec 4, 2026
998ff75
A plain worker denial also sends its copy last next time
zlareb1 Dec 4, 2026
0fcf51b
Each worker copy request reads the owner's whole standing, and drop t…
zlareb1 Dec 4, 2026
68772fd
Say interval_seconds is refused outside selected_refresh, and rewrap …
zlareb1 Dec 4, 2026
a7df63d
State the worker copy capacity bound, and send each refusal to its ow…
zlareb1 Dec 4, 2026
001a636
Merge remote-tracking branch 'origin/main' into feat/mcp-worker-store…
zlareb1 Dec 4, 2026
62055a4
A worker turn out of time before its listing marks pass bound reached
zlareb1 Dec 4, 2026
8e02d62
Mark a refresh the document bound holds back, and keep one retry rule
zlareb1 Dec 5, 2026
fb7fa2d
A refresh the document bound holds back is checked only when its chec…
zlareb1 Dec 5, 2026
c417ca3
Merge remote-tracking branch 'origin/main' into feat/mcp-worker-store…
zlareb1 Dec 5, 2026
cd1cf33
Merge remote-tracking branch 'origin/main' into feat/mcp-worker-store…
zlareb1 Dec 5, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 10 additions & 11 deletions docs/architecture/document-sources.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,18 +42,15 @@ its source lease, clearing their credentials, as `code.repo.remove` does today,
source outlives its namespace with a sealed credential or writes back what an erasure
took. A worker source registration goes inactive with its config and items unchanged,
its credentials cleared, as are a crawl row's selected addresses, approval and
registrant, and no queued cleanup. Native mirror retirement finds a source's copies by
the sync worker's actor and the source's `source-id` tag, which a worker's copies need
not carry, so it cannot find them. A namespace erasure still purges every mirror the
namespace has had, worker copies included; after `namespace.delete`, `collection.delete`
or `code.repo.remove`, which retire sources without erasing, copies a later build wrote
for a worker source stay until a build with worker cleanup removes them.
registrant, and its copies queued for retirement like a mirrored source's: they carry
the sync worker's actor and the source's `source-id` tag, which mirror retirement finds
them by ([stored copies](mcp-source-worker-boundary.md#stored-copies-and-refresh)). A
namespace erasure purges every mirror the namespace has had, worker copies included.

`knowledge.source.remove` removes a worker source as namespace retirement does: its
owner, with the writer role, or the namespace's administrator writes it inactive, its
credentials cleared, its stored registration kept and nothing queued, and answers
`documents_pending` 0 even with `delete_documents`: this build writes no worker copy,
and copies a later build wrote stay until that build's cleanup removes them.
credentials cleared, its stored registration kept and its copies queued for retirement,
and answers `documents_pending` 0, as for any mirrored source.
`knowledge.source.check`, `update`, `rotate`, `sync_now`, `push_configure`,
`push_status` and `push_confirm` refuse a worker source with `SOURCE_WORKER_OWNED`,
which does not clear on retry, and `add` refuses the name of a removed one the same way.
Expand Down Expand Up @@ -1376,8 +1373,10 @@ statements and census keys against these, and its tests pin each one:
an owner with no revocation keeps every row. A registration's `created_at` is taken
before its last caller check, so a cutoff that lands after that check reaches its row.
A team reader's link to an erased source is the reader's row: it names only the opaque
source id and stays until the reader's own deletion or the namespace's erasure. The
source has no sync state to erase, since no build syncs a worker source.
source id and stays until the reader's own deletion or the namespace's erasure. Before
it deletes a namespace's worker rows, owner erasure queues each registration's copies
for the mirror retirement worker, as it does for a connected source; a copied source's
sync state lives under the mirror, which the namespace's erasure takes.
`knowledge.source.worker_register` creates active worker rows
([source registration](mcp-source-worker-boundary.md#source-registration)), which hold
no credential; every other writer writes a worker row only inactive, clearing its
Expand Down
142 changes: 124 additions & 18 deletions docs/architecture/mcp-source-worker-boundary.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,19 +13,21 @@ receives the result controls what it retains.

The source worker owns upstream credentials, outbound MCP requests and account
consent. Loom owns source configuration, access policy and the erasure of what it
stores; this build keeps no worker copies and schedules no worker refresh. Loom
stores opaque worker and connection identifiers, their generations and the approved
profile digest. The worker resolves the connection within its own credential
authority. Neither side uses the other side's credential at the upstream endpoint.
stores, an owner-only source's private copy included ([Stored copies and
refresh](#stored-copies-and-refresh)). Loom stores opaque worker and connection
identifiers, their generations and the approved profile digest. The worker resolves the
connection within its own credential authority. Neither side uses the other side's
credential at the upstream endpoint.

This build serves the live read, the collection approval operations described in
[Collection approvals](#collection-approvals), the account link described in
[Account enrollment](#account-enrollment) and the registration of an owner-only live
source described in [Source registration](#source-registration). No operation links a
team reader or registers a snapshot or selected-refresh source; the checks those need
ship uncalled, and this page describes what they require. A write to an approval,
account or team link row locks that row, which the frame fence locks shared, so a
revocation that commits before a frame's handoff withholds that frame.
[Account enrollment](#account-enrollment), the registration of an owner-only source
described in [Source registration](#source-registration) and, while
`LOOM_KNOWLEDGE_SOURCE_WORKER_COPIES_ENABLED` is on, the private copy of an owner-only
snapshot or selected-refresh source. No operation links a team reader; the checks a team
reader needs ship uncalled, and this page describes what they require. A write to an
approval, account or team link row locks that row, which the frame fence locks shared,
so a revocation that commits before a frame's handoff withholds that frame.

The selection proof asks the worker's `/v1/check-access` for each selected identity
through the owner's own connection; the worker answers the digest of what it read, never
Expand All @@ -52,9 +54,10 @@ worker](../../source_worker/README.md#running-the-companion)).

A stored-copy confirmation resolves the read with the `stored` purpose, which accepts
only a snapshot or selected-refresh registration and looks up the collection approval by
that registration's mode. The worker's digest must match the stored revision, which must
not change during the check. The evidence carries Loom's own clock time, not the
worker's `fetched_at`, and expires within its bounded lifetime.
that registration's mode. It confirms the owner's access only: the worker's digest is
not compared with the stored copy's, so a changed resource keeps its copy until the copy
is due again. The evidence carries Loom's own clock time, not the worker's `fetched_at`,
and expires within its bounded lifetime.

## Worker provisioning

Expand Down Expand Up @@ -311,9 +314,11 @@ audit row records the caller. Its owner or the namespace's administrator removes
`knowledge.source.remove`, namespace retirement writes it inactive, and its owner's
erasure deletes it ([document sources](document-sources.md#erasure-and-audit)).

Only `live` is registered, with the `owner_only` reader policy: a snapshot or a selected
refresh needs a stored copy and its refresh, and team access a linked team reader,
neither of which ships, so each answers `unavailable`. Both operations answer one
Every registration has the `owner_only` reader policy: team access needs a linked team
reader, which no operation makes, so it answers `unavailable`. A `snapshot` or
`selected_refresh` registration, the latter with its `interval_seconds` (300 to 86400),
answers `unavailable` too unless `LOOM_KNOWLEDGE_SOURCE_WORKER_COPIES_ENABLED` is on,
since only then does the sync keep its copy. Both operations answer one
`status`. The caller check of [Collection approvals](#collection-approvals) at the
writer role runs first; `denied` covers its refusal, an account the caller has not
linked there, an erasure that may still reach the collection and a proof the worker
Expand Down Expand Up @@ -379,5 +384,106 @@ follows that ownership:

## Stored copies and refresh

Worker copies, refresh and retirement are not built: no store this page lists accepts a
worker copy.
While `LOOM_KNOWLEDGE_SOURCE_WORKER_COPIES_ENABLED` is on, the sync worker keeps a
private copy of each active, unpaused, owner-only `snapshot` or `selected_refresh`
source in its collection's mirror (`source_sync_worker`), inside the same private scope
as a connected source's turn. A copy is a document at the resource's address
(`mcp_identity.resource_uri`), written by the sync actor with the source's `source-id`
tag and a permission list naming the owner alone; its metadata carries the worker's
`content_sha256` and revision.

A turn reads the collection's current approval of the registration's mode and the
owner's worker account at the registered generation first; one that no longer matches
ends the registration (below). It then needs the owner's standing: an active directory
account, no revocation since the registration, and a writer grant in the collection.
Each worker request resolves that authority again as a live read does (`CurrentRead`
with the `stored` purpose), with the owner as requester: before a copy request and after
its reply, and for an access check also just before it is sent. A resource with no copy,
or a selected-refresh one whose interval has passed, is read through the worker's live
path; a reply with the stored digest writes nothing. A process's turns run one after
another, so it has at most one copy in flight, in a channel share of one request per
worker that Loom's live reads never wait on. That share guards only Loom's own channel
slots: on the worker, a copy and a live read take the same `read_limits.concurrent` and
`concurrent_per_org` slots, so on a small worker a copy in flight can make a live read
answer `overloaded`. Every other copy whose access was last confirmed more than half of
`knowledge_source_acl_stale_seconds` ago is checked with `/v1/check-access`, which
returns the digest only. Resources without a copy go first, then the stored copies by
oldest confirmation. Copies count against the pass's mirror document bound; checks count
against its time alone, so a worker source's turn still starts once other mirrored
sources have used up the bound, and only its due copies wait for a pass with room. A
copy's address is fixed by its source ID and its resource, and a registration's
selection never changes, so every stored copy belongs to a selected resource.

Capacity: a process sends its copies and checks one at a time, within the mirrored phase
of each `knowledge_source_sync` pass, which native mirrored sources share. Every stored
copy needs a check every half of `knowledge_source_acl_stale_seconds`, so the copies one
deployment keeps served are bounded by the mirrored phase time in that window divided by
one check's time (Loom's authority reads and the worker's upstream session). Past that
bound the oldest listings lapse and those copies stop being served, which fails closed;
a turn the bound cuts reads `pass bound reached`, and a source the phase does not reach
keeps its last state. A `selected_refresh` copy is read again at most once a pass and
spends the mirror document bound even when its digest is unchanged, so
`interval_seconds` is the least time between copies, not a schedule. This feature is
experimental and off by default.

Of the worker's answers, only its report that the upstream refused the account retires a
copy at once: a `403` whose body is exactly
`{"status": "denied", "reason": "upstream_access"}`, read whole within 256 bytes, which
the worker sends only for the upstream's own HTTP 403 to the resource request itself,
the `resources/read` or the mapped read's `tools/call`
([source worker responses](../../source_worker/README.md#responses)); a 403 to
`initialize`, tool discovery, the GET stream or the closing `DELETE` stays a plain
`denied`. Even then the registration, the owner's standing, the approval and the worker
account are read again and must still hold. Any other `denied` ends the turn with every
copy kept: a grant the worker refused (a rotated or mismatched grant key, a clock
outside the grant's lifetime), Loom's own check of authority that changed during the
turn, or a reply that failed validation. A worker build that names no reason never
causes a retirement on a denial; its copies stop being served once their access goes
unconfirmed past the stale window. A copy answering `unsupported` follows the lapsing
rule below with either build. `reconnect`, `overloaded` and `unavailable` end the turn
and keep every copy, and a stored copy whose request keeps ending turns keeps every copy
of the source unserved until it answers or the source is removed, which fails closed;
`timeout` and `unsupported` keep that resource's copy and let the turn go on. A
`timeout` may be the upstream's or the worker's, so it never retires a copy. A stored
copy that answers `unsupported` once its confirmation would lapse before the next pass
(older than `knowledge_source_acl_stale_seconds` less
`knowledge_source_sync_interval_seconds`; only a copy whose check fell due can have a
peer confirmed since, so none goes before half the window) is retired before it can hold
back the listing of the others, its state noting `copy_unconfirmable`, but only when
another copy was confirmed after its own check fell due, which shows the failure is the
resource's, and with the registration and the owner's authority read again and still
holding, in a turn no other refusal ended. Removal, namespace retirement, owner erasure
and the end of a registration (below) also retire every copy of the source. A resource
left without a copy, denied by the upstream or unsupported, is read again only after its
refresh interval or, for a snapshot, half of `knowledge_source_acl_stale_seconds`; one
that timed out, or whose refusal ended the turn, after half of
`knowledge_source_acl_stale_seconds`. The mirror read gate needs a listing no older than
`knowledge_source_acl_stale_seconds`, and the turn records the listing at the oldest
confirmation among the stored copies, so a copy whose access was not confirmed in that
window stops every copy of the source being served until it is confirmed or retired.
Nothing confirms a copy while the owner's standing, the approval or the worker account
fails, so they fail closed together.

An approval or worker account read that no longer matches the registration (the
collection's approval at another generation or gone, the owner's worker account
inactive or at another generation) ends the registration, since nothing restores that
generation: under the namespace's source lease, once a read there confirms it, the row
goes inactive, its copies are queued for retirement and its sync state reads
`owner_inactive`, as for a connected source whose owner left
(`source_sync_connected.ensure_current`). A read that fails, a routes file that does not
provision the profile in that process, and a lost writer grant or directory standing
keep the registration and every copy, unserved once the stale window passes.

The mirror read gate admits a worker source's copies to its owner alone: the latest row
of the name must be the same registration the request first read, still copied, the
reader's own sign-in subject must be its owner with the viewer role, and the approval
and the owner's worker account must be current. Any other reader, a changed registration
or a failed check admits no copy. While copies are on, the gate's registration read
returns only worker rows whose stored registration names an owner-only copy mode, so a
live worker source costs a reader nothing.

`knowledge.source.remove`, namespace retirement and owner erasure queue the source's
copies for the `knowledge_source_retire` worker before its row goes inactive or is
deleted; that worker deletes them as it deletes a mirrored folder source's copies, and
an active row of the same source ID stops it. A namespace erasure purges the mirror with
every copy in it.
25 changes: 25 additions & 0 deletions docs/architecture/rolling-upgrades.md
Original file line number Diff line number Diff line change
Expand Up @@ -1167,6 +1167,31 @@ See the [participant lifecycle baseline](cells.md#participant-lifecycle-baseline
rollout. `tests/unit/test_run_ledger.py` and `tests/unit/test_mcp_session_runs.py`
check N's side, and the mixed-version gate does not check this rule.

77. **Worker copies** (`knowledge_source_worker_copies_enabled`, no migration): with the
setting on, N registers owner-only `snapshot` and `selected_refresh` worker sources,
syncs their copies into the collection's mirror, serves those copies to the owner
and queues their retirement on `knowledge.source.remove`, namespace retirement and
owner erasure. N-1 registers no such source, its sync worker and mirror reads skip
every worker row, its `knowledge.source.live` refuses a non-live registration, and
its removal paths queue no worker copy. So the operator turns the setting on only
once every replica runs N; it is off by default, so the rollout itself writes no
copy. Whatever the setting, N's `knowledge.source.remove` and namespace retirement
queue a worker source's copies and write its inactive row with `pending_delete`,
since a copy written while the setting was on outlives turning it off. With no copy
the entry finds nothing to delete: N clears it, and N-1's retirement worker leaves
it pending, since it still counts an inactive worker row as blocking. A rollback to
N-1 leaves the copies in the mirror, unserved, and an owner erased or a source
removed under N-1 queues none of them: before rolling back, remove every snapshot
and selected-refresh worker source with N and let the `knowledge_source_retire`
worker drain. A source worker build older than N's names no reason on its `403`, so
N never retires a copy on its denial, and an N-1 Loom ignores the reason N's worker
adds: a refused resource's copy is kept and its source's copies stop being served
after the stale window, until a worker that names the reason answers. A copy
answering `unsupported` follows the
[lapsing rule](mcp-source-worker-boundary.md#stored-copies-and-refresh) with either
worker build. No gate holds the rollout. `tests/unit/test_worker_source_copies.py`
checks N's side, and the mixed-version gate does not check this rule.

## What checks them

`scripts/gates/mixed_version.py` (`make test-mixed-version`, the `mixed-version` CI job,
Expand Down
9 changes: 4 additions & 5 deletions docs/features/knowledge.md
Original file line number Diff line number Diff line change
Expand Up @@ -326,11 +326,10 @@ A removed source's row stays, inactive and with its credential cleared. With
document is counted yet (a sync turn running at that moment may still write one); the
worker clears it once none is left. A worker source's owner, with the writer role, or
the namespace's administrator removes it the same way; it keeps its stored registration,
and `delete_documents` queues nothing and counts no documents: this build writes no
worker copy, and copies a later build wrote stay until that build's cleanup removes
them. Removing a repository (`code.repo.remove`) retires the sources registered on its
namespace the same way and names them in `sources_deactivated`; the purge of the
repository's code index that follows deletes their sync state (it lives in
and its copies are queued for retirement whatever `delete_documents` says, uncounted, as
for any mirrored source. Removing a repository (`code.repo.remove`) retires the sources
registered on its namespace the same way and names them in `sources_deactivated`; the
purge of the repository's code index that follows deletes their sync state (it lives in
`loom.code_index_state`) and the namespace's documents, and leaves the inactive source
rows. An `add` that probed while the repository was being removed answers
`NAMESPACE_INACTIVE`, or, when it lands before the namespace is deleted, is retired with
Expand Down
Loading
Loading