Repository navigation
Owner-only snapshot and selected-refresh worker sources keep a private copy in the mirror - #2165
Conversation
…e copy in the mirror With knowledge_source_worker_copies_enabled on, a collection writer can register an owner-only snapshot or selected_refresh worker source (the latter with a new interval_seconds field). The sync worker keeps its copy in the collection's mirror: each turn copies a resource that has no copy or whose refresh interval passed through a new copy share of the worker channel, checks the rest with check-access once their confirmation is half the ACL stale window old, retires a copy the worker denies, and records the listing at the oldest confirmation of the stored copies, so an unconfirmed copy stops being served within the stale window. The mirror read gate admits a worker source's copies to its owner alone while the registration, the approval and the owner's worker account are current. knowledge.source.remove, namespace retirement and owner erasure now queue a worker source's copies for the retirement worker, which no longer skips an inactive worker row. The setting is off by default and is turned on only once every replica runs this build. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Signed-off-by: zlareb1 <lareb.zafar@clickhouse.com>
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
…d-copy Signed-off-by: zlareb1 <lareb.zafar@clickhouse.com>
…er's own denial The workers child and `loom knowledge sync` open the source worker directory, so their sync turns reach the provisioned workers. A turn reads exactly the selected copies' addresses instead of the newest page of documents, and a page of unselected leftovers apart. A copy is retired only on the worker's own 403, once the registration and the owner's authority are read again and hold; a denial Loom's own checks answer ends the turn with every copy kept. A resource left without a copy waits its refresh interval or half the stale window before it is read again. An approval or worker account that no longer matches the registration ends it under the sources lease: the row goes inactive, its copies are queued for retirement and its state reads owner_inactive. A copy request resolves its authority before it is sent and after the reply, no longer three times. The mirror read gate's registration read returns only worker rows whose stored registration names an owner-only copy mode. The setup `mode` description fits the generated references whole, and the docs say what removal does with the setting off. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Signed-off-by: zlareb1 <lareb.zafar@clickhouse.com>
| copy.entry["retry_at"] = (asked + self._wait()).isoformat() | ||
| if copy.stored: | ||
| copy.entry["verified_at"] = asked.isoformat() | ||
| return True |
There was a problem hiding this comment.
Refused copy still resets refresh clock
Medium Severity
When a stored copy's new body is refused, _write returns without updating sha, but visit still sets copied_at and verified_at. For selected_refresh, that restarts interval_seconds and lets _vouch treat the old body as freshly confirmed, so the upstream text is not read again until the full interval elapses.
Reviewed by Cursor Bugbot for commit bb02ac0. Configure here.
The source worker answers the upstream's own HTTP 403 to a read with
{"status": "denied", "reason": "upstream_access"}; every refusal it makes itself (a grant
that fails to verify, a binding or record that no longer matches, a document naming
another resource, a redirect, a refused closing DELETE) stays a plain denied. Loom reads
that body bounded and strictly, and its sync retires a copy only on it, after the
registration and the owner's authority are read again; a plain 403 ends the turn with
every copy kept. A worker build without the reason never causes a retirement.
The mirror read gate skips a worker row its reader does not own before any registry
read, using the row's owner and the reader's own subject read once per plan. A
registration whose authority is gone ends through the same helper a connected source
uses, and the leftover-copy retirement stops at the pass budget.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: zlareb1 <lareb.zafar@clickhouse.com>
…enial The source worker answers `upstream_access` only for an upstream 403 to the resources/read, or the mapped read's tools/call, inside an opened session. A 403 to initialize, tool discovery, the GET stream or the closing DELETE may come from a network policy in front of the upstream, so it stays a plain denied. A plain denial of a resource with no copy now sets its wait before the turn ends, so the next turn reaches the other resources. A process sends at most one copy at a time, so the channel's copy share holds one slot. The boundary page says a copy and a live read share the worker's own read slots. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Signed-off-by: zlareb1 <lareb.zafar@clickhouse.com>
The boundary page said a stored-copy confirmation compares digests; it confirms the owner's access only, and a test now pins that. The upstream-403 check drops a method test the read flag already implies, and a one-key comprehension becomes a plain lookup. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Signed-off-by: zlareb1 <lareb.zafar@clickhouse.com>
A stored copy whose access check keeps answering timeout or unsupported no longer pins the listing of every other copy: once its last confirmation is older than knowledge_source_acl_stale_seconds it is served no more, so it is retired, waits, and is copied again once readable. The state notes copy_unconfirmable. The unselected-copy sweep goes: a copy's address is fixed by its source ID and resource, and a registration's selection never changes. The owner's writer-grant check is one helper, connected_accounts.owner_writes, for the worker turn and both connected checks. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Signed-off-by: zlareb1 <lareb.zafar@clickhouse.com>
A copy that kept answering timeout or unsupported was retired only after the listing it held back had expired, leaving the source's other copies unserved until the next pass. It now goes once its confirmation would lapse before the next pass, and only while the owner's authority, read again, still holds. The listing write drops a publication guard that does nothing for a worker source, and the docs say which retirements there are. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Signed-off-by: zlareb1 <lareb.zafar@clickhouse.com>
…firmed peer A stalled upstream answers every request with a timeout, and retiring the copies that lapsed then cost a full re-copy and a wait of up to the refresh interval for nothing. A timeout now keeps the copy. A copy answering unsupported as its confirmation is about to lapse goes only when another copy was confirmed after its own check fell due, which shows the failure is the resource's. A resource without a copy that times out waits half the stale window, so it no longer comes first on every pass. The lapsing age drops a floor no check could reach. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Signed-off-by: zlareb1 <lareb.zafar@clickhouse.com>
Retiring a lapsing copy in a turn that a later refusal ended gained nothing, since that turn records no listing, and broke the documented rule that such a refusal keeps every copy. The lapsing age's docstring and the boundary page now give the real reason no copy goes before half the stale window, and two paragraphs are reflowed. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Signed-off-by: zlareb1 <lareb.zafar@clickhouse.com>
…d-copy The worker copies rolling-upgrade rule becomes rule 76 after main's read receipts took 75, and it, the boundary page and the source worker README now say an older worker never causes a retirement on a denial, while a copy answering unsupported follows the lapsing rule with either build. The boundary page lists the turn's authority checks in the order the code runs them. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Signed-off-by: zlareb1 <lareb.zafar@clickhouse.com>
…the turn's checks The boundary page and the source worker README said an older worker never causes a retirement; a copy answering unsupported still follows the lapsing rule with either build. The boundary page lists the turn's authority checks in the order the code runs them. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Signed-off-by: zlareb1 <lareb.zafar@clickhouse.com>
…s pass the bound A copy whose request ended a turn (unavailable, overloaded, reconnect, a plain denial) came first again on every pass, so one failing resource kept every other copy of its source unconfirmed. It now sorts after the others for half the stale window, and a resource without a copy waits that long. A worker source's turn also starts once other mirrored sources have used up the document bound, since its checks spend only time. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Signed-off-by: zlareb1 <lareb.zafar@clickhouse.com>
A stored copy refused with a plain denied (a reply naming another resource) ended every turn first, as the other turn-ending refusals did before. It now gets the same mark and sorts after the rest. The module docstring states the order and each wait. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Signed-off-by: zlareb1 <lareb.zafar@clickhouse.com>
…he ended mark A turn read the owner's directory standing once at its start, then only the writer grant for each request, so a SCIM deactivation or revocation mid-turn still let the turn read and write copies. Every request now reads the whole standing. The mark that sent a copy last after a turn-ending refusal changed nothing a reader sees, since that copy ends each turn it is checked in, so it is removed; the docs say such a copy keeps the source's copies unserved until it answers, which fails closed. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Signed-off-by: zlareb1 <lareb.zafar@clickhouse.com>
…a docstring Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Signed-off-by: zlareb1 <lareb.zafar@clickhouse.com>
…n wait Copies and checks run one at a time within the mirrored phase, so the copies one deployment keeps served are bounded by that phase's time over one check's; the boundary page says so, and that past the bound copies stop being served. A plain denial of a resource without a copy waits half the stale window, as other turn-ending refusals do, and a routes file that does not provision the profile reads unavailable rather than the owner's. interval_seconds is described as the least time between copies. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Signed-off-by: zlareb1 <lareb.zafar@clickhouse.com>
…d-copy Brings the worker setup CLI from main. With this branch's copy modes, the worker-preview and worker-register commands gain --interval-seconds, and --mode's help says snapshot and selected_refresh answer unavailable unless the server keeps worker copies. Also: the interval_seconds description leads with its rule so the generated reference keeps it, the capacity paragraph says only a turn the bound cuts reads pass bound reached, and a check that could not fail is gone. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Signed-off-by: zlareb1 <lareb.zafar@clickhouse.com>
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes using default effort and found 1 potential issue.
There are 2 total unresolved issues (including 1 from previous review).
❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, have a team admin enable autofix in the Cursor dashboard.
Reviewed by Cursor Bugbot for commit 001a636. Configure here.
| ] | ||
| oldest = _oldest_confirmation(copies) | ||
| if not due and oldest is not None and oldest.isoformat() == listed: | ||
| return # every copy was confirmed lately, and the listing says so |
There was a problem hiding this comment.
Idle sync skips registration retirement
Medium Severity
When nothing is due and the stored listing timestamp already matches, _sync_copies returns before authority. A revoked approval or a dead worker account then never reaches _end_registration until a check is due, up to half of knowledge_source_acl_stale_seconds. The registration stays active and its copies are not queued for retirement.
Reviewed by Cursor Bugbot for commit 001a636. Configure here.
The turn marked the bound only when it cut a visit, so a turn whose time ran out after its last visit recorded no listing with no mark. The listing and lapsing steps now mark it too. The interval_seconds description fits the generated SDK comment, and the capacity paragraph is rewrapped. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Signed-off-by: zlareb1 <lareb.zafar@clickhouse.com>
A stored selected_refresh copy due for its refresh at an exhausted document bound was only checked, with no mark, so the turn read ok while refreshes waited; it now marks pass bound reached. The retry waits come from one helper, the lapsing step's pass-bound branch has a test, and rule 76 says N-1's retirement worker leaves an entry pending while an inactive worker row of that source ID remains. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Signed-off-by: zlareb1 <lareb.zafar@clickhouse.com>
…k is due The previous change sent an access check every pass for a stored copy due for refresh at an exhausted document bound, however fresh its access, which spent the mirrored phase's time the capacity bound counts on. It now marks the bound and checks only when the copy's check is due. Rule 76 states N-1's pending retirement once, and the worker drops an authority refusal the close never meets. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Signed-off-by: zlareb1 <lareb.zafar@clickhouse.com>
…d-copy The generated Go wire models conflicted; they are taken from main and generated again for this branch's fields. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Signed-off-by: zlareb1 <lareb.zafar@clickhouse.com>
…d-copy The worker copies rolling-upgrade rule becomes rule 77 after main's session-run rule took 76. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Signed-off-by: zlareb1 <lareb.zafar@clickhouse.com>
main's #2165 made an owner's worker copy a mirrored turn (`_mirrored`): the two turn-tally lines this branch adds in `_sync_turn` use `_mirrored` too, so a worker copy's failure counts under `SYNC_FAILED`. The generated SDK models are regenerated over both sides. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Signed-off-by: Lareb Zafar <lareb.zafar@clickhouse.com>


