Skip to content

An administrator assigns a shared namespace's document source to a service account's worker - #2376

Open
zlareb1 wants to merge 8 commits into
mainfrom
feat/source-worker-service-assignment
Open

zlareb1 wants to merge 8 commits into
mainfrom
feat/source-worker-service-assignment

Conversation

@zlareb1

@zlareb1 zlareb1 commented Dec 6, 2026 •

Copy link
Copy Markdown
Member

Related: #1189
Related: #1232

Changelog category (leave one):

  • New Feature

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 namespace administrator can assign a document source in a shared namespace to a service account that runs a worker (knowledge.source.worker_assign), and that worker's knowledge.source.worker.claim is offered its sources in every namespace of the org. Assigned sources stay experimental.

Why

knowledge.source.worker_assign took only an agent's subject, in that agent's own namespace. A team's shared index, such as public documentation, has no agent: an operator runs the worker under a service account, and no assignment could name it.

The worker subject's kind now decides where an assigned source lives:

Worker subject Namespace it syncs
An agent's (sa:<trust>:<agent>) The agent's own namespace, and not while the agent has lent it. Unchanged.
Any other A namespace no workload trust made for an agent, that takes a shared source: not a person's own, and active.

A claim follows the same split. An agent's subject is offered the sources of its own namespace and nothing else. A subject with no namespace of its own is offered the sources that name it across its org, from one statement over the registry and one read of their sync states, never a read per namespace.

Scope and risk

Touches the assign handler, the claim handler, three new store statements, the op and CLI descriptions, the docs, and the dashboard's menu for an assigned source. No op, field, migration or setting is added.

Tenant isolation:

  • The org-wide statement filters on the caller's own subject and returns only rows that name it. It returns the key, the row version and the registration, never the items. The row a turn starts on is read whole before its turn lease, and is offered only at the version and subject the poll read.
  • An agent's token never claims outside its own namespace, whatever row names its subject: that path is unchanged and reads one namespace.
  • A subject that is no agent's is never assigned inside an agent's namespace. The directory tag a workload trust leaves decides it, and a released agent namespace keeps the tag. An agent claim's mark starts as a trust's tag does and names no trust, so the statement leaves it out: a namespace claimed at sign-up is refused as a person's own (PERSONAL_NAMESPACE). A namespace that holds an active source cannot later become an agent's own, since the name is in use.
  • Only a service account calling as itself is answered a turn. worker_assign cannot tell what a subject string names, so a source that names a person is stored and never synced. The docs say so.
  • The copies are read by every reader of the namespace, as for any source added to a shared namespace. A viewer of another namespace sees neither the source nor a copy.

Design calls:

  • The shared-namespace check reuses the rule for a source added to a namespace, so a person's own namespace and an inactive one are refused (PERSONAL_NAMESPACE, NAMESPACE_INACTIVE).
  • A poll by a subject with no namespace of its own draws the namespace tier of its rate limit on a slot per subject, so one worker's polls spend no other's.
  • One claim reads 2,000 sources at most, a bound on the statement. Assignment does not count a subject's sources; the docs name the bound and say to run a second worker under another subject past it.
  • The dashboard offers Retire on an assigned source to the subject that assigned it, the only one the server takes its removal from, and its dialog says the copies go with the source.
  • A worker run beside an account host syncs the one namespace its job names, whatever the kind of its subject. An agent's claim reads no other namespace. A service account that is no agent's and runs that way is assigned sources in that one namespace: a source its claim answers from another shared namespace is refused tool_not_allowed and left blocked. docs/architecture/mcp-source-worker-boundary.md states the rule for both kinds of subject.

What could break: a service account that polled claim and was answered none is now answered the turns of the sources that name it. No such source could exist before this change.

