Skip to content

memory.inspect reports one user, agent or session's own rows apart from what it reads - #186

Merged
zlareb1 merged 29 commits into
mainfrom
feat/i160-inspect
Nov 3, 2026
Merged

zlareb1 merged 29 commits into
mainfrom
feat/i160-inspect

Conversation

@zlareb1

@zlareb1 zlareb1 commented Nov 3, 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):

memory.inspect (viewer, read-only) shows one user, agent or session of a namespace: the live rows filed under it (own) apart from every other live row it also reads (others), each with counts, tags, categories and its newest rows cited by memory_id, version and content_sha256; the calls the ledger files under it in a window; and the guide, categories and, for an org admin, the extraction policy that create its memories. It is in the assistant MCP toolset; a token narrowed below the namespace cannot call it.

Why

Issue 160 asks to inspect a user, agent or session and to keep what it wrote apart from what it can read. The existing reads blur the two: memory.list filtered on agent lists an agent's rows, but the agent name records the writer and is not a read boundary, so that list never stands for what the agent knows. Nothing read the guide revision, the categories and the extraction settings that shape a subject's memories in one place, and nothing said which of them a caller may not see.

What changes

  • server/memory/api/models_inspect.py, ops_inspect.py: memory.inspect, subject (user, agent or session) and id; the unset - and * are refused. sample_limit (default 10, at most 50) and window_seconds (default 7 days, 1 hour to 90 days). Viewer, idempotent, not audited, so read_only and served on the read-only MCP surfaces.
  • server/memory/store/inspect.py: the reads, each on the (org, namespace) prefix of its table's sort key; the subject's column is one of three fixed names and the id is bound. namespace_report_hash_max_bytes now also bounds the values memory.inspect reads to cite a hash.
    • Per view (own: the subject's column equals id; others: it does not): counts by type, status and source class with the first and last update; the 20 most used tags; the registered categories its rows are filed under (loom.memory_categories); the newest rows with key, memory_id, version, identity, actor, sensitivity and a 200-character excerpt. Their content_sha256 comes from the reports' citation read (revisions_for, as namespace.audit cites, with each row named by its whole identity so the primary index prunes the read): the hash memory.get serves, which differs from the stored column for an object with a null field, so an if_match_sha256 taken from it matches. It is empty for a high-sensitivity row (a short secret's hash can be guessed; memory.list withholds it too), for a value past namespace_report_hash_max_bytes, and for a row revised between the two reads. A high-sensitivity row has no excerpt either.
    • Every read of memory rows that selects them takes the request's read scope (scope_and), as the read-scope rule asks of each store reader, though a narrowed token is refused before the handler; the preview and version reads are keyed by the ids those reads returned. The newest rows are located without value, then their value_preview is read by (memory_id, version) without FINAL, as memory.list does: one statement under FINAL would read every row's value before its limit. A preview of a value longer than the 2,048 bytes it keeps (value_len > 2048) is closed and decoded, dropping a cut escape or half of a surrogate pair; an uncut one is decoded whole or kept as it is.
    • Neither view counts promoted rows (memory.promote, loom.shared); each definition says so. The second view is others, not shared, since Loom names the promoted layer that way.
    • The versions loom.memory_versions holds for each listed row (uniqExact(version), so a duplicate not yet merged away counts once; the entity tagger's re-emits are counted, which memory.history leaves out, and the field says so).
    • The calls loom.agent_events files under the subject, one entry per operation with its calls and the ones that succeeded, leaving out worker rows and the dashboard's and the assistant's calls (INSPECTOR_CONSUMERS). The ledger files a call under the agent, user_id and session_id its arguments name, or the user and session a narrowed token is pinned to, so a call by anyone that names the subject is counted (an agent's own mentor.brief included), and a served memory.inspect, which names none, is not; the docs and the description say "the calls the ledger files under the subject".
  • server/memory/app/inspect.py: each section's read is guarded; a failure lands in skipped as section: error type, and a skipped section is not an empty one. settings reads the guide (revision, summary) and categories through their handlers, and the operator extraction policy only when row_in_scope grants the caller org admin (extraction_policy_unavailable says why otherwise; a grant read that fails makes row_in_scope refuse, and a refusal this check could not verify (fail_closed.unreadable(), cleared just before it, since a clean refusal restores a note an earlier check left) is reported in skipped with its own reason, not as a non-admin's). It says that extraction instructions are per request: no user, agent or session setting stores them. activity.gap names a ledger that keeps fewer days than the window, judged by the namespace's own retention_days (which sets its ledger's TTL) before the deployment's, as mentor.brief does. Both read it through one accessor, server.identity.app.registration.namespace_retention_days, over the directory row; mentor.brief's own copy of the statement in server/insights/store/mentor.py is removed; an unread retention is skipped and claims no gap. A view whose counts read failed reports complete: false.
  • server/operations/toolsets.py: memory.inspect joins the assistant toolset; server/transport/mcp_descriptions.py gives it a description.
  • server/identity/domain/read_scope.py is unchanged: memory.inspect is not a scoped op, so a token with read_scope own_user or own_session is refused. A pinned user would read the rest of the namespace through others.
  • server/insights/app/op_mix.py classes it as a read; OP_BUDGETS_P99_MS gives it 3000 ms.
  • docs/features/namespaces-and-sharing.md: a row in the operations table and a section on what each view holds.
  • SDKs and the operations reference regenerated.

Scope and risk

  • Measured locally (system.query_log):
    • 200,000 short live rows in one namespace across 20 agents, 500 users and 5,000 sessions: one call runs about 27 statements (eight per view, two of them the citation read; the ledger; the namespace's retention; the reads behind the guide, the categories and the access check) reading about 990,000 rows and 41 MiB in all, 43 MiB peak for the largest, 245–290 ms wall time. The citation read names each listed row by its whole identity, the table's sort key, so it reads 1,000–4,700 rows (35–106 KiB) per view, not the namespace.
    • 2,000 rows of 20 KB incompressible values: one call reads about 20 MiB in all, 9.1 MiB peak, 150–240 ms. Most of it is the citation read's served-hash statement, which decodes whole granules of value for the listed rows (at most namespace_report_hash_max_bytes each): 2.5–16.5 MiB per view, against 84 KiB to locate the rows and 1.4 MiB for their previews. One statement reading value under FINAL to list them took 14 MiB.
    • Each view reads the namespace's live rows once per section (FINAL on loom.memory, no value), so the cost grows with the namespace's row count, not the subject or the size of its values.
  • It changes nothing it reads: no recall credit and no memory row; the integration test compares loom.memory's row count before and after. Its one write is the exposure-ledger row below, which inside a run can feed the usage fold's acted credit, as memory.list's does.
  • A row's excerpt is served to a viewer of the namespace, who reads the same rows through memory.list; a high-sensitivity row's excerpt and hash are empty, as on memory.list.
  • Each call that lists rows writes one exposure-ledger row (loom.memory_exposures, operation memory.inspect) with the listed keys, as memory.list does, so walking a namespace's subjects is counted in a token's read breadth.

Compatibility, rollout and rollback

  • Wire: one op added (memory.inspect, maturity experimental). Nothing removed or changed.
  • During a rolling upgrade a replica one release older answers UNKNOWN_OP for it, and its assistant listing does not carry it.
  • Operator steps: none.
  • Rollback: revert; the only rows it leaves are exposure-ledger rows, which expire with that table's TTL.

Tests

  • Unit (tests/unit/test_memory_inspect.py): the sentinel ids are refused; the op is a viewer read_only op; own and others filter on the subject's column with the id bound, each with its subject's definition; a view counts, lists and cites, the excerpt read from the listed version's preview only; a cut preview decodes; a view whose counts failed is not complete; sample_limit: 0 reads no rows; activity leaves out the inspectors and names the retention gap, the namespace's own retention winning over the deployment's, and an unread retention claims none; the extraction policy is read only for an org admin; an unreadable grant (the real row_in_scope over a check that notes the failed read and refuses) withholds the policy, lands in skipped with its own reason and marks the request the server's; an org admin whose policy read fails is told "the policy could not be read" and the section is skipped; while a failed read an earlier check noted is not blamed on a clean refusal; a high-sensitivity row lists no excerpt and no hash; a row revised between the two reads is listed without a hash; each of the four reads that select rows applies its scope; the listed keys go to the exposure ledger, and a call listing none writes no row; a failed section is skipped, not raised.
  • Integration (tests/integration/test_memory_inspect.py, private ClickHouse and server with auth on): three agents (one writing a high-sensitivity row) and two users; inspecting the agent splits its two rows (own) from the other agent's one (others), inspecting the user splits its row from the rest, and inspecting a session that holds a row splits it the same way; a high-sensitivity row is listed with no excerpt, no hash and sensitivity: high; an object value with a null field is cited with the hash memory.get serves; the listed row's memory_id and content_sha256 equal memory.get's and its versions equals the versions loom.memory_versions holds; tags, a registered category filed on the row, the guide revision and the category count read back; the extraction policy is unavailable to a writer; the agent's activity is exactly the calls that name it (two memory.set, one memory.get), none of the inspections; nothing is written to loom.memory, and the exposure-ledger rows for the namespace hold the keys listed; a token pinned with read_scope: own_user and a token for another namespace are both refused with 403.
  • tests/integration/test_cross_principal_leakage.py lists memory.inspect among its core surfaces; the walk now builds a Literal field from its values when the shared hint is not one of them, so the op is probed with a tenant B token against tenant A's data. It passes, as does the assistant toolset suite.
  • Analyzer corpus (tests/analyzer): a memory_inspect case drives every store read for each subject, both views and a narrowed scope; tests/analyzer/shapes.txt gains its 53 shapes, and the analyzer passes them against a migrated ClickHouse.
  • make format-check lint typecheck, the unit tests above and the generator checks.

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 against the tables it reads on 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, and no other open PR uses that version. (No plugin change.)
  • 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 29 commits November 3, 2026 06:43
…om what it reads

A read-only viewer op: the live rows whose user_id, agent or session_id names the
subject (own) apart from every other live row of the namespace (shared), each with
counts, tags, categories and the newest rows cited by memory_id, version and
content_sha256; the subject's own ledger calls in a window, without the dashboard's
and the assistant's; and the guide, categories and, for an org admin, the extraction
policy that create its memories. It is in the assistant toolset; a narrowed token
cannot call it.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: zlareb1 <[email protected]>
…second view others

The newest rows are located without the value, then their value_preview read by
(memory_id, version), as memory.list does. The second view is `others`, since
`shared` names the promoted layer, which neither view counts. A view whose counts
failed is not complete; versions are counted distinct; the activity text says the
calls are the ones the ledger files under the subject.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: zlareb1 <[email protected]>
A preview cut between the two escapes of an emoji decoded to a lone surrogate, which
the UTF-8 response refused. The counts read signals failure by its value; `versions`
says it includes the entity tagger's re-emits; the budget comment counts the reads;
the integration test inspects a session that holds a row and checks `versions`
against the history table.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: zlareb1 <[email protected]>
…y a cut preview as cut

An uncut preview that began with a quoted word lost its tail to the cut handling; the
preview read now says whether the value was longer than its preview. Activity is one
entry per operation with its calls and successes. Every output field has a
description; equal counts sort by name; the unit test's category stubs reach the
catalog handler.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: zlareb1 <[email protected]>
…at module top

The activity docstring opens with a whole sentence, which the SDK keeps; the two unit
tests that build their own fake also serve the catalog handler.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: zlareb1 <[email protected]>
An inspection names no agent, user or session, so the ledger never filed it under the
subject and leaving it out did nothing, while leaving out mentor.brief hid an agent's
own brief. The integration test waits for the exact calls that name the agent.

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

A failed grant read skipped the whole report; it now lands in `skipped` and the policy
stays withheld. The activity text names the narrowed token's pinned user and session,
which the ledger files a call under too.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: zlareb1 <[email protected]>
A namespace's `retention_days` sets its ledger's TTL and replaces the deployment's, so
the gap used the wrong number for any namespace that sets one. The docs name what `own`
holds for a session.

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

The SDK surface snapshot gains `inspect`.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: zlareb1 <[email protected]>
row_in_scope refuses when the grant read fails rather than raising, so the report told
an org admin they were not one. The refusal it could not verify is read from
fail_closed and lands in `skipped` with its own reason.

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

The check-level reset was redundant: the authorization check clears it on entry.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: zlareb1 <[email protected]>
A clean refusal restores a note an earlier check in the request left, so without the
reset a non-admin was told their access could not be read.

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

A short secret's hash can be guessed, so a high-sensitivity row is listed with neither
excerpt nor hash, as memory.list lists it. Each call that lists rows writes one
exposure-ledger row with their keys, so walking a namespace's subjects is counted.

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

The stored column differs from the served hash for an object with a null field, so the
listed hash now comes from the reports' citation read, empty for a high row, a value past
the hash bound or a row revised between reads. Rows carry `sensitivity`. Every read of
memory rows takes the request's read scope. The texts that said nothing is written name
the exposure-ledger row.

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

The citation read by memory_id scanned the namespace's live rows again; by the whole
identity it reads only the listed rows' granules. The texts name the usage fold's
`acted` credit an exposure row can feed, and every reason a hash is empty.

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

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]>
…'s count

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: zlareb1 <[email protected]>
The unit test also checks that the citation read takes the request's scope.

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

identity.app.registration.namespace_retention_days reads it from the directory row; the
two store copies are gone. The citation read alone withholds a high row's hash, the
activity text names the worker rows it leaves out, and an admin whose policy read fails
is tested.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: zlareb1 <[email protected]>
Each read is driven for every subject, both views and a narrowed scope; the corpus gains
their shapes. Docstrings name the three agents and what other domains read from
identity's namespace directory.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: zlareb1 <[email protected]>
Two rows of one key written in the same second listed in either order at the limit;
memory.list breaks the tie the same way. The exposure row's top_k is the most rows a
call lists.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: zlareb1 <[email protected]>
…reak is tested

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: zlareb1 <[email protected]>
memory.bulk_set declares no such field.

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

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: zlareb1 <[email protected]>
@zlareb1
zlareb1 merged commit 6d4594f into main Nov 3, 2026
21 of 22 checks passed
@zlareb1
zlareb1 deleted the feat/i160-inspect branch November 3, 2026 07:07
@pufit pufit mentioned this pull request Nov 4, 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