Skip to content

Read live documents through a provisioned source worker - #1302

Open
zlareb1 wants to merge 24 commits into
mainfrom
feat/mcp-worker-live-control
Open

zlareb1 wants to merge 24 commits into
mainfrom
feat/mcp-worker-live-control

Conversation

@zlareb1

@zlareb1 zlareb1 commented Nov 24, 2026 •

Copy link
Copy Markdown
Member

Related: #1189
Related: #1190
Related: #1298

Changelog category

  • New Feature

Changelog entry

Add an experimental operation for reading a selected document through a provisioned source worker. The read keeps no body and does not change stored document search.

Why

Live reads need the exact caller's upstream connection, but Loom does not need the credential. The worker resolves an opaque connection under a signed request. Loom checks the caller's collection grant, approved worker, selected resource and current account before it contacts the worker and again before it delivers the result.

Scope and risk

knowledge.source.live is an experimental read operation on the existing HTTP and MCP transports. It requires the protected publication barrier and Postgres knowledge authority. Loom holds the source update lease and locks the exact approval, account and team link rows during each bounded response handoff. A response may wait for another source operation within its frame deadline. Loom checks authority after taking the lease, so a retirement or revocation that has already committed stops that frame. The worker read ends before the separate deadline for retention, accounting and delivery. A team reader needs a separate enrolled connection for the same verified resource realm. Loom checks current team enrollment, both connections and approval before testing whether the requested identifier is selected. Selected and unselected identifiers get the same response when a team reader lacks current authority. The live read caps the document and its escaped MCP text copy at 16 MiB before it retains the publication fence. Larger results return unsupported without a document. Both transports cap the unknown argument names they echo. MCP also bounds the JSON-RPC request ID. This operation admits no answer tokens and does not fall back to a stored copy. The ledger keeps request accounting without arguments, result bodies or exception text. The operation disables body capture regardless of namespace consent.

This is the live read prerequisite. Account setup, selected imports, refresh and stored access remain separate work. The dashboard has no protected live view. No provider or native source is removed. See Document source worker boundary.

Compatibility, rollout and rollback

  • Wire: adds knowledge.source.live and explicit read status, body, source link and fetch time. Existing operations and defaults are unchanged.
  • Operator steps: LOOM_KNOWLEDGE_SOURCE_WORKER_ROUTES_FILE defaults to empty. A configured route requires explicit trust, a client certificate and a separate request signing key. Worker settings can shorten the read, publication and frame deadlines and reduce concurrent setup checks. The defaults keep the existing bounds. Keep registrations and copy writes disabled until the worker, account setup, erasure and mixed versions qualify together.
  • Rollback: Postgres migrations add metadata tables. The worker source codec uses the existing ClickHouse source configuration and item columns. An old reader cannot serve the mirrored worker row. This change leaves writes to these registrations disabled.

Tests

Focused tests cover worker authority, enrollment, approvals, route configuration, privacy, and the SDK and settings contracts. Configuration tests cover valid overrides and refusal of out-of-range worker limits. A selection test proves the lowest parallelism setting still checks every selected resource. Regression tests cover concurrent delivery, retirement during delivery, equal responses for selected and unselected identifiers during approval outages, retention and delivery after the read deadline, and the exact worker metadata erasure statements. Ruff, function length and strict mypy for the changed authority modules pass. The Python, TypeScript, Ruby and Rust contracts describe the protected live read. Large fenced response bodies use bounded chunks. Each chunk checks current source and worker authority under the publication locks without repeating those lookups outside the fence. The response keeps its byte length, stream terminator, and existing deadlines. Focused request-tail and worker tests cover a 16 MiB transport body under simulated datastore latency and revocation between chunks. Worker protocol fixtures also exercise the real HTTP and MCP encoders: escape-heavy content within the budget arrives intact, while oversized content returns a complete refusal without retaining the publication fence. Hosted checks cover the real Postgres lock and mixed version paths.

