Skip to content

Document sources live on any shared namespace or collection, and the Library shows the sources of the place in view - #541

Merged
zlareb1 merged 7 commits into
mainfrom
feat/sources-any-namespace
Nov 12, 2026
Merged

zlareb1 merged 7 commits into
mainfrom
feat/sources-any-namespace

Conversation

@zlareb1

@zlareb1 zlareb1 commented Nov 11, 2026 •

Copy link
Copy Markdown
Member

Related: #539 (the document-sources design page; this is its step A)

Changelog category (leave one):

  • Backward Incompatible Change

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 document source can be registered on any shared namespace or collection, not only a repository's trunk code namespace, the Library shows the sources of the place in view, and a source is retired when its namespace is deleted or erased. The source ops no longer answer NOT_A_CODE_NAMESPACE; knowledge.source.add, rotate and sync_now answer NAMESPACE_INACTIVE for an inactive namespace and PERSONAL_NAMESPACE for a person's own collection or namespace.

Why

Sources lived only on a repository's trunk (is_trunk_namespace), so meeting notes and team documents, which have no repository, had no place to go. This implements the "Any namespace" section of docs/architecture/document-sources.md (#539), whose code names and intro this PR brings in line with what ships.

What changed

  • server/knowledge/app/sources.py:
    • The trunk check (is_trunk_namespace, _require_trunk_namespace, _source_in_repository) is deleted.
    • add refuses an inactive namespace, or a collection the collections tree no longer holds, with NAMESPACE_INACTIVE. It checks before the probe and again under the source lease, the second time with sequential reads.
    • add refuses a person's own place with PERSONAL_NAMESPACE: a col-me-… collection, a personal-… namespace, a namespace claimed at sign-up, a person's or an agent's (its directory row's owner is the namespace itself), or the u-… namespace single sign-on gives a person (personal_namespace.is_own_namespace checks the three name forms; one read of knowledge.store.sources.directory_row then covers both the sign-up claim and an inactive row). A user erasure erases what the person wrote, but a source's documents are the sync worker's (user_id -), so they would stay after it.
    • The registry-based race guard against code.repo.remove is gone. code.repo.remove deletes the namespace, and that delete now retires, under the lease, any source an add landed meanwhile.
  • knowledge.source.add is refused with ERASURE_RUNNING (409, retryable) while a namespace or namespace-list erasure that will still run may cover the namespace (ledger.open_namespace_erasures), checked before the probe and again under the source lease. The erasure step waits until no add holds any erased namespace's source lease before it reads the sources, so an add either lands before that read or sees the erasure. Upgrade step 13's second query also lists a source an older build added during a newer build's erasure, after its retirement, since the older build's add does not read the ledger (rule 44). The query drops its steps_completed filter for that, and the step says its list is a worklist acted on once, since a source removed in the cleanup stays listed.
  • A source ends with its namespace. These paths retire the namespace's sources: an inactive row with the credential cleared, under the source lease, taken before the account claim, as code.repo.remove takes them.
    • namespace.delete and collection.delete, through delete_namespace, even when there is no directory row.
    • A new step of a namespace erasure, knowledge_sources.retire (retire_sources_of), its first step, ahead of pg_memory.delete, so no mining turn writes a decision into what that step erased. It waits until no live holder keeps any erased namespace's source lease, reads their sources once, sequentially (sources_in: namespace and name, active or not), and takes the source lease only of namespaces that hold a source, to retire them. It then waits until no live holder keeps each source's sync turn lease (knowledge-source-sync:<org>/<ns>/<name>, read only, inactive names included, so a retried step waits too), waiting up to 30 seconds in all, the retirement's own lease wait included, so a turn that passed its last registry check before the retirement finishes before the later steps erase. A turn still running past that fails the step with OVERLOADED, and the saga's retries (erasure_recovery) wait it out; the short wait keeps the step inside a request behind the proxy and inside the recovery worker's pass.
    • Without this, a source would keep its sealed credential after its namespace is gone and write back what an erasure removed.
  • OverloadedError joins the erasure saga's failures of the moment, renamed _TRANSIENT_FAILURES. A busy lease in any step is retried like any failure of the moment, and its log line has no traceback.
  • server/knowledge/app/source_sync.py:
    • A pass drops only sources whose namespace is inactive.
    • It refreshes the repository registry once per pass. It still stops with RegistryUnread after its retirements while the registry has never been read.
    • _repo_tag tags repo:<id> only on a repository's trunk namespace (docs_namespaces).
  • Text and docs:
    • The wire model descriptions, the generated op tables and reference pages, docs/features/knowledge.md, docs/features/dashboard.md and the CLI help say "namespace".
    • Rolling-upgrade rule 44 is new.
  • Dashboard:
    • RepoSourcesList (RepoSources.tsx) becomes SourcesList (SourcesList.tsx), taking namespace and place: {label, noun}.
    • The Library shows it for the namespace or collection in view. On a collection only the collection's own role grants Add, since an admin claim reaches no collection; elsewhere the admin check is canCall("knowledge.source.add", …) on the header namespace's role.
    • knowledge.source.list answers accepts_sources, false wherever add would refuse the namespace (PERSONAL_NAMESPACE or NAMESPACE_INACTIVE, one predicate for both). On such a place the Library offers no Add, and shows the section only while the place still holds a source (one N-1 left active on a deleted namespace), whose menu then offers only Check and Retire; a viewer sees no section on a place with no source; a person's own namespace shows no Sources section. The dashboard keeps no copy of the server's name forms.
    • Both the Library and the repository card load it lazily, which keeps the index chunk under its budget.