Compatibility, rollout and rollback

  • Wire: no op or field added or removed. knowledge.source.worker_assign accepts a worker_subject that is no agent's in a shared namespace, where it answered 422 SOURCE_WORKER_NAMESPACE; in that case it can also answer 422 PERSONAL_NAMESPACE or NAMESPACE_INACTIVE. knowledge.source.worker.claim offers a service account that is no agent its sources across the org. The descriptions of namespace and worker_subject on worker_assign, the description of claim, and the help of loom knowledge source assign changed.
  • Operator steps: none.
  • Rolling upgrade: the stored row has the shape of every assigned row. A replica one build behind lists it, retires it on remove and expires its copies as it does an agent's. It refuses to make or change one, and answers that subject's claim none, so a worker routed to it polls again. stored, put and commit on a turn the new build opened are served by both builds. docs/architecture/rolling-upgrades.md records this under the assigned-source rule.
  • Rollback: sources assigned to a service account stay in the registry and are never claimed. Their copies are served until the copy age bound retires them or the registrant removes the source. Generated files revert with the commit.

Tests

The branch holds main at 54c149c, merged in twice: first at f9cb57f, then at 54c149c. The second merge conflicted in two generated files, tests/unit/snapshots/cli_help.json and the cli region of docs/reference/cli.md; both are regenerated from the merged code and hold the sync-now command beside the changed assign help. git merge-tree against main at 377ad6b reports no conflict. The results below marked "merged tree" were measured after the first merge, those marked "second merge" after the second, and the others at the head before either (408da55, on b462e6c).

  • Unit, new, each failed before the code: test_a_service_subject_is_assigned_only_outside_agent_homes, test_a_service_worker_claims_across_namespaces, test_a_person_named_as_worker_subject_claims_nothing, test_the_org_wide_claim_is_one_statement_and_one_state_read, and test_a_source_rewritten_since_the_poll_read_it_starts_no_turn. The first also covers a namespace claimed at sign-up, a case that answered SOURCE_WORKER_NAMESPACE before its fix.
  • Merged tree, pytest -n 2 on tests/unit/test_assigned_source.py, test_source_worker_ops.py, test_by_id_ops_scoped_tokens.py, test_cli_surface_snapshot.py, test_cli_knowledge_source.py, test_cli_knowledge_source_worker.py, test_agent_shares.py, test_knowledge_source_retirements.py, test_source_worker_wire_fixture.py, test_docs_reference.py, test_package_contracts.py, test_op_transport_contract.py, test_tunable_constants.py, test_store_names_refused.py, test_degraded_unnoted.py, test_public_copy.py, test_doc_links.py, test_agent_instructions.py and tests/analyzer: 910 passed, 13 skipped, 1 failed. The failure is test_degraded_unnoted.py::test_every_broad_handler_notes_its_fallback_or_says_why_it_need_not, on _history_section in server/code/app/index/review_brief_build.py. This change touches neither that file nor the test's list, and the same test fails in the CI run of main at f9cb57f.
  • Second merge, pytest -n 2: test_cli_surface_snapshot.py and test_cli_knowledge_source.py, 25 passed. test_source_worker_ops.py, the six test_ratelimit_*.py files, test_admission_gates.py, test_admission_parity.py, test_runtime_overrides.py, test_traffic_classes.py, the eight scans named above and tests/analyzer: 848 passed, 12 skipped, 1 failed. The failure is the same test_degraded_unnoted.py case: the file it names is the one main holds at 54c149c, and main changes that file for this scan in f2eeb8a, which this branch does not hold.
  • Before the merge, test_mcp_listing_budget.py, test_sdk_surface_contract.py, test_go_sdk_contract.py, test_op_reach_census.py, test_read_scope.py and test_session_content_senders.py passed with the files above. The MCP listing budget is unchanged.
  • Integration, against a server from source on a ClickHouse started for this change. Merged tree: tests/integration/test_assigned_source_ch.py and test_a_reader_of_the_shared_namespace_finds_a_service_workers_copy, 8 passed. The new test_a_namespace_claimed_at_sign_up_is_refused_as_a_persons_own_place failed before its fix, answered SOURCE_WORKER_NAMESPACE. Before the merge: tests/integration/test_source_worker_turn_ch.py and tests/integration/test_assigned_source_ch.py, 22 passed, and the new case in tests/integration/test_cross_principal_leakage.py passed with LOOM_AUTH_REQUIRED=true and with auth off. The service worker test and the leakage case were written with the code, so they have no failing run on the branch; on main the first assignment they make is refused with 422.
  • Analyzer, merged tree: python -m tests.analyzer.corpus --write leaves three statement shapes of this change in shapes.txt and no other difference. tests/analyzer passes, and test_every_shape_passes_the_analyzer passes against that ClickHouse.
  • Generators, merged tree: docs_reference, sdk_py_gen, sdk_py_client_gen, sdk_ts_gen, sdk_rb_gen, op_reach_census and plugin_eval_tools pass --check, and the CLI snapshot test passes. sdk_rust_gen and sdk_go_gen need rustfmt and gofmt, which the machine these checks ran on does not have, so CI is their check; this change's diff against main holds no file under sdk/rust or sdk/go. Second merge: the same seven, sdk_py_admin_gen and settings_reference pass --check.
  • ruff format --check, ruff check, make typecheck, the function-length gate (at its baseline), Prettier on the changed pages and the prose checker pass on the merged tree, and again after the second merge.
  • Dashboard: five new tests failed before the change. npx vitest run src/views/SourcesList.test.tsx src/flows/KnowledgeSourceDialog.test.tsx --maxWorkers=2: 85 passed, 1 failed. The failure is SourcesList > names the collection in the toast and offers Open when the source lands elsewhere, which times out at 5,000 ms in this environment with the base branch's files too; this change does not touch it. npm --prefix frontend run build and the bundle budget pass, and the budget is not raised. Second merge: npx vitest run on SourcesList.test.tsx, KnowledgeSourceDialog.test.tsx and KnowledgeSourceDialog.connected.test.tsx, 120 passed, and npx tsc -b reports no error.

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 by hand: the two assign rules and their refusals, that the org-wide statement answers only rows naming the caller, the fresh read before the turn lease, and each test result above.

  • 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 make test-unit and applicable integration results are reported by CI; a full local run is not required before pushing.
  • Generated files are regenerated in this PR, not by hand: the SDK op tables, docs/reference/configuration.md and the docs/reference/ tables (python scripts/codegen/docs_reference.py), the reach manifest, schemas/schema.sql (make schema-dump), the Codex plugin copies (python3 scripts/codegen/agent_plugin_sync.py) and the standalone skill bundles (python3 scripts/codegen/standalone_skills.py).
  • A new migration is additive and numbered after the latest on main; no merged migration is edited.
  • A behaviour change to any file a plugin ships (hooks/, lib/, bin/, skills/, .mcp.json, the Codex plugin-defaults.json) bumps both plugin manifests' version, and no other open PR uses that version.
  • The frontend builds (npm --prefix frontend run build) and its tests pass, if frontend/ changed.
  • Docs under docs/ describe the system as it now is, and this description names any operator steps and wire changes.
  • Repository text has no dates, people, host names, internal namespaces, ticket or decision numbers; the history goes in this description (tests/unit/test_public_copy.py).
  • Commits are signed off (git commit -s), as CONTRIBUTING.md asks.
  • I signed the Contributor License Agreement (CLA) if CLA assistant requested a signature.