AI assistance in the code

  • AI-generated with Codex. The tests and diff were checked against the current authority and publication code.

  • I can explain every line of this diff and how it interacts with the rest of Loom.

Checklist

  • Local format, lint, type checks and focused tests pass. The full suites are reported by CI.
  • Applicable SDK, settings and reference outputs were regenerated.
  • Postgres migrations are additive and follow the base migrations.
  • Mixed builds and live transport qualification pass on hosted CI.
  • Commits are signed off.

Note

High Risk
Touches authentication gates, Postgres authority locks, external worker trust, and live document delivery with strict publication fencing—security-sensitive live read surface.

Overview
Adds an experimental knowledge.source.live path (HTTP/MCP and all SDKs) that fetches one selected resource through an operator-provisioned source worker, returns link and body to the caller, and does not index or persist the content.

Worker integration is gated by LOOM_KNOWLEDGE_SOURCE_WORKER_ROUTES_FILE and new timeout/parallelism settings. Loom validates collection scope, worker approval, enrolled connections, and team reader links in Postgres (new mcp_worker_* migrations), signs short-lived Ed25519 grants, and talks to workers over mTLS with bounded responses (including 16 MiB publication cap → unsupported).

Publication safety extends request_tail: optional fences hold source/approval/account locks through delivery, including chunked large bodies with authority re-checks between chunks. Live reads are excluded from narrowed tokens, rate-limited as knowledge reads, and omit bodies from diagnostics/ledger via operation_privacy. Erasure and storage docs register the new tables.

CI adds test_mcp_worker_pg_fence.py to the Postgres storage matrix.

Reviewed by Cursor Bugbot for commit a3d7cbc. Bugbot is set up for automated code reviews on this repo. Configure here.

@vercel

vercel Bot commented Nov 24, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
loom-docs Ready Ready Preview Nov 26, 2026 8:25pm UTC
loom-telemetry Ready Ready Preview Nov 26, 2026 8:25pm UTC

Request Review

@zlareb1

zlareb1 commented Nov 24, 2026

Copy link
Copy Markdown
Member Author

85528c3a60bc02898d295d90b71cd8941c771389 adds a real Postgres test to the ordinary 16 and 18 storage jobs. The test observes the database blocking a team unlink, account revoke or approval revoke while a response frame is held. The revocation must commit after handoff, and a later handoff must be denied. Local checks covered the test syntax, lint and workflow selection; the database cases have yet to pass on hosted CI.

The earlier changes corrected the reported type errors, documented the metadata tables, classified live reads, and regenerated the SDK and settings snapshots. The focused checks passed. Fresh source review and required hosted checks are pending; setup, stored copy writes and native retirement remain disabled.

@zlareb1

zlareb1 commented Nov 24, 2026

Copy link
Copy Markdown
Member Author

The full CI run for 85528c3a60bc02898d295d90b71cd8941c771389 failed. Run

  • Both PostgreSQL storage jobs reached the new live delivery fence test. The approval revocation case failed because PostgreSQL inferred conflicting types for the mode parameter in the update. The owner and reader cases did not appear in the failure summary. The local fix binds that parameter as the column's smallint type.
  • Ruff, format, generated contract checks, SDK mypy, and the server mypy gate passed in the combined job. The function length check rejected the ledger and MCP call functions. The local fix moves the payload suppression and capture decision into small helpers; the capture test checks that live reads skip namespace consent, while regular calls still honor it.
  • The route provisioning test expected an active worker directory under the default unit settings. The local fix tests both storage authority modes explicitly, including the fail-closed case.

The base commit's CI run already failed seven of the same unit and isolation job categories. That comparison does not clear any required check. The changes above still need a new exact-head run and an independent whole-diff review. This draft remains limited to the protected live read path; it does not enable a deployment, stored copies, or the refresh worker.

@zlareb1

zlareb1 commented Nov 24, 2026

Copy link
Copy Markdown
Member Author

