Skip to content

The SQL surface page says a grant is per namespace and serves all five views - #2211

Merged
zlareb1 merged 3 commits into
mainfrom
docs/sql-grant-per-namespace
Dec 5, 2026
Merged

zlareb1 merged 3 commits into
mainfrom
docs/sql-grant-per-namespace

Conversation

@zlareb1

@zlareb1 zlareb1 commented Dec 5, 2026 •

Copy link
Copy Markdown
Member

Related: #1232

Changelog category (leave one):

  • Documentation (changelog entry is not required)

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

Not required.

Why

The Access section of docs/reference/sql-surface.md does not say what one grant reaches. A team lead who wants session counts across members cannot tell from it that a grant on a member's personal namespace also serves that member's memories and conversation turns, or that the count has another route.

The section gains one paragraph, after the sentence on which rows a view admits:

  • A grant's scope is namespaces, never views: loom sql-access grant gives a user all five views (sql_v1_memories, sql_v1_memory_history, sql_v1_conversations, sql_v1_agent_events and sql_v1_usage_daily) over every namespace in its scope.
  • A grant on a team member's personal namespace therefore serves the memories, memory versions and conversation turns stored there, with that namespace's request ledger, except what the views never show.
  • A count of sessions across a team's members needs no such grant: run.list (role viewer) lists the runs of the namespace it addresses, each with its session_id, and its first page answers total.
  • A run is stored in the namespace its run.begin addressed, and an MCP session's own run in the caller's default namespace, whichever namespace its calls name: the runs stored in the shared namespace are listed there, under any member's token, and those stored in a member's personal namespace are listed there, under that member's own token.

The paragraph links to "A namespace a team shares" in docs/features/namespaces-and-sharing.md and to "MCP sessions" in docs/features/runs.md, and repeats neither.

Each statement was read in the code first:

Statement Where the code says it
The surface has five views, with these names server/insights/domain/sql_surface.py (VIEWS) and the five sql_v1_* views of schemas/schema.sql
A grant is keyed by user, org and namespace, and names no view loom.sql_access is ordered by (user_name, org, namespace) and has no view column (schemas/migrations/090_sql_surface.sql); loom sql-access grant takes --user, --org, --namespaces, --all and --rotate (server/cli/sql_access.py)
Every grant serves all five views grant_sql grants SELECT on each of VIEWS on every call, and each view admits the same scope rows (schemas/migrations/118_store_names_reserved.sql); tests/unit/test_sql_surface.py asserts both (test_a_new_user_is_granted_the_views_alone, test_every_view_scopes_and_excludes_alike)
What run.list answers server/tasks/app/run.py (handle_run_list) reads the runs of the addressed (org, namespace) at role viewer; RunRow carries session_id; total is counted when offset is 0
A run is stored in the namespace its run.begin addressed server/tasks/app/run.py (_open_run) writes the run row with input.org and input.namespace; server/tasks/store/runs.py (list_runs) filters on both
An MCP session's own run is stored in the caller's default namespace, whichever namespace its calls name server/transport/mcp_runs.py (ensure) opens the run with the namespace of the caller's defaults, and begin_session_run (server/tasks/app/run.py) writes the row there; _bind_caller_identity (server/transport/mcp_call.py) resolves those defaults with _caller_defaults, which takes the token and the client's name and no argument of the call; docs/features/runs.md ("MCP sessions") and docs/reference/mcp.md ("Implicit run") say the same
A member with a role on the shared namespace lists its runs run.list needs viewer, and Role orders viewer below writer and admin (server/operations/base.py)

