Skip to content

namespace.inventory reports what a namespace holds, with members apart from the identities seen on its rows - #170

Merged
zlareb1 merged 24 commits into
mainfrom
feat/i160-inventory
Nov 1, 2026
Merged

zlareb1 merged 24 commits into
mainfrom
feat/i160-inventory

Conversation

@zlareb1

@zlareb1 zlareb1 commented Nov 1, 2026 •

Copy link
Copy Markdown
Member

Related: #160

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):

namespace.inventory reports what a namespace holds and who appears in it: live counts and newest write for memories, records, documents, runs and integrations, the member count, and the agents, authors and subjects observed on memory rows, each labeled complete: false with a reason when it was not counted. Under a read scope bound to one user, the memory and run counts and the observed agents, authors and subjects are that user's; documents and members are counted namespace-wide, and records and integrations are not counted. /v1/health now reports fake_embedding (and so providers_degraded) for a keyed embedding model with no key and for LOOM_EMBEDDING_PROVIDER=fake, which are served by the fake embedder.

Why

Issue 160's "What is in this project?" and "Who are the users in this project?" starters need one read that answers with counts and freshness per plane and says which sections are missing, and that keeps registered members, row authors and memory subjects as separate populations. namespace.summary counts memory types and recent activity only, and nothing today reports documents, records, runs or members beside memory, or names what a caller could not see.