Independent review of 15ac4a2e3757edf91e1d6474ef650068e93571f9 requests changes. It covers the full changed-path set against a87e613a7faa2ebe72ac63d19e14b39c4027ff50. Unchanged role revocation internals remain outside review coverage; the review does not claim atomic ordering with them or with a future source mutation.

  • The shared admission rule treated every knowledge.* read like a namespace-owned row. A live upstream request cannot apply a user or session row filter. The local fix excludes this exact operation and enforces the same token restriction at the protected entry point. Focused tests passed for HTTP and MCP admission and the protected context.
  • The architecture page used present tense for storage, indexing, and refresh paths that do not run. It now states them as requirements and identifies the registered live prerequisite.

The exact head passed hosted lint and type checks. Both PostgreSQL storage jobs are still running, so the local revision is not published yet. A new independent review and exact-head hosted run are required after the next push. No activation is proposed by this draft.

@zlareb1

zlareb1 commented Nov 24, 2026

Copy link
Copy Markdown
Member Author

Hosted workflow 45390047966 for 15ac4a2e3757edf91e1d6474ef650068e93571f9 passed both PostgreSQL storage jobs (16 and 18). Both job logs show the new live source fence fixture ran. The approval revocation failure from the preceding head did not recur. The workflow remains red: seven unit and isolation jobs failed, in the same categories previously observed on the base. This is not a merge waiver.

New head 851772554cea3cd50ed127ae84d810d45c294458 rejects narrowed read credentials for the live operation before HTTP and MCP policy consumption, and documents the released scope of this draft. The relevant focused checks passed (8 tests). Fresh whole-source review and normal exact-head hosted qualification are pending. This draft does not enable live reads in production.

@zlareb1

zlareb1 commented Nov 24, 2026

Copy link
Copy Markdown
Member Author

Independent review of 851772554cea3cd50ed127ae84d810d45c294458 covered the 72 changed paths and confirmed the narrowed-token refusal and the corrected live/stored documentation. It recommends keeping the draft unmerged until hosted checks and the activation boundaries are qualified.

The exact-head HTTP schema job failed in test_generated_payloads_obey_the_actual_success_schema: Hypothesis reported HealthCheck.too_slow during input generation, before the test's request assertions. Recent main runs of that workflow passed. This is unresolved; there is no unchanged rerun or relaxed gate. The normal workflow is still running on this head.

@zlareb1

zlareb1 commented Nov 24, 2026

Copy link
Copy Markdown
Member Author

Exact head 851772554cea3cd50ed127ae84d810d45c294458: the required Postgres 16 and 18 storage jobs passed, each with 922 passing tests in the authority matrix. Both logs confirm execution of the worker fence fixture. Their standby durability and reconcile steps also passed.

The overall required workflow failed; separate unit and isolation jobs are red, and the separate HTTP contract workflow still records the input generation health check failure noted above. The independent review requests verification. This head cannot merge. The storage result covers the live-read control and its fence; it does not qualify scheduled refresh, stored document copies, or a real upstream provider.

@zlareb1
zlareb1 marked this pull request as ready for review November 26, 2026 16:28

@cursor cursor Bot left a comment •

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Stale Bugbot comment from a previous run.

Resolve the current enrollment, account realm, and worker approval before checking selection for a team reader. Keep unselected owner requests out of the approval lookup.

Signed-off-by: zlareb1 <[email protected]>
@zlareb1

zlareb1 commented Nov 26, 2026

Copy link
Copy Markdown
Member Author

The formatter failed on docs/pages/agent-memory-selector.astro in the merge with main. This PR does not change that page. The same Biome error occurs on main at 0e3555645029.

PR job: https://github.com/ClickHouse/loom/actions/runs/45862140452/job/140055809389
Main job: https://github.com/ClickHouse/loom/actions/runs/45861195869/job/140052411285

End the worker read timeout before retaining the protected result. The retention path still validates session and source authority under its bounded delivery deadline.

Signed-off-by: zlareb1 <[email protected]>
@zlareb1