Where the code differs from the statement this change set out to add, the page says what the code does:

  • No op grants the surface. The grant is the server command loom sql-access grant, so the paragraph names the command.
  • run.list counts runs, not sessions. total is the number of runs the filters match, and one session can hold several runs. The paragraph says that the op lists runs with their session_id and what total counts; it does not call total a session count.
  • total is null on a full page after the first, so the paragraph says the first page answers it.
  • A team's runs are not always in its members' personal namespaces. A run is in the namespace its run.begin addressed, and the coding plugin's run.begin sends the namespace it resolves from LOOM_NAMESPACE, then the namespace of config.json, then the token's first namespace that is not a wildcard, then coding (integrations/claude-code-plugin/lib/loom-client.mjs, scopeFor). A member granted a role on the shared namespace before a first sign-in also gets no personal namespace: ensure_personal_namespace_cached (server/auth/personal_namespace.py) provisions one only for a subject with no live grant. run.list on a namespace that holds none of a team's runs answers an empty list and no error, so the paragraph names the namespace by what holds the runs and gives both cases: the shared namespace, read under any member's token, and a personal namespace, read under that member's own token.
  • An MCP session's own run follows another rule. The session's first run-scoped call opens it, and the client sends no run.begin for it: ensure (server/transport/mcp_runs.py) begins it in the caller's default namespace, which a namespace named on the call does not change. The default is the caller's saved pick, then the namespaces the token names, then the caller's grants ranked by role (_pick_default, server/identity/app/caller_home.py). With no saved pick and a token that names no namespace, a member who holds admin on a personal namespace and writer on the shared one has the personal namespace as the default. That member's session can name the shared namespace on every call while its run is stored in the personal namespace: run.list on the shared namespace lists no run of that session and answers no error. handle_run_list filters on neither environment nor metadata.implicit, so the run is a row of run.list in the personal namespace, and a session of an MCP client that sends no run.begin has no other run. The paragraph states both rules and names the listed runs by where they are stored.
  • A scope can be a wildcard (* for every namespace of an org, --all for the deployment), so the paragraph says "every namespace in its scope".
  • The views withhold the value of a high row, a redacted value, rejected and deleted rows and every row of a restricted namespace. The sentence on a personal namespace links to "What the views never show".
  • docs/features/namespaces-and-sharing.md has no sentence on the SQL surface. Its one SQL statement is an insights.query call, an op that reads one namespace under the caller's token, so no link is added there.

Scope and risk

Touches one page: 17 lines added to docs/reference/sql-surface.md. No code, test, view, grant, op or generated page changes.

Left alone:

  • A view of runs on the SQL surface that can be granted alone: its own design.
  • docs/features/namespaces-and-sharing.md, for the reason above, and i18n/ (the translation workflow reads the English page after the merge).
  • The read-scope rules. run.list is refused to a token narrowed below the namespace (server/identity/domain/read_scope.py names it in neither SCOPED_OPS nor NARROW_SAFE_OPS), which docs/concepts/identities-and-namespaces.md states for every op that list does not name. A token carries the scope namespace unless it is minted narrower.

What could break: a statement that is wrong. Each was read in the code, as the table shows. No hook, op, stored row or permission changes.

Compatibility, rollout and rollback

  • Wire: no op, field, table, column, view, migration or setting is added, changed or removed.
  • Operator steps: none.
  • Rollback: a revert restores the previous text and leaves nothing behind.

Tests

No new test: the change is prose, and the existing docs tests cover links, anchors and public copy.

What ran at this head, with no ClickHouse and no server:

  • pytest -n 2 over tests/unit/test_doc_links.py, test_public_copy.py, test_help_docs.py, test_docs_reference.py, test_agent_instructions.py, the repository scans (test_package_contracts.py, test_op_transport_contract.py, test_tunable_constants.py, test_store_names_refused.py, test_degraded_unnoted.py) and tests/analyzer: 647 passed, 12 skipped.
  • npx prettier@3.9.9 --check docs/reference/sql-surface.md: pass. ruff format --check on the page, which formats the Python blocks in Markdown: pass.
  • python3 .claude/skills/loom-writing/scripts/check_prose.py on the page, each commit message and this description: no hit.
  • ruff check over the paths make lint gives it (server extractor sdk/python tests scripts .claude) and make typecheck: pass.