🤖 Generated with Claude Code

…rvice account's worker

knowledge.source.worker_assign took only an agent's subject, in that agent's
own namespace, so a team's shared index had no worker that could sync it.

The worker subject's kind now decides where the source lives. An agent's
subject keeps its rule: its own namespace, and not while it has lent it. Any
other subject is assigned only in a namespace no workload trust made for an
agent, and one that takes a shared source: not a person's own and active. A
blank subject is refused.

knowledge.source.worker.claim offers an agent's subject the sources of its
own namespace, as before. A subject with no namespace of its own is offered
the sources that name it across its org: one statement over the registry on
the key prefix org that returns the key, version and registration of the rows
naming the caller, 2,000 at most, and one read of their sync states. The row a
turn starts on is read whole before its lease and is offered only at the
version and subject the poll read. Such a poll draws the namespace tier of its
rate limit on a slot per subject.

The dashboard offers Retire on an assigned source to the subject that
assigned it, and says that its copies go with it.

No op, field, migration or setting is added. A replica one build behind lists,
retires and expires such a source as it does an agent's, refuses to make one
and answers its subject's claim with none.

Signed-off-by: Mohammad Lareb Zafar <lareb.zafar@clickhouse.com>
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
@vercel

vercel Bot commented Dec 6, 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 Dec 6, 2026 10:33am UTC
loom-telemetry Ready Ready Preview Dec 6, 2026 10:33am UTC

