Repository navigation
Conversation
zlareb1
force-pushed
the
feat/i160-doc-inspect
branch
from
November 4, 2026 03:11
e81a4c1 to
60893a9
Compare
zlareb1
force-pushed
the
feat/i160-doc-inspect
branch
from
November 4, 2026 03:22
fb046d6 to
170c97f
Compare
7 of 9 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Related: #160
Changelog category (leave one):
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):
knowledge.inspect(viewer, assistant toolset) reports a namespace's documents: counts by format, source scheme and revision, which live chunks search can serve, the newest documents with their chunks and the decisions cited from them (decided apart from proposed), findings on chunks that search cannot serve, andnamespace.audit's findings on memories shaped like documents.Why
Someone investigating a namespace, or an assistant acting for them, has no single read that answers "which documents are here, which versions are searchable, and what was extracted from them".
knowledge.listpages documents,knowledge.getreads one, and the audit's document-shaped memory findings sit in another report. This op composes what is already stored into one bounded, read-only report. It never parses a document.What it reads:
loom.documentsFINAL on the(org, namespace)prefix: live and deleted documents grouped by format (stored content type, else the extension of the original filename or thesource_uripath, host excluded) and bysource_urischeme, plus the newest live ingest.loom.chunk_supersessions: retired versions, counted once per(source_uri, doc_version).loom.chunksunder the shared live-chunk predicate: live chunks per embedding model, how many carry a vector (embedding_dim > 0), andsearchable, meaning under the server's model with a vector.knowledge.searchreads exactly these.kind,rule_version,source_op,population,sample_limit,samples_complete,exceptions,uncertainty). A clean check is reported atinfowith count 0:documents_without_chunks,unembedded_chunksandchunks_under_other_modelaresystem_state: the server's own state.chunks_under_other_modelcounts documents with live chunks and none under the server's model, so a document whose chunks are under the server's model without a vector isunembedded_chunksonly, and agrees with the listing'sother_model. The remedy isloom rechunkorknowledge.upsert.mixed_live_versionsis ausage_heuristic: live chunks of two versions of one document.sample_limitlive documents, each with its version, retired versions, live chunks (searchable, unembedded, other model, distinct versions, min/median/max characters, models) and decisions.decision(or tagged so) whosesource_resource_idcitesknowledge:<namespace>/<uri>#<section>, asloom decisions extractanddecision.recordwrite it. They are reported by stage, per listed document and for the namespace:decided, andproposed(recorded withstage="proposed", taggeddecision:proposed; the extractor records a proposal's decisions this way). Each stage counts confirmed (pinned, or attested in its current content), unconfirmed,source-changedand outcome known. A pin on a proposal confirms the proposal's wording, not a choice, so it is never counted with the decided rows. A citation goes to the longest document URI it starts with, sodoc#v2#Introcounts fordoc#v2, neverdoc, whether or notdoc#v2is listed. One bounded read ofloom.documents(sort-key column, at most 1,000 URIs, flagged inskippedpast that) finds the documents, live or deleted, that extend a listed one with#. They go to the decision read with the listed URIs. A row under a longer unlisted document counts only in the namespace total.namespace.audit, called in process withsample_limit=0asnamespace.tunecalls it. Itsoversized_valuesandepisodic_blobsfindings are cited by code, kind, severity, rule version and count. The audit's own samples and evidence stay in the audit.namespace.audit's own reason for a rule it skipped is carried intoskippedasmemory_findings.<code>: <reason>.Each section is guarded. A failed read lands in
skippedas<section>: <ExcName>and its fields stay null or empty. A store outage (BACKEND_NOT_NOW) fails the call, asnamespace.inventorydoes.Design calls:
SCOPED_OPS. Documents and chunks are the namespace's under any scope, as everyknowledge.*read serves them. The decision rows are memory rows, so they are read withscope_and. The audit reads every user's rows and is not itself served to a narrowed token, so under a narrowed scopememory_findingsis skipped and says why. Listing the op explicitly inSCOPED_OPS, rather than leaving it under theknowledge.narrow-safe group, records that it reads memory rows.loom.memory, so it lives in the memory plane's store (server/memory/store/document_decisions.py, throughmemory.app.query.document_decision_tally), not inserver/knowledge/store/. The table's owner keeps its statements, asnamespace.inventoryreads memory throughmemory_tally. It reusesattested_sqlandserved_status_sql.has(tags, 'decision:proposed'). Counting per stage keeps every count meaningful for a proposal, rather than adding aproposedcount beside totals that mix the two.mentor.brief'sdocuments_as_memoriesis per agent. A namespace report has no agent to ask about, and calling the mentor once per writing agent would cost one ledger scan each. The audit'soversized_valuesis the namespace-wide count of the same shape, and the output names the mentor hint as its per-agent counterpart._REPORT_OPS.knowledge.inspectjoins the audit's report-op list, asmemory.inspectandnamespace.tunedid, so its own ledger rows do not close a telemetry gap.telemetry_unavailablegoes to rule version 3.Findings about what main stores (stated here, not worked around):
loom.documentsisReplacingMergeTree(version)keyed on(org, namespace, source_uri), so it holds only a document's current version.superseded_aton that row means deleted, not revised. Earlier versions survive only as retired chunk ingestions. "Superseded versions" is therefore reported asretired_versionsfromloom.chunk_supersessions. That count includes the version a delete retired, and an earlier version's title or metadata is not recoverable.knowledge.addon an existingsource_uriwrites a new version without retiring the earlier one's chunks, so search serves both texts.knowledge.upsertretires them. This was verified on a live server, andmixed_live_versionsreports it.loom reembedcovers memory only;loom rechunkis the remedy for documents.memory.pinwrites the row it is given. Pinning a decision without passing itsmemory_type,tagsandsource_resource_iddrops its citation and its decision type. The integration test passes them.Scope and risk
New files:
server/knowledge/api/models_inspect.py,server/knowledge/app/inspect.py,server/knowledge/store/inspect.py,server/memory/store/document_decisions.py.Small edits: the op declaration (
ops_knowledge.py),MCP_ASSISTANT_OPS, the MCP description,OP_BUDGETS_P99_MS(4000 ms, with a comment naming the reads),SCOPED_OPS, the audit's_REPORT_OPSand its rule version, and the feature and MCP reference docs.Tenant isolation: every statement filters on
(org, namespace)with bound parameters. The decision read takes the request scope. The cross-principal walk includes the op in_CORE.Nothing is written: no ledger exposure row, since the op lists document URIs and not memory rows. The integration test checks that
loom.memoryis unchanged.Statement shapes: the per-document chunk read measures chunk text (
lengthUTF8(content)) for the listed documents only. No statement reads a document's text.tests/analyzer/shapes.txtis regenerated. Besides the op's ten new shapes, it picks up onememory.for_fileshape that main's file had not caught up with.Compatibility, rollout and rollback
knowledge.inspect(experimental, viewer, read-only, not audited). Input:org,namespace,sample_limit(0–100, default 20). No field of any other op changes. A build one release older answers it as an unknown op.Tests
tests/unit/test_knowledge_inspect.py(28 tests on fakes) covers:listed_complete,sample_limit=0, and the audit citation;skippedwith null fields, the decision and audit reads failing, an unbuildable embedder, and the group cap;skipped.tests/unit/test_knowledge_inspect_sql.py(10 tests, clickhouse-local, realschema.sqltables) covers:join_use_nullsvalues;doc#v2fordoc;tests/integration/test_knowledge_inspect.pypasses against a private server with auth off and with auth on. It writes:knowledge.upserttwice) and a page written twice withknowledge.add;source-changed) and one proposed row (stage="proposed"), each stage checked on every count.It then checks every section, then that a narrowed token reads documents with
memory_findingsskipped, and that a foreign token gets 403.Cross-principal walk with auth on:
test_cross_principal_leakage.py,test_restricted_namespace_leakage.pyandtest_read_scope_isolation.pygive 67 passed, 17 skipped; rerun after the stage change with this op's integration test, the leakage and restricted suites: 44 passed, 17 skipped. The skips are the end-user issuer and code-repo cases, unrelated to this op.Affected unit suites (2,579 tests) pass: knowledge, audit, read scope, op budgets and reach, MCP listing budget and assistant toolset, the LibreChat integration, package contracts, public copy, doc links, SDK surface, agent instructions.
After the review fixes, the affected unit suites (2,251 tests) pass. The integration test, the leakage suite and the restricted-namespace suite with auth on give 44 passed, 17 skipped.
python -m tests.analyzer.corpus --checkgives 2,017 shapes, 0 rejected.After the stage change, the affected unit suites (2,318 tests: knowledge, decisions, context pack decisions, audit, read scope, op budgets and reach, MCP listing and assistant toolset, LibreChat, package contracts, public copy, doc links, SDK surface, agent instructions) pass.
make format-check,make lint(every generator--check, reach census) andmake typecheckare clean.python -m tests.analyzer.corpus --checkagainst the migrated ClickHouse: 2,017 shapes, 0 rejected.tests/analyzer/test_corpus.pypasses.Cost on a namespace of 2,000 documents, on a private single-node ClickHouse with the fake embedder. The namespace holds 1,900 live and 100 deleted documents, 4,781 live chunks, 313 retired versions, 60 decision rows and four URI schemes. Figures come from
system.query_log, filtered on the call'slog_comment, as the median of three runs:sample_limitThe cost was measured before the stage grouping. That grouping adds one key to a GROUP BY over the same rows, and there were 60 decision rows.
The longer-document read added since then is one more statement over the namespace's document URIs (the sort-key column), so a run is 23 statements.
Of the 22 statements, 8 are the report's own (29,127 rows, 98 ms) and 14 are
namespace.audit's. The audit's share grows with the namespace's memory rows, not its documents. The largest single read is the chunk-health join (9,319 rows). The listed-document reads grow withsample_limitin bytes, not rows.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 on clickhouse-local and the live server, the scope handling under a narrowed token, and the cost numbers in
system.query_log.I can explain every line of this diff and how it interacts with the rest of Loom.
Checklist
make format-check,make lint,make typecheckandmake test-unitpass; the integration suite passes if server behaviour changed. (format, lint, typecheck and the affected unit and integration suites pass; the fullmake test-unitis still to run.)docs/reference/configuration.mdand thedocs/reference/tables (python scripts/codegen/docs_reference.py), the reach manifest,schemas/schema.sql(make schema-dump) and the Codex plugin copies (python3 scripts/codegen/agent_plugin_sync.py).main; no merged migration is edited.hooks/,lib/,bin/,skills/,.mcp.json, the Codexplugin-defaults.json) bumps both plugin manifests' version, and no other open PR uses that version.npm --prefix frontend run build) and its tests pass, iffrontend/changed.docs/describe the system as it now is, and this description names any operator steps and wire changes.tests/unit/test_public_copy.py).git commit -s), as CONTRIBUTING.md asks.🤖 Generated with Claude Code