Run at the first commit and not again, since no module changed after it:

  • A one-line probe of the modules the table names printed the five VIEWS, one GRANT SELECT from grant_sql for each, the columns of a scope row (user_name, org, namespace, granted, updated_at), no op with sql in its name, and run.list with the output fields runs and total.

Not run:

  • make lint and make format-check as wholes. No check of make lint reads this paragraph: its generators render from code, and test_docs_reference.py covers the generated regions of docs/reference/. The two formatters that read Markdown were run on the page.
  • The statements against a live ClickHouse: tests/integration/test_sql_surface_live_ch.py covers the views and the grant in CI, and this change alters neither.
  • The documentation site build, the full unit suite and the integration suite: CI runs them.

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 paragraph, read each statement in the code and ran the checks listed under Tests.

  • 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.

Unticked: this change has no generated file, no migration, no shipped plugin file and no frontend file, so those four checks do not apply; the CLA line is the committer's to confirm. The first box is ticked with the gap named under "Not run": make lint and make format-check were not run as wholes.

🤖 Generated with Claude Code


Note

Low Risk
Documentation-only change to one markdown page; no code, permissions, or wire behavior changes.

Overview
Expands the Access section of docs/reference/sql-surface.md with a new paragraph clarifying how loom sql-access grant scopes work and how run/session visibility relates to namespaces.

The prose states that grants are namespace-scoped, not view-scoped: one grant exposes all five sql_v1_* views for every namespace in scope (including what a personal namespace holds, minus what the views never show). It also documents an alternative for cross-member activity: run.list at viewer role lists runs (with session_id) and returns total on the first page, without needing SQL surface access—with separate notes for runs in a shared team namespace vs a member's personal namespace, including MCP session placement. Links point to namespaces-and-sharing, run.list, runs/MCP, and the visibility exclusions section.

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

…ve views

A reader of the Access section could not tell what one grant reaches: that a
grant on a member's personal namespace also serves that member's memories and
conversation turns, or that a count of sessions across members has another
route.

docs/reference/sql-surface.md: `loom sql-access grant` gives a user all five
views over every namespace in its scope, so a grant on a personal namespace
serves the memories, memory versions and conversation turns stored there, with
that namespace's request ledger. A count of sessions across a team's members
needs no such grant: under each member's own token, `run.list` lists the runs
of that member's personal namespace with their `session_id`, and its first
page answers `total`.

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 5, 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 5, 2026 6:27am UTC
loom-telemetry Ready Ready Preview Dec 5, 2026 6:27am UTC

Request Review

zlareb1 and others added 2 commits December 5, 2026 06:09
The Access section sent a reader who counts sessions across a team to each
member's personal namespace. A run is stored in the namespace its `run.begin`
addressed, which for a team whose sessions address the shared namespace is the
shared one: `run.list` on a personal namespace then lists none of those runs,
with no error, and the count is short.

docs/reference/sql-surface.md: `run.list` lists the runs of the namespace it
addresses. The runs of the sessions that address the shared namespace are
listed there, under any member's token, and those of the sessions that address
a member's personal namespace are listed there, under that member's own token.

Signed-off-by: Mohammad Lareb Zafar <lareb.zafar@clickhouse.com>
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
An MCP session's own run has no `run.begin` from the client. The transport
opens it on the session's first run-scoped call, in the caller's default
namespace, whichever namespace the call names. A session that names a
shared namespace on every call can therefore have its run in a member's
personal namespace, and `run.list` on the shared namespace does not list
that run.

The Access paragraph of `docs/reference/sql-surface.md` states both rules:
a run is stored in the namespace its `run.begin` addressed, and a session's
own run in the caller's default namespace. It links to "MCP sessions" on
the runs page and names the listed runs by the namespace that stores them.

Signed-off-by: Mohammad Lareb Zafar <lareb.zafar@clickhouse.com>
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
@zlareb1
zlareb1 merged commit d8cb197 into main Dec 5, 2026
68 of 77 checks passed
@zlareb1
zlareb1 deleted the docs/sql-grant-per-namespace branch December 5, 2026 06:31
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