zlareb1 commented Nov 26, 2026 •

Copy link
Copy Markdown
Member Author

On 701374b64835671bc77ee3a5bce942a1dd554426, concurrent live responses can wait for the source lease within the frame deadline. The final authority check still runs after acquisition. The regression failed on the prior head and passes on this one. The settings ratchet also passes locally; the supported worker settings preserve the existing defaults and cap the configured waits.

The formatter job reports docs/pages/agent-memory-selector.astro, outside this diff. The same formatter failure is on main. The Go analysis job stopped at the pinned analysis bundle download, before analyzing the Go SDK. Other hosted checks are still running.

A fresh independent review approved this exact head with no findings. It passed 37 focused tests and five subtests and exercised the lease polling code with a fake store. A waiting reader acquired the lease after release; a reader that timed out could neither enter the protected block nor release the other reader’s lease. The reviewer also verified the four generated settings and the tunable constants ratchet. GitHub approvals are still required.

@zlareb1

zlareb1 commented Nov 26, 2026

Copy link
Copy Markdown
Member Author

Independent review approved a47a773e61883ba323b358922395eabc43e23e6e with no findings. The review passed 177 focused tests and 25 subtests. The scoped inventory check reproduced the four missing settings on the previous head and confirmed that this head covers all four. Hosted checks and the required GitHub approvals are still pending.

@zlareb1

zlareb1 commented Nov 26, 2026

Copy link
Copy Markdown
Member Author

The full hosted feature inventory passes at a47a773e61883ba323b358922395eabc43e23e6e in unit part 5, and unit part 4 passes. Unit part 5 remains red only because the IndexNow test omits /agent-memory-selector. #1572 updates that assertion and formats the selector page; both of those jobs pass there. This PR still needs green checks on its own head after the base fix lands.

@zlareb1

zlareb1 commented Nov 26, 2026

Copy link
Copy Markdown
Member Author

Refreshed on main after the formatter and IndexNow fixes merged. Main also passed the TypeScript timing shard that failed on the preceding head. The preceding integration run separately hit a ClickHouse trace log flush timeout in the SCIM physical work fixture. This change does not edit either test or its bounds.

The new head keeps the worker behavior, tests and storage job coverage. The local checks passed lint, formatting, function length, settings type checks, generated settings and SDK output, and 65 focused settings, worker and inventory tests. The operation manifest retains the base hook entries. Full hosted checks and a fresh independent review will verify this head.

@zlareb1

zlareb1 commented Nov 26, 2026

Copy link
Copy Markdown
Member Author

Independent review approved d48461c6f3ddb8c24f845727a47d92a916373c60 with no findings. The merge from main preserved the feature changes across all 78 paths. The exact head passed 177 focused tests and 25 subtests, including delivery fencing and revocation. Hosted Postgres integration and the remaining checks still need to finish.

@cursor cursor Bot left a comment •

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Stale Bugbot comment from a previous run.

Split large encoded bodies into bounded chunks and reacquire the publication fence before sending each one. Keep the response length, stream termination, and existing publication deadlines.

Signed-off-by: zlareb1 <[email protected]>
Recheck the source and worker under the publication locks. Avoid repeating those lookups before taking the locks, and bound each body chunk to 512 KiB so delivery fits more readily within the existing deadline.

Signed-off-by: zlareb1 <[email protected]>

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes using high effort and found 1 potential issue.

Fix All in Cursor

❌ 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 4784da9. Configure here.

read.document.text,
read.document.mime_type,
)
_check_publication_size(document)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Size check races the read deadline

Medium Severity

_check_publication_size runs inside the live-read timeout_at after the worker returns. The worker channel already uses the same 8s bound, so a completed large read can expire that window during the two json.dumps calls. The outer handler then maps TimeoutError to timeout, so a document that should be ok or unsupported is withheld as a timeout instead.

Fix in Cursor Fix in Web

Reviewed by Cursor Bugbot for commit 4784da9. Configure here.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant