Skip to content

Audit and validate findings carry their kind, rule version, coverage and cited revisions - #168

Merged
zlareb1 merged 6 commits into
mainfrom
feat/i160-findings
Nov 2, 2026
Merged

zlareb1 merged 6 commits into
mainfrom
feat/i160-findings

Conversation

@zlareb1

@zlareb1 zlareb1 commented Oct 30, 2026 •

Copy link
Copy Markdown
Member

Related: #160

Changelog category (leave one):

  • Improvement

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.audit and namespace.validate findings say whether each is a contract violation or a usage heuristic, which rule version and operation computed it, what it was measured against, whether its samples are complete, and which live revisions (memory id, version, content hash) back each sampled row. Each report lists the rules it ran and skipped in coverage, its summary reads and the evidence read among them.

Why

Issue 160 asks for findings that the CLI, the dashboard, MCP clients and a chat client can share, and that keep three kinds of result apart: a broken stored contract, a usage heuristic that a legitimate design can match, and a recommendation that needs review. Today a finding is a code, a severity, a count and key samples. A reader cannot tell a heuristic warning from a broken invariant, whether the samples are all the matches, what population the count was measured against, or which stored revision a sample referred to when the report ran. An explanation built on top of the report (in a chat, say) would have to restate that from prose.

This adds one shared contract (server/identity/api/models_findings.py) to both reports. Codes, severities, healthy and the existing fields are unchanged; the contract fields come first in each finding. A cited row's content_sha256 is the hash memory.get serves: the hash of the value it serves, computed the same way (the stored column can differ for an object, whose JSON column drops a null field); a high-sensitivity row is cited without it, as memory.list serves it, because these reports are unaudited reads and a short secret's hash can be guessed.

Each sample names the row that matched: by its memory_id, or by its full identity (agent, user_id, session_id, memory_key) when it comes from loom.memory_embeddings, which has no id. One extra read per report (server/memory/store/reads.py::live_revisions) fetches the live head of every named row, identifiers only; a second read keyed by each cited row's whole sorting key reads the value memory.get serves, to hash it, and returns no value. A row whose value is longer than LOOM_NAMESPACE_REPORT_HASH_MAX_BYTES (new, live, 64 KiB) is cited with no hash and its value is not read, so a report over the largest values (oversized_values, episodic_blobs) reads at most that much per cited row. A key held under several identities cites only the identity that matched. A sample that names no single row (a hot key from the ledger, a key's version history) and an orphan vector are not cited. A failed citation read leaves the findings uncited, adds evidence: <error> to skipped, and marks coverage.complete false; it never fails the report.

population is the denominator of the finding's share (audit); validate's checks report a count with no denominator and leave it null, and so does an audit finding whose summary read was skipped. namespace.audit lists its summary reads in coverage.rules_run, since most findings are measured against one of them.

Scope and risk

  • Read-only. One more loom.memory FINAL read per report, over identifier columns only (plus one read of the cited rows' values keyed by their whole sorting key and bounded by namespace_report_hash_max_bytes per row, so no read scans the namespace's values), filtered on (org, namespace) and the sampled rows' memory_id or identity tuple, capped at the number of rows named and taking the request's read scope, as every reader of memory rows does; like the audit's other reads it scans the namespace's live rows: at most 14 findings × sample_limit (50).
  • Samples gain a memory_id column (and unembedded_rows samples their identity columns), which joins each sample to its evidence entry; the samples main already returned keep every column. The CLI table and the dashboard do not print memory_id; they do print the unembedded_rows sample's identity columns (agent, user_id, session_id), as they print every other sample column. Both ops read the whole namespace and a token narrowed below it is refused before either runs (pinned by a test). exact_key_store and version_churn read one sample row past the cap, so a full page is told from a cut one.
  • Evidence carries no value, and no hash for a high-sensitivity row, so the audit's "keys and counts, never a value" promise holds.
  • The kind, exceptions and uncertainty for each rule are written next to its existing detail and remedy text. Every error-severity validate check is a contract_violation. The thresholds-based checks (conflicted_aging, unsourced_low_confidence, unanchored_time_cue, unresolved_evidence, code_links_stale) and every audit code except unembedded_rows are usage_heuristic.
  • exact_key_store groups every get of the window by key in one scan, so the window's gets and the hot keys' reads are counts of one snapshot (the hot-key grouping costs that scan on its own). On 300,000 gets over 5,000 keys in one namespace, both forms read 300,238 rows; the median of five runs was 12 ms against 11 ms, and memory 6.07 MB against 5.68 MB (system.query_log).
  • The stale_of_served code-link read gains memory_id; tests/integration/test_memory_code_links.py runs it on the live store.
  • The dashboard's audit panel shows the kind, rule version, uncertainty ("May still be fine") and exceptions ("Scope") in the expanded row, and says when the samples are not every match. The CLI table gains a kind column.