Scope and risk

  • knowledge.source.remove with delete_documents=true also accepts a source a namespace delete already retired, so its documents can still be retired. Without delete_documents such a source answers SOURCE_NOT_FOUND, as before.
  • Who may call is unchanged. The gate requires admin for add, check, rotate, remove and sync_now, and viewer for list and inspect.
  • A source whose namespace stops being a trunk keeps syncing into that namespace, and its new documents carry no repo: tag.
  • _repo_tag reads the configured repositories once per document written and passes that list to docs_namespaces. It is not cached across documents: next to a ClickHouse write per document, one parse of the list is small.
  • PERSONAL_NAMESPACE goes by the name's form for personal-…, u-… and col-me-…, so a shared namespace registered under such a name is refused too; a self-signup namespace is told by its directory row.

Kept as is, with the reason

  • identity.app.collections.in_tree is a one-line wrapper because the package contract allows no cross-plane store import from knowledge.app; the directory row is read by knowledge's own store, as inactive_namespaces already did.
  • code.repo.remove still retires the namespace's sources itself, before the registry row, although its namespace delete retires them again: a call that fails between the two then leaves the repository registered to retry with its sources already stopped, and five of its tests pin that order. Its sources_deactivated is the union of both.
  • SourcesList is lazy-loaded with the same line in two views: the views use named exports only, and each lazy declaration is that view's own split point.

Compatibility, rollout and rollback

  • Wire:
    • NOT_A_CODE_NAMESPACE is no longer returned by knowledge.source.*; sync_now answers NAMESPACE_INACTIVE or PERSONAL_NAMESPACE as rotate does.
    • namespace.delete's output gains sources_retired, the sources it retired (also when deleted is false); collection.delete's sources are retired by its erasure's first step.
    • NAMESPACE_INACTIVE, PERSONAL_NAMESPACE and ERASURE_RUNNING are new.
    • This breaks a client that branched on the old code.
    • namespace.restore brings a deleted namespace back without its sources, which the delete retired with their credentials; an admin removes each with delete_documents=true and adds it again (docs/features/knowledge.md). Before this change a deleted namespace's source stayed active and synced nothing, since the sync skips an inactive namespace.
  • Rolling upgrade, rule 44:
    • N-1 refuses add, check, rotate and sync_now on a non-trunk namespace, and its worker skips such sources.
    • N-1's delete and erasure do not retire sources. After the rollout, an operator retires what N-1 left (upgrade step 13). loom erasure-re-verify runs no step.
    • The erasure step name knowledge_sources.retire is new in steps_completed.
  • Operator steps: once the newer build serves alone, a roll forward after a rollback included, follow the new upgrade step 13 (docs/operations/upgrades.md). It lists, with their queries, the active sources on namespaces an older build deleted and the sources registered before a namespace erasure an older build completed that were still active then (active, or retired after it). An erasure an older build started and the newer one finished needs no step: its final census reopens the steps for what the source wrote back. Remove those sources, or delete or erase those namespaces again.
  • Rollback: revert. Rows already written stay valid.