Related: #1190
Related: #2144
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):
With
knowledge_source_worker_copies_enabledon, a collection writer can register an owner-onlysnapshotorselected_refreshworker source. The sync worker keeps a private copy of its selected resources in the collection's mirror, which only the owner can search.Why
A worker source served only
livereads: each search read the resource through the worker and kept nothing.snapshot(copy once) andselected_refresh(copy again on an interval) were in the setup contract but answeredunavailable. They need a stored copy, a refresh, a read check and erasure, all of which the native mirrored sources already have.This change gives worker copies those same pieces: the source sync engine, the collection's mirror, the mirror read gate and the
knowledge_source_retirequeue. It adds no table. The one worker protocol change is an optionalreasonon the worker's 403 body.Scope and risk
knowledge_source_worker_copies_enabled, off by default. While it is off, setup answersunavailablefor both modes, as before, and nothing in this PR writes or serves a copy.snapshotandselected_refresh. Team access still answersunavailable.selected_refreshtakes a newinterval_secondsfield, 300 to 86400: the least time between a resource's copies, since a copy is read again at most once a sync pass and only with room in the mirror document bound. It is required for that mode and refused for the others.resources/reador mappedtools/callrequest becomes a new client error,forbidden, which the HTTP service answers with theupstream_accessreason. A 403 toinitialize,tools/list, any other POST, the GET stream or the closingDELETEstays a plaindenied, because those are often the worker's own network or setup (an allowlist, an Origin check, a firewall). Grant, binding and protocol refusals keep the plain{"status":"denied"}body.loom knowledge source worker-previewandworker-registergain--interval-seconds, and their--modehelp sayssnapshotandselected_refreshanswerunavailableunless the server keeps worker copies. The CLI snapshots and reference are regenerated.copyshare of 1 slot, since a process sends at most one copy at a time, so a copy never takes one of Loom's live-read channel slots. On the worker, a copy and a live read share the sameread_limits.concurrentandconcurrent_per_orgslots, so on a small worker a copy in flight can make a live read answeroverloaded; the boundary page says so. A copy uses the worker's existing live route, and an access check usescheck_access, which returns a digest and no content.server/knowledge/app/source_sync_worker.py), for each selected resource:selected_refreshwhen its interval has passed. The copy is read as the owner throughCurrentRead(purpose="stored")and written with an access list naming only the owner. An unchanged digest writes nothing.knowledge_source_acl_stale_secondsold. A check confirms the owner's access only; the digest is not compared, so a changed resource keeps its copy until the copy is due again.{"status":"denied","reason":"upstream_access"}, which the worker sends only when the upstream MCP server answered 403 to the resource read itself. The registration, the owner's standing and the owner's authority must also still hold when re-read just before. Every otherdeniedends the turn and retires nothing. That covers the worker refusing Loom's grant (a rotated key, a skewed clock, a mismatched binding) and Loom's own changed authority, as well as a reply Loom cannot trust.timeoutandunsupportedleave that copy unconfirmed and the turn moves on. Atimeoutmay come from the upstream or the worker, so it never retires a copy. A copy answeringunsupported(for example a resource deleted upstream) is retired once its confirmation would lapse before the next pass, that is, once it is older thanknowledge_source_acl_stale_secondslessknowledge_source_sync_interval_seconds. Two conditions must also hold: another copy was confirmed after this copy's own check fell due, which shows the failure is the resource's, and the owner's authority, read again, still holds, in a turn no other refusal ended. The copy then waits before it is tried again, so one resource cannot keep the source's other copies from being served.reconnect,overloaded,unavailableor lost owner standing end the turn.unsupportedanswer, so the next turn reaches the others. 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.knowledge_source_acl_stale_seconds. So once any copy's access has gone unconfirmed for that long, none of the source's copies is served.source_access._worker_copy_eligible): it admits a worker source's copies only when all of these hold:connected_accounts.owner_writes, now reads the owner's writer grant for both connected sources and worker copies. The owner keeps their directory standing, with no revocation since the registration, and a writer grant on the namespace. Every worker request reads that whole standing again, andCurrentReadre-checks the approval and the owner's worker account at the registered generation before the request and after its reply, so a SCIM deactivation or revocation mid-turn stops the next read and write.owner_inactive, as the owner check does for connected sources. A failing read, a lost writer grant or a profile this replica's routes file does not provision ends nothing.loom knowledge syncopen the source worker runtime, so copies sync in the defaultworkers_process=childdeployment.pass bound reachedin the source's sync state (a source the phase does not reach keeps its last state). The boundary page states this. The bound is not measured in this PR; raising it (concurrent checks, or a worker-side refresh) belongs to the hosted scale qualification. The feature is experimental and off by default.unavailable, notowner_unavailable.prepareand one by eachcheckbatch; a copy row the reader does not own is then skipped before any registry read.knowledge.source.remove, namespace retirement and owner erasure queue a worker source's copies for theknowledge_source_retireworker. Owner erasure queues them before it deletes the rows.source-id:tag, so the existing retirement path finds them.Compatibility, rollout and rollback
interval_secondson the worker setup preview and register inputs, required forselected_refreshand refused for the other modes. Aselected_refreshpreview or register without it, which used to answerunavailable, now gets an invalid-input error, whatever the setting. Theremoveand setup descriptions are updated, and the SDKs and the docs reference are regenerated.docs/architecture/rolling-upgrades.md.unsupportedfollows the lapsing rule with either worker build. That source's copies stop being served after the stale window instead. An N-1 Loom ignores the reason a new worker adds.pending_deletewhen a worker source is removed, because a copy written while the setting was on outlives turning it off. With no copy the entry finds nothing; N clears it and N-1 leaves it pending.snapshotandselected_refreshworker source with N and let theknowledge_source_retireworker drain. N-1 neither serves nor retires their copies.Tests
tests/unit/test_worker_source_copies.py(53 test functions, 76 cases with parametrization) covers:deniedretires, transient failures keep the copy and record no listing, the document bound, a copy answeringunsupportedretired before its confirmation lapses only when a peer was confirmed since its check fell due, kept on any timeout, on refusals that end the turn and when the owner's authority is gone; a deactivation mid-turn stopping the next read; worker turns past the document bound;tests/unit/test_mcp_worker_read.pycovers the copy share.tests/unit/test_cli_knowledge_source_worker.pyadds aselected_refreshpreview sending its interval, and no interval sent unless given.tests/unit/test_worker_copy_store_sql.pyruns the new store queries on clickhouse-local againstschema.sql. It checks that 241 copies are all found past a page of documents, along with another writer's row and a superseded row, and that the read gate's query returns only owner-only copy-mode worker rows.upstream_accessanswer for an upstream 403 to the read, and a plaindeniedfor a 403 toinitialize, discovery, the GET stream or closing the session, and for grant, binding and resource mismatches.source_worker/qualification/test_real_tls.pyadds a read-time 403 over real TLS.denied;Local runs:
ruff formatandruff check, the function-length gate, the no-secrets check, all 16 generator--checks, and Prettier and the prose checker on the changed docs.mypyon the changed modules. It reports errors only for imports missing locally (numpy,tree_sitter).source_worker/qualification/test_real_tls.py(7 tests) andmypyonloom_source_worker.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 wrote the turn, the read gate, the retirement changes and the tests. I set the design (reuse the sync engine, mirror, read gate and retirement queue instead of a new queue; fail closed through listing freshness; a setting turned on after the rollout) and checked the turn and the rolling-upgrade rule.
I can explain every line of this diff and how it interacts with the rest of Loom.
Checklist
make test-unitand applicable integration results are reported by CI; a full local run is not required before pushing.docs/reference/tables.docs/describe the system as it now is.🤖 Generated with Claude Code
Note
Medium Risk
Touches sync, mirror access control, retirement/erasure, and cross-version rollout when enabling the flag; default-off limits exposure, but mixed replicas or rollback without draining sources can leave orphaned unserved copies.
Overview
Adds experimental, off-by-default owner-only
snapshotandselected_refreshworker sources that Loom mirrors into the collection (gated byLOOM_KNOWLEDGE_SOURCE_WORKER_COPIES_ENABLED). Preview/register gaininterval_secondsforselected_refresh; setup serves those modes only when the flag is on.A new
source_sync_workerturn copies or refreshes selected resources through the source worker (dedicatedcopychannel slot), runs periodic access checks, and records listing freshness fail-closed like native mirrored sources. The mirror read gate admits those copies only to the owner with current approval and worker account.Removal, namespace retirement, and owner erasure now queue worker copies for
knowledge_source_retire(same path as other mirrored sources), including erasure ordering before row delete. Connected-source owner inactive retirement is factored to sharedretire_owner_inactive.The source worker distinguishes upstream resource 403 (
reason: upstream_access) from other denials so Loom can retire a copy immediately on true upstream access loss; other failures keep copies until stale/lapsing rules apply.Workers child and
loom knowledge syncload the source worker runtime so copies can sync in the default deployment. Docs, settings schema, and SDKs are regenerated for the flag and wire fields.Reviewed by Cursor Bugbot for commit cd1cf33. Bugbot is set up for automated code reviews on this repo. Configure here.