Compatibility, rollout and rollback

  • Wire: added output fields; the finding contract's fields come first in each finding's JSON object, ahead of its code, severity and count. Two changes in meaning: computed_at (audit) and checked_at (validate) are now when the report started, in whole seconds, not when it finished, so a cited revision's updated_at can be compared with it. One behaviour fix: namespace.validate with sample_limit: 0 counted every finding as 0 (each count rode its sample rows under LIMIT 0); it now counts and lists none, as namespace.audit already did. NamespaceAuditFinding and the validate finding gain kind, rule_version, source_op, window_seconds, population, sample_limit, samples_complete, evidence[], exceptions, uncertainty. NamespaceAuditOutput and NamespaceValidateOutput gain coverage (rules_run, rules_skipped, complete). No input changes.
  • New setting LOOM_NAMESPACE_REPORT_HASH_MAX_BYTES (live, default 65536; 0 cites no hash). Operator steps: none.
  • Rollback: revert; nothing is stored.

Tests

  • Unit: every audit code and validate check declares its kind, version and uncertainty; findings carry the contract and cite the revisions the citation read returns; one citation read per report bound to the sampled rows' ids and selecting no value; each cited row's value is read by its sorting key and hashed as memory.get hashes it (an object and a raw string value), one revised between the two reads is cited with no hash, and a high-sensitivity row is cited with no hash and no value read; a key under two identities cites only the row that matched, for a value check and for an index row judged per identity; exact_key_store samples are complete only when the hot keys account for every get, both counted by one statement, and never when the ledger summary failed; each code's built-in thresholds and validate's time-cue pattern are pinned beside their rule version; hot keys under a failed ledger summary are not a complete listing; ledger and version-history samples are not cited; version_churn's population is its version rows; hot-key samples_complete at and below the limit; a row behind two samples is cited once; a row stored without a hash is cited with the hash memory.get computes from its value; validate with sample_limit: 0 still counts and is not a complete listing; a failed citation read is reported in skipped and coverage; a population whose summary read was skipped is null; a value over the hash bound is cited with no hash and never read; the analyzer corpus renders both citation statements; a skipped check or summary read is named in coverage.
  • Integration (tests/integration/test_namespace_findings_contract.py, against a private ClickHouse and server): the citation read resolves a row by id and by identity tuple with an empty id list, an identity that holds nothing, and nothing under another user's read scope; a key read past the hot threshold beside a key read once is sampled alone and not a complete listing; a double-encoded value's double_encoded_values finding cites the memory_id and content_sha256 that memory.get serves, and the report does not carry the value; both reports' coverage lists no skipped rule, so every check's SQL, the join projections that now select memory_id included, ran on the live store; a row whose content_sha256 column holds the default '0' is cited with the hash memory.get serves, for a string value and for an object value served from the JSON column, and so is a hashed object with a null field (whose stored hash differs from memory.get's); a high-sensitivity row is cited with no hash; with a second agent holding the same key unverified, the stale attestation's stale_verification finding cites only the stale row's agent and hash. test_memory_verify.py, test_memory_code_links.py and test_read_ops_never_5xx.py pass against the same server (230 passed, with test_memory_precondition.py and test_read_scope_isolation.py, since every write-path if_match_sha256 hash now goes through the same helper).
  • The rule-version pins (each code's thresholds and the time-cue pattern, as literal values) are a reminder, not enforcement: an edit fails beside the version that must rise with it. A predicate edit raises its version through review.
  • Dashboard: Recent.audit.test.tsx checks the kind line with its separators, the incomplete-samples note, and that a finding from a server one release older (no evidence fields) shows neither.
  • make format lint typecheck, npm --prefix frontend run build and Recent.audit.test.tsx pass. The whole tests/unit passes except three repository-wide checks that main fails too, on decision_extract code this PR does not touch: test_tunable_constants.py::test_no_new_tunable_constant, test_llm_max_tokens.py::test_no_call_site_caps_its_output_with_a_literal and test_tests_patch_only_real_settings.py::test_every_patched_settings_name_is_a_settings_field (25039 passed).

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 the rule classification against each check's SQL, the citation read's projection, and the integration run.

  • 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.
  • 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
zlareb1 force-pushed the feat/i160-findings branch 4 times, most recently from a53a108 to a20a202 Compare November 2, 2026 12:35
…and cited revisions

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: zlareb1 <[email protected]>
@zlareb1
zlareb1 force-pushed the feat/i160-findings branch from 6f91f0d to 7fe6950 Compare November 2, 2026 14:55
zlareb1 and others added 5 commits November 2, 2026 15:34
…und fits UInt32

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

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: zlareb1 <[email protected]>
…onKey names the versioned key

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: zlareb1 <[email protected]>
@zlareb1
zlareb1 merged commit 855c3c9 into main Nov 2, 2026
20 of 22 checks passed
@zlareb1
zlareb1 deleted the feat/i160-findings branch November 2, 2026 18:00
@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