Tests

  • Unit, tests/unit/test_knowledge_sources.py:
    • A source is added and rotated on a plain namespace.
    • An inactive namespace is refused before the probe, and when it goes inactive during the probe. The re-check under the lease reads sequentially.
    • Personal names are refused (personal-…, the suffixed form, u-…, col-me-…), and so is a collection the tree no longer holds.
    • A namespace a person claimed at self-signup is refused (directory_row, run on clickhouse-local against a shared namespace, an agent's, an inactive one and one with no row).
    • sync_now refuses a source of an inactive namespace; the erasure step waits for a source an older build added between its read and its lease; add answers ERASURE_RUNNING while an erasure of the namespace runs, and not for an abandoned or replay-pending one.
    • knowledge.source.list answers accepts_sources false on a sign-up namespace, a personal name, a col-me-… collection and an inactive namespace, true on a shared one.
    • delete_namespace leaves the source inactive with its credential cleared. It takes the lease, then the claim.
    • The erasure step retires each namespace's sources over a namespace list and then waits for each source's turn lease to be free. Every erased namespace's source lease is watched, a namespace with no source too, and only namespaces with a source take it; an add holding the lease past the deadline fails the step; the step reads no source while the add holds on, and reads them once, sequentially, after it lets go. A turn lease still held past the deadline fails the step, the retry waits on it again, and the waits share one deadline (ManualClock).
    • test_the_erasure_step_waits_less_than_the_recovery_workers_pass: the step's wait stays under half the erasure_recovery pass deadline. The 30 s is _SOURCE_RETIRE_WAIT_S, marked not a setting with its reason.
    • test_pg_authority.py: under the Postgres authority a namespace erasure runs knowledge_sources.retire, then pg_memory.delete.
  • Unit, other files:
    • The erasure step trace (test_erasure_step_order.py).
    • test_a_busy_sources_lease_is_one_warning_line (test_erasure_backend_failure_logs_one_line.py).
    • _repo_tag tags trunk only, and a pass stops on RegistryUnread after its retirements (test_knowledge_source_sync.py, test_repo_snapshot_contract.py).
    • sources_in and the two step-13 queries on clickhouse-local (test_knowledge_sources_sql.py), a namespace_list erasure stored as a plain array included.
  • Vitest, Documents.sources.test.tsx:
    • The Library lists sources and offers Add to admins only, and a collection's own role decides, also for a token with an admin claim.
    • On a place the source list says takes no new source, no section shows while it holds none, and its active sources stay listed, with no Add, while it does.
    • A person's own collection makes no source read and shows no section; the repository card's list on a closed namespace with no source says it takes none, with no Add.
    • A viewer sees no section on a place with no source, nor when the list cannot be read, where an admin sees the error; an admin on an empty place that takes sources sees the section and Add; on a closed place a viewer sees the copy with no retire hint and no menu, and an admin's menu offers only Check and Retire.
  • Integration:
    • test_namespace_delete.py: namespace.delete and a namespace erasure.request each leave the namespace's source inactive with its credential cleared, and the erasure's steps include knowledge_sources.retire.
    • test_knowledge_sharing.py: collection.delete does the same for a collection's source.
    • test_knowledge_sources.py: a source on a namespace that is no repository's trunk serves check and sync_now, and add on a plain namespace reaches the probe.
  • Gates:
    • make lint and make typecheck pass.
    • The frontend's tsc -b, build, budget and full vitest suite pass.
    • The full unit suite passes, with test_deeply_nested_hidden_html_parses_in_bounded_time deselected, a timing test that also fails on main on this host.

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.

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

Checklist

  • make format-check, make lint and make typecheck pass, and the full unit suite passes on c116557 (the pushes after it change only docstrings, a message and docs, and the sources, error and docs tests pass on 17ef42b) with test_deeply_nested_hidden_html_parses_in_bounded_time deselected, a timing test that also fails on main on this host. The integration tests listed run in CI and were not run locally.
  • Generated files are regenerated in this PR, not by hand.
  • 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.
  • Repository text has no dates, people, host names, internal namespaces, ticket or decision numbers.
  • Commits are signed off (git commit -s), as CONTRIBUTING.md asks.

🤖 Generated with Claude Code

@zlareb1
zlareb1 force-pushed the feat/sources-any-namespace branch 2 times, most recently from 059801f to 594d039 Compare November 12, 2026 04:37
@zlareb1 zlareb1 changed the title Document sources live on any namespace, and the Library shows the sources of the place in view Document sources live on any shared namespace or collection, and the Library shows the sources of the place in view Nov 12, 2026
…Library shows the sources of the place in view

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: zlareb1 <[email protected]>
@zlareb1
zlareb1 force-pushed the feat/sources-any-namespace branch from e457f52 to 716ddd9 Compare November 12, 2026 12:47
zlareb1 and others added 6 commits November 12, 2026 12:55
…s deadline, and the design page names ERASURE_RUNNING and no longer describes trunk-only sources as current

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: zlareb1 <[email protected]>
…ing names every lease wait, a test shows it failing at its deadline while the retirement lease is held, and the design page's sentence is rewrapped

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: zlareb1 <[email protected]>
…a fresh lease wait; drop a comment the docstring repeats; refill the docstring and the design page's intro and Any namespace paragraph

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: zlareb1 <[email protected]>
…e code's history

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: zlareb1 <[email protected]>
…and the source error table lists it

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: zlareb1 <[email protected]>
…ace, in its docstring, message and docs, rewrapped

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: zlareb1 <[email protected]>
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