Request Review

@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 default effort and found 2 potential issues.

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 408da55. Configure here.

"a source there",
code="SOURCE_WORKER_NAMESPACE",
)
await source_ops._require_source_namespace(org, namespace)

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Assignment races agent namespace creation

High Severity

A service-account assignment treats a namespace as shared after trust_made sees no directory row, under sources_lease. Agent provisioning creates that home under account_change after its own in_use check, so both can succeed and leave the source in the agent namespace. knowledge.source.worker.claim then offers that row org-wide and never checks the trust tag.

Additional Locations (1)
Fix in Cursor Fix in Web

Reviewed by Cursor Bugbot for commit 408da55. Configure here.

Comment thread server/knowledge/store/sources.py Resolved
zlareb1 and others added 7 commits December 6, 2026 09:34
The dependency review compares the snapshot inputs between the merge base and
the base branch, and main changed sdk/rust/src/wire_models.rs after the merge
base this branch had. The merge is clean: main's hunks in the generated
reference pages, the TypeScript ops, the CLI snapshots and the analyzer shapes
touch none of this branch's lines.

Signed-off-by: Mohammad Lareb Zafar <lareb.zafar@clickhouse.com>
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
…PERSONAL_NAMESPACE

An agent claim's mark, machine:agent-signup:claimed, starts as a workload
trust's tag does and names no trust. trust_made matched it, so
knowledge.source.worker_assign answered SOURCE_WORKER_NAMESPACE with "is an
agent's own namespace; only that agent's subject syncs a source there" for a
namespace no agent's subject can be assigned in. The statement leaves the
claim's mark out, and the namespace reaches the shared-source check, which
refuses a person's own place as knowledge.source.add does. Both answers are 422.

Signed-off-by: Mohammad Lareb Zafar <lareb.zafar@clickhouse.com>
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
…d maturity

The reference cuts a command's help at 200 characters, and the help was 240,
so the row ended before "(knowledge.source.worker_assign, experimental)". The
help is 158 characters, and the rule for the namespace is in the help of
--namespace.

Signed-off-by: Mohammad Lareb Zafar <lareb.zafar@clickhouse.com>
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
…nds of subject

Five statements said a claim reads only the caller's home namespace, or that a
host connection serves only an agent's own namespace. An agent's claim reads
its own namespace and draws the namespace bucket there. Any other service
account's claim reads the org's rows that name it, where the assignment is the
grant, and draws the bucket on a slot per subject. A host connection gives
authority where an administrator assigned the source: the agent's own
namespace, or a shared one for a subject that is no agent's.

Signed-off-by: Mohammad Lareb Zafar <lareb.zafar@clickhouse.com>
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Two generated files conflicted, and both are regenerated from the merged code:
tests/unit/snapshots/cli_help.json by the CLI surface snapshot test, and the cli region
of docs/reference/cli.md by docs_reference.py. Each holds the sync-now command beside
the assign help that names both kinds of namespace.

Signed-off-by: Mohammad Lareb Zafar <lareb.zafar@clickhouse.com>
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
…t, for both kinds of subject

The host backend section said a claim reads the home namespace alone, which holds for an
agent's subject only. The claim of a service account that is no agent's reads the org's
rows that name it. The page says what each claim reads, and that the backend syncs the
one namespace it is given: a source claimed from another shared namespace is refused
`tool_not_allowed`.

Signed-off-by: Mohammad Lareb Zafar <lareb.zafar@clickhouse.com>
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
…er many namespace buckets

The comment sits above the org's poll and write limits. Only a claim by a subject that
is no agent's draws a namespace bucket of its own; `stored`, `put` and `commit` draw the
bucket of the source's namespace, which the workers assigned there share.

Signed-off-by: Mohammad Lareb Zafar <lareb.zafar@clickhouse.com>
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>

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