namespace.inventory (viewer, read-only, experimental) composes existing tables; it adds no storage:

  • Sections: memories (loom.memory, the rows a read serves: not tombstoned and in a served status, through served_status_sql, the definition the search legs use, so a duplicate, superseded, proposed or rejected row is not counted; a row past expires_at or valid_to is served by memory.list and memory.get until the sweep, so it counts (search leaves it out). memory.list's default page also keeps rejected rows, which is left as it is here: its repository functions serve other callers with every status. The observed populations read the same rows), records (loom.memory_records, active rows: a rewritten record keeps its earlier version as a superseded row, and the record reads serve active rows only), documents (loom.documents, current versions), runs (loom.agent_runs), integrations (loom.memory_webhooks, not removed). Each carries count, latest_at (None when empty) and complete. Each count is read through the plane that owns its table (memory.app.query.memory_tally, memory.app.records.record_tally, knowledge.app.document_reads.document_tally, tasks.app.run.run_tally, memory.app.webhooks.webhook_tally, a count statement in server/memory/store/webhooks.py that reads no URL or secret), so each table's liveness rule stays in its own store, and the observed identities come from memory.app.query.identity_tally. The observed identities are read from the memory store, not from a store of the identity plane's own.
  • Populations: members counts the grant holders, the people holding an active grant, folded as grants.list folds them (server/identity/store/grants.py::member_count counts over grants.list's own statement, with the namespace predicate widened to a lineage). For a col- collection the lineage is the collection and its ancestors (from the cached tree), since a parent's grant reaches every child, so a child's count includes the people its parents grant. A pending join request alone, a group, an agent and a service account are not people and are not counted. A grant to everyone, a group or an agent (every end user signed in under that agent) anywhere on the lineage, or a code namespace marked readable by the whole org (authz.is_org_readable_code_namespace, now public), widens who can read without naming them, so the count is then complete: false with that reason; a personal collection, whose owner holds no grant, is not counted. The subject kinds come from server/core/principals.py (a SERVICE_ACCOUNT constant is added there) and match lowercase. grants.list on the namespace (and, for a collection, on each ancestor) lists those grants. A token whose own claims name the namespace reads it without a grant and is never counted; the count is of grant holders, not of everyone who can read. agents, authors (the server-stamped actor) and subjects (user_id) are distinct values on live memory rows, each with its total and the largest population_limit by row count. subjects never includes the unset -.
  • Capabilities: whether a real model and a real embedder serve the process that answered (each replica reads its own settings and keys), so a client can tell whether model-backed steps are available. /v1/health and this op read it through the same two helpers (the embedder_key_missing health problem keeps its own key check: loom doctor runs it before boot from the keys and environment it is handed, not the process's), server.llm.client.llm_is_fake and server.embedding.embedder.embedder_is_fake. The embedder helper uses the condition the embedder factory falls back to the fake on (_key_missing, shared with _served): a fake model or LOOM_EMBEDDING_PROVIDER=fake, or a keyed provider without its key. /v1/health's fake_embedding therefore now also turns true in two cases it missed: a keyed embedding model with no key, and LOOM_EMBEDDING_PROVIDER=fake over a model name that does not start with fake. Both are what the process serves, and the first is what its docstring already promised; providers_degraded follows it. A model name no provider serves (provider_for raises) reads as not fake, as before: building its embedder fails, so no fake serves it, and health and the inventory still answer.
  • Each section and population runs as one task of an asyncio.TaskGroup, on its own (one helper, _attempt, decides how a read fails; the outage errors are one tuple, server.core.errors.BACKEND_NOT_NOW, which the sharing gate now also reads): a failed read is logged and is complete: false with read failed: <error type>, and the rest still answer. A store that is down, past its deadline or overloaded fails the whole call with its usual error, as any read does, and cancels the other legs' reads, so an outage is never answered as a successful report of empty sections.

Access: the integrations count is shown only to a namespace admin, as webhook.list is admin-only. When that check could not read the grants (an unverified refusal), the section reads read failed and the request is marked the server's failure (note_answered_unverified), as row_in_scope does; the rest still answer. The op is classified in SCOPED_OPS: under a token pinned to one user, or a request with read_scope=own_user / own_session, every memory and run count, and each observed population, carries the scope's user (and session) predicate. Documents and members are counted namespace-wide under any scope, as the knowledge.* ops and grants.list (which a narrowed token may call) read them. Records and integrations are not read and are reported as not counted: a record key holds one active record whoever wrote it last (no memory.record.* op serves a narrowed token), and webhook.list is refused to a narrowed token. A namespace-wide caller narrows to one user with read_scope=own_user and user_id, which the "Analyze one user's memories" starter needs.

Scope and risk

  • Read-only; nine concurrent aggregates (for a col- collection the members leg first reads the cached tree), each filtered on (org, namespace), the key prefix of every table read, except two org-wide reads the member count shares with grants.list and the sharing checks: the alias join of grants.list's statement reads loom.namespaces FINAL by org, and a col- collection's tree comes from the grant cache (loom.collections by org). The observed populations are one GROUP BY over live memory rows each, the most expensive of the nine. Budget: 800 ms p99.
  • Measured locally on a private ClickHouse, one namespace of 300,000 live memory rows (20 agents, 50 authors, 1,000 users), six calls: 57–162 ms end to end. In system.query_log each of the three population statements and the memory count reads 300,000 rows; the population statements take 30–37 ms at the median and at most 153 ms (the first, cold call), with at most 9.1 MiB of memory; the member count takes 71 MiB at its peak on the grant folding, over an empty grants table. That is the folding statement's own cost: grants.list's page statement peaks at the same 71 MiB, and the count with the page's two sorts and its limit removed peaks at 68.5 MiB against 68.5 MiB with them, so reusing the page statement adds nothing measurable.
  • experimental, so it is not listed under ?toolset=all; over MCP it is reachable through loom_op. It joins the assistant MCP toolset (a separate open change) after both merge.

Compatibility, rollout and rollback

  • Wire: one new op, namespace.inventory. No existing op or field changes.
  • Operator steps: none.
  • Rollback: revert; nothing is stored.

Tests

  • Unit (tests/unit/test_namespace_inventory.py): every plane and population counted namespace-wide; under own_user every memory and run statement binds the user, documents and members are counted namespace-wide, and records and webhooks are never read; under own_session every statement binds the session; a failed read is labeled and the others answer; integrations are not read for a non-admin, an unverified admin refusal reads read failed and marks the request the server's, and any other admin-check error is labeled too, leaving the other sections complete; a grant to everyone, a group or an agent leaves the member count incomplete with its reason, a collection's count is taken over its whole lineage in one statement, the lineage statement binds both of its grant reads, a personal collection reads no grants, an org-readable code namespace leaves the count incomplete, and a plain namespace never reads the collection tree; a store outage fails the call and cancels the other reads; a zero population_limit keeps the totals; the capabilities follow the two fake-provider helpers. test_read_scope_admission.py holds the three new scoped readers (reads.live_tally, reads.identity_tally, runs.run_tally) to a required scope argument. The analyzer corpus (tests/analyzer) now runs the inventory handler, so its nine statements are in shapes.txt, and the grants case adds the member count over a lineage. test_embedder_is_fake.py: the helper agrees with the embedder _served builds for a fake model, a fake provider, a keyed model without its key and one with it, and a model no provider serves reads as not fake. test_health_problems.py: the likely-cause case now gives its real embedding model a key, since without one the process serves the fake, and a keyed model without its key reads fake_embedding and providers_degraded.
  • Integration (tests/integration/test_namespace_inventory.py, private ClickHouse and server): memory rows for two users and the unset user, one document, one record written twice, a run for each user, one webhook, grants for two people (one under two spellings), one pending join request, one revoked grant and one service-account grant, and stored duplicate, superseded, proposed and rejected rows plus one row past its expiry; the namespace-wide inventory counts five memories, one record, one document, two runs, one integration, two members (complete), two subjects with the unset user left out, the writing agent and the stamped author; a viewer token gets every section but integrations; a token pinned to one user counts only that user's two rows and its one run, reports records as not counted, names that user alone as a subject, counts the namespace's document and its two members, and reports integrations as not counted; a namespace-wide token asking for read_scope=own_user gets that user's counts; a population limit of 1 lists one subject and keeps the total of two; four collections created through the ops (creator service-account grants on each): a root granting one end user counts one member, complete; its child granting another counts both, complete; a collection granting an end user and an agent counts one, incomplete; one granted to everyone counts none, incomplete; an empty namespace reports every plane at 0 with no write time (if(n = 0, NULL, max(...)), not the epoch) and empty observed populations.
  • make format lint typecheck, make test-unit.

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 each statement's scope predicate, the admin gate and the integration run against a live server.

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

Checklist

  • make format-check, make lint, make typecheck and make test-unit pass; the integration suite passes if server behaviour changed.
  • Generated files are regenerated in this PR, not by hand.
  • A new migration is additive and numbered after the latest on main; no merged migration is edited. (No migration.)
  • A behaviour change to any file a plugin ships bumps both plugin manifests' version. (No plugin file.)
  • The frontend builds (npm --prefix frontend run build) and its tests pass, if frontend/ changed. (No frontend change.)
  • 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.
  • Commits are signed off (git commit -s), as CONTRIBUTING.md asks.

🤖 Generated with Claude Code

zlareb1 and others added 16 commits November 1, 2026 15:39
…served identities

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: zlareb1 <[email protected]>
… has its description

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: zlareb1 <[email protected]>
…ake providers for health and inventory

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: zlareb1 <[email protected]>
…eir planes, and reports an unreadable admin check as the server's

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: zlareb1 <[email protected]>
…tage, and counts personal and inherited collections honestly

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: zlareb1 <[email protected]>
…any scope, and survives an unknown embedding model

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: zlareb1 <[email protected]>
…e counted by a statement in their store

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: zlareb1 <[email protected]>
…tuses); one live-record rule in the record store

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: zlareb1 <[email protected]>
…oin the analyzer corpus

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: zlareb1 <[email protected]>
…te; field comments say which counts the scope bounds

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: zlareb1 <[email protected]>
…ays how it reuses the page statement

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: zlareb1 <[email protected]>
…bers are named as grant holders; one run tally statement

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: zlareb1 <[email protected]>
…s as scoped

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: zlareb1 <[email protected]>
… one tuple in core.errors

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: zlareb1 <[email protected]>
…tested for no write time

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: zlareb1 <[email protected]>
@zlareb1
zlareb1 force-pushed the feat/i160-inventory branch from a24c8e9 to 55dbdcb Compare November 1, 2026 15:39
zlareb1 and others added 8 commits November 1, 2026 15:51
…eeps its total, tested on real SQL

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: zlareb1 <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: zlareb1 <[email protected]>
… holds grants

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: zlareb1 <[email protected]>
…n one statement; a failed admin check stays in its section

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: zlareb1 <[email protected]>
…cstring names agent grants

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: zlareb1 <[email protected]>
…age; any_live_grant is gone

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: zlareb1 <[email protected]>
… checks its reason

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: zlareb1 <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: zlareb1 <[email protected]>
@zlareb1
zlareb1 merged commit 0d98eb3 into main Nov 1, 2026
21 of 22 checks passed
@zlareb1
zlareb1 deleted the feat/i160-inventory branch November 1, 2026 17:37
@pufit pufit mentioned this pull request Nov 2, 2026
9 tasks done
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