Repository navigation
Agents report wrong, outdated or missing knowledge with knowledge.reports.* - #1947
VanshajPoonia wants to merge 25 commits into
Conversation
Signed-off-by: Vanshaj Poonia <vanshajtheunique@gmail.com>
Signed-off-by: Vanshaj Poonia <vanshajtheunique@gmail.com>
Knowledge gaps resolved the asker in private helpers. Knowledge reports need the same person for the reporter, so a user erasure finds both by the same spellings. The helpers move to server/knowledge/app/people.py unchanged. Signed-off-by: Vanshaj Poonia <vanshajtheunique@gmail.com>
memory.get's read-scope narrowing moves into _within_read_scope, and readable_version uses it to answer the version and content hash of the row memory.get would serve, recording no read exposure or sensitive-read audit. Knowledge reports check their memory target with it. Signed-off-by: Vanshaj Poonia <vanshajtheunique@gmail.com>
…orts.* submit files a report about a memory claim, a document or missing knowledge under the token's person, after checking the caller can read the target; the id repeats for a retry. get serves it to its reporter and the namespace's admins, list is the admins' queue without anyone's words, update takes, asks for evidence, resolves, dismisses or reopens it, and evidence lets the reporter add references. Writes wait for every replica to know the table, run under a per-report claim, and narrowed tokens are refused. SDKs and the operations reference are regenerated. Signed-off-by: Vanshaj Poonia <vanshajtheunique@gmail.com>
Signed-off-by: Vanshaj Poonia <vanshajtheunique@gmail.com>
A version is written and read back with every column, the latest wins, the queue filters, the handlers file, take and add evidence under the claim, and both erasure steps remove what they own. Signed-off-by: Vanshaj Poonia <vanshajtheunique@gmail.com>
Submit, update and evidence check for an unfinished erasure that reaches the report's namespace or its people before the insert and again once the version is visible, as knowledge gaps record a miss, and delete a version that landed as one started. A link an update keeps is no longer checked again, so a related report erased since it was linked does not block new links. Signed-off-by: Vanshaj Poonia <vanshajtheunique@gmail.com>
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
Submit looked up the existing report only after it checked the related reports and the target again, so a retry after either changed was refused instead of answered with the report. It now answers a repeat first. A problem that is blank once trimmed is refused instead of stored empty. Signed-off-by: Vanshaj Poonia <vanshajtheunique@gmail.com>
zlareb1
left a comment
There was a problem hiding this comment.
Report versions need the write provenance required by the repository. The document target field also needs to describe the identifier the lookup accepts.
A maintainer's update stored the reporter's identity tuple and an assignee, so a version could not say which token principal wrote it. loom.knowledge_reports now has actor and source_class columns, and submit, update and evidence stamp them from the token with writer_actor and source_class_for, never from the body. With auth off the writer is the identity's agent, or "-" for an update, as the reporter and the maintainer are. Signed-off-by: Vanshaj Poonia <vanshajtheunique@gmail.com>
The handler looks a document target up by source URI, so the field description and the refusal now say source URI instead of document id. The Go and TypeScript wire models and the operations reference are regenerated. Signed-off-by: Vanshaj Poonia <vanshajtheunique@gmail.com>
knowledge.reports.get is a VIEWER read, so it joins the reads that spend knowledge.read instead of the write-shaped knowledge.add bucket. The admin queue read stays in knowledge.add, as the read bucket test expects for any op that is not read-only. Signed-off-by: Vanshaj Poonia <vanshajtheunique@gmail.com>
delete_version drops a report version that landed as an erasure started. It writes no cell control row, so it goes with the other knowledge store deletes. Signed-off-by: Vanshaj Poonia <vanshajtheunique@gmail.com>
Regenerated with LOOM_UPDATE_SNAPSHOT=1. The only change is the five knowledge.reports methods. Signed-off-by: Vanshaj Poonia <vanshajtheunique@gmail.com>
…ge-reports Signed-off-by: Vanshaj Poonia <vanshajtheunique@gmail.com> # Conflicts: # docs/reference/operations.md # docs/reference/status.md # sdk/go/wire/models.gen.go # sdk/ruby/lib/clickhouse/loom/generated/ops.rb # sdk/typescript/src/generated/ops.ts
|
The unit jobs have not run on this fork yet. A local run found three failures from the PR: the read bucket for |
The cap of 20 references was checked before repeats were dropped, so adding evidence the report already cites could be refused while the distinct references still fit. The cap now counts distinct references. Signed-off-by: Vanshaj Poonia <vanshajtheunique@gmail.com>
When the directory could not be read or tied the token to two accounts, the reporter fell back to the token's raw principal. The report id was hashed with that spelling, so once the person folded again a retry filed a second report and get and evidence no longer matched the reporter. A directory failure is now a 503 to retry and a tie is a 403. Get and evidence resolve the caller before the report, so neither answer says whether it exists. Signed-off-by: Vanshaj Poonia <vanshajtheunique@gmail.com>
zlareb1
left a comment
There was a problem hiding this comment.
The provenance and source URI fixes are in this head. The remaining blockers include report access after a grant downgrade, erasure of maintainer-authored data, and version checks across replicas. The existing reporter identity thread also needs a fix because a directory failure can change who owns the report.
| return n + await count_then_mutate( | ||
| "loom.knowledge_reports", | ||
| count_where=where, | ||
| mutation="UPDATE assignee = ''", |
There was a problem hiding this comment.
P1 — A maintainer can dismiss or request evidence without taking the report. User erasure then misses both their actor and their free-text reason. Clearing assignee also leaves those fields on reports they took. An evidence update carries the reason forward under a different actor, so record who wrote the reason and scrub that user's fields in every version while preserving the reporter's data. Include this case in the erasure census and readback tests.
There was a problem hiding this comment.
Thank you for tracing the reason through the evidence version. Fixed in 445e214: each version records who wrote its reason in a new reason_by column (migration 118, still unreleased, edited in place). The user step and the census now reach every version where the user is the assignee, the writer actor or the reason's author, and clear only those columns, so the reporter's words stay. The integration test covers an evidence request made without taking the report and carried forward by the reporter's version, and checks the census before and after. schemas/schema.sql gained the column by hand to match the migration because no ClickHouse was available here to dump it, so the CI schema check is the confirmation.
There was a problem hiding this comment.
The reason has an owner field. The actor scrub still misses verified end-user subjects. It strips the human prefix from human:user:<id>, leaving user:<id>, while user erasure passes the bare id and its aliases. Test an end-user maintainer who did not file the report.
| input.kind, | ||
| input.target_kind, | ||
| input.target_key, | ||
| " ".join(input.problem.split()), |
There was a problem hiding this comment.
P1 — A memory target is read by key and identity tuple, but the deduplication key omits the target tuple. If a namespace-scoped reporter files the same problem on two users' rows with the same key, the second submission returns the first row's report. Bind the ID to the resolved memory target and test distinct rows alongside true retries.
There was a problem hiding this comment.
Thank you for the two-rows case. Fixed in 4775dc7: a memory target's agent, user and session are part of the id. I bound it to the tuple the read resolves under rather than the row it finds, for two reasons. Reports refuse narrowed tokens, so the request tuple is the read tuple. And the id is computed before the target is read, so a retry is still answered after the target is gone. Documents are read by URI alone and keep one id across tuples. test_the_same_key_in_two_rows_is_two_reports covers distinct rows next to true retries.
There was a problem hiding this comment.
The request tuple distinguishes different user rows. It still gives two report ids when queries under two different agents both fall back to the same stored row for the user. Bind the id and subsequent target reads to the identity of the row that was found.
| elif input.action in ("release", "reopen"): | ||
| next_row["assignee"] = "" | ||
| next_row["reason"] = input.reason.strip() | ||
| next_row["resolution_revision"] = input.resolution_revision.strip() |
There was a problem hiding this comment.
P2 — Resolve accepts any nonblank revision identifier, including a draft identifier while the reported target remains unchanged. Check that the identifier names a published correcting revision, as the operation contract requires.
There was a problem hiding this comment.
Thank you for pointing back to the contract. Fixed in 8c2fdf9: for a report about a memory claim or a document, resolution_revision must be a revision number newer than the reported one and no newer than what readers are served now. A draft id or an unchanged target is refused. A target that is gone has no published correction, so its report is dismissed instead. Memory versions are not contiguous, so this checks the published range rather than looking up the exact version.
There was a problem hiding this comment.
The served-version bound still accepts numbers that were never published. Memory versions are allocated from the clock, so there are gaps between published versions. Require the served correcting version, or verify the supplied version in the history.
| if row is None or row["reporter"] != await _caller(input.org, row["agent"]): | ||
| raise NotFoundError(f"report {input.report_id!r} was not found") | ||
| try: | ||
| evidence = rules.check_evidence(list(row["evidence"]) + input.evidence) |
There was a problem hiding this comment.
P2 — Submit and evidence accept syntactically valid references without checking that they exist or that the caller can read them. Detail then returns those references without a per-reference access check. Validate citation targets on write and filter unreadable references on read.
There was a problem hiding this comment.
Thank you for flagging the unchecked references. Fixed in 8145cf4: each reference and the report's run_id are checked as the caller would read them (server/knowledge/app/report_refs.py). A run must be one of the namespace's runs, read as run.get reads it. A reflection is the memory at that key under the report's identity tuple. A gap must be in the latest build and is readable only by namespace admins, as knowledge.gaps.list is. A write citing one the caller cannot read is refused as not found, and get serves only the references the caller can read at that moment.
Get decided a maintainer from the token's claims, so a token minted while its subject was an admin kept reading other reporters' reports after the grant fell to viewer. It now asks the namespace gate at admin, which caps the claim at the live grant. The report tests run on real tokens. Signed-off-by: Vanshaj Poonia <vanshajtheunique@gmail.com>
The id hashed the target key without the identity tuple the key is read under, so a reporter who filed the same problem about the same key in two users' rows got the first report back for the second. A memory target's agent, user and session are now part of the id. A document is read by its URI alone and keeps one id across tuples. Signed-off-by: Vanshaj Poonia <vanshajtheunique@gmail.com>
Resolve took any nonblank text, so a draft id or a revision of a target that never changed closed the report. For a report about a memory claim or a document, resolution_revision is now a revision number newer than the reported one and no newer than what readers are served now. A target that is gone has no published correction, so its report is dismissed. Signed-off-by: Vanshaj Poonia <vanshajtheunique@gmail.com>
zlareb1
left a comment
There was a problem hiding this comment.
This head fixes the unstable reporter identity and counts unique evidence references toward the cap. The previous blocking findings still apply. I verified that a downgraded maintainer is still authorized from the token role and that maintainer-authored reasons are still outside user erasure. The new identity-folding thread also reproduces from the call order. Report detail refuses an already-authorized maintainer when the reporter identity lookup fails, while the queue remains available.
A writer could answer with version 2 and release its claim before another replica held the insert. The next writer's FINAL read could then return version 1, pass expected_version=1 and write a second version 2. Head reads now use select_sequential_consistency and each version is inserted synchronously, as the task inboxes do. Signed-off-by: Vanshaj Poonia <vanshajtheunique@gmail.com>
A maintainer can dismiss or ask for evidence without taking a report, and the user step only cleared the assignee, so their writer actor and their reason stayed. An evidence version also carried the reason forward under the reporter's actor. Each version now records who wrote its reason in reason_by (migration 118, unreleased, edited in place). The user step and the census reach every version where the user is the assignee, the writer or the reason's author, and clear just those columns. The reporter's words stay. schemas/schema.sql gains the column by hand to match migration 118, since no ClickHouse was available to dump it; the CI schema check compares it. Signed-off-by: Vanshaj Poonia <vanshajtheunique@gmail.com>
The two erasure checks around an insert did not fence a send already on its way: a writer cancelled while it awaited the insert left a version that could land after the erasure verified absence, and the cleanup check never ran. Each write now takes the org's report write fence and marks its send uncertain until the insert settles, so an interrupted send keeps the fence until its bound passes. Both report erasure steps take the same fence. The check after the insert and delete_version are gone, since no eraser runs between the check inside the fence and the insert. Signed-off-by: Vanshaj Poonia <vanshajtheunique@gmail.com>
Submit and evidence took any well-formed reference, and get served every stored reference to anyone who could read the report. Each reference and the report's run_id are now checked as the caller would read what they point at: a run of the namespace (run_exists, as run.get reads it), the reflection memory at that key under the report's identity tuple, and a gap of the latest build, which only namespace admins read. A write citing one the caller cannot read is refused as not found. A read serves only the ones the caller can read then. A reference the report already holds is not checked again when evidence is added. Signed-off-by: Vanshaj Poonia <vanshajtheunique@gmail.com>
Get resolved the caller's person before the report and refused on a failed fold, so a namespace admin whose directory lookup failed, or whose token is tied to two accounts, lost report detail while the queue still served them. A maintainer now reads on: only the reporter match is lost. A caller who is not a maintainer is still refused before the read. Signed-off-by: Vanshaj Poonia <vanshajtheunique@gmail.com>
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes using high effort and found 1 potential issue.
Reviewed by Cursor Bugbot for commit 728eb89. Configure here.
| _stamped(next_row, row["agent"]), | ||
| started_s, | ||
| {row["reporter"], row["user_id"], row["assignee"]}, | ||
| ) |
There was a problem hiding this comment.
Evidence write can restore erased reason
Medium Severity
knowledge.reports.evidence copies reason and reason_by from a row read under the per-report claim, then inserts that snapshot inside the org write fence while erasure_since is only told the reporter, user_id, and assignee. A maintainer who requested evidence or dismissed without taking is not in that set, and erasure does not take the per-report claim, so a user erasure can finish and an overlapping evidence (or related-only) write can land a later version that puts their words back.
Additional Locations (1)
Reviewed by Cursor Bugbot for commit 728eb89. Configure here.
zlareb1
left a comment
There was a problem hiding this comment.
The erasure race applies to both evidence and related-only updates. The earlier actor erasure, target identity, and published revision findings still have cases to cover. The live admin grant check, sequential head reads, and cancelled-send fence address the earlier findings on those paths.
| raise ReportRefused("the target is gone, so no published revision corrects it") | ||
| if not revision.isdigit(): | ||
| raise ReportRefused("resolution_revision is the target's revision number") | ||
| if int(revision) <= reported: |
There was a problem hiding this comment.
P2 — A resolve request with resolution_revision=² returns HTTP 500. The value passes isdigit() and then int() raises a ValueError that escapes the handler. Validate a decimal revision or turn the conversion error into the existing report refusal. Add this input to the resolution tests.


Closes: #1147
Related: #1232
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):
Agents and clients report a memory claim or a document as incorrect or outdated, or report missing knowledge, with
knowledge.reports.submit. Namespace admins review the reports withknowledge.reports.list,knowledge.reports.getandknowledge.reports.update, and a reporter adds evidence withknowledge.reports.evidence.Why
Step 1A of #1232. An agent that finds a claim wrong or a passage outdated has no way to say so short of editing the target, and maintainers have no queue of such findings. A report records the problem and points at its target; it never edits it. The fix stays an ordinary memory or document write, and resolving a report names the published revision that made it.
Memory proposals and definition drafts were checked first and cannot hold this: both are candidate memory rows decided by accept or reject, while a report points at someone else's claim, or at nothing, and must never be recalled. So reports get their own table,
loom.knowledge_reports, modelled on the knowledge gap tables.Design, in docs/architecture/knowledge-reports.md:
server/knowledge/app/people.py.readable_version, which reads asmemory.getdoes under the report's identity tuple and serves nothing of the row; a document throughknowledge.get's read path. A target the caller cannot read answers 404.leases.holding), so two maintainers never build on the same version.erasure_since): an unfinished erasure that reaches the report's namespace or people answers 409, and a version that lands as one starts is deleted.getserves a report to its reporter and the namespace's admins; an admin who cannot read the target now sees it without the problem and the correction.listrows carry no one's words.knowledge.reports.*, as withknowledge.gaps.*.Scope and risk
Touches: a migration and the report table, its erasure steps and census rows, five ops,
memory.get's read-scope narrowing (moved into_within_read_scope, behaviour unchanged), and the gap person helpers (moved, behaviour unchanged).Left for a follow-up: the dashboard's report queue. Until it exists
get,listandupdateare named inNOT_IN_DASHBOARD. Also left out: #1766 (a search verdict on a missing-knowledge report).Risk: a report holds people's words, so every read checks the target and the role, list rows carry no text, and both erasure scopes cover the table. Open #1510 also adds a migration 118; whichever lands second renumbers.
Compatibility, rollout and rollback
knowledge.reports.submit,get,list,updateandevidence, allexperimental. No existing op or field changes.Tests
tests/unit/test_knowledge_reports.py(26 tests): the reporter comes from the token, the target read check, the id a retry repeats (also after the target or a linked report is gone), a blank problem, the refusals, who reads a report, a changed or unreadable target, the queue without words, every maintainer action,expected_version, the claim held elsewhere, the reporter's evidence, both sides of the erasure fence, a link to an erased report, the rollout gate, narrowed tokens, andreadable_versionserving nothing. The domain rules keep their tests intests/unit/test_knowledge_reports_domain.py.tests/integration/test_knowledge_reports.py(5 tests) against a ClickHouse started withdev/ci_start_clickhouse.shandmake migrate: a version read back with every column, the latest version winning, the queue's filters, the handlers' submit, update and evidence under the claim, and both erasure steps.test_erasure_verify.py,test_erasure_step_order.py) include the new table and step.make lintandmake typecheckpass;make schema-dumpreportsschemas/schema.sqlcurrent; every generator indocs/development/adding-an-operation.mdwas run, and the reach census, SDK, docs and op-gate tests pass.tests/unit/test_knowledge_ingest.pyandtests/integration/test_knowledge_gaps.py::test_gap_draft_rereads_eligible_questions_and_claims_one_model_attemptfail on this machine onmaintoo (the first needs the local job runner, the second a server heartbeat), so they were not part of this check.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 diff 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
make test-unitand applicable integration results are reported by CI; a full local run is not required before pushing.docs/reference/configuration.mdand thedocs/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).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.Note
Medium Risk
Adds a new SoR for user-authored text with admin-only queue access, target readability checks, and erasure/rollout gates; behaviour is well bounded but touches auth, erasure, and rolling upgrades.
Overview
Introduces knowledge reports: agents and clients can flag memory claims or documents as missing, incorrect, or outdated via
knowledge.reports.submit, without editing the target. Namespace admins work a maintainer queue throughknowledge.reports.list,knowledge.reports.get, andknowledge.reports.update(take, resolve with a published revision, dismiss, etc.); reporters add reference-only evidence withknowledge.reports.evidence.Persistence is a new
loom.knowledge_reportstable (migration 118,ReplacingMergeTreeby report version), with per-report write claims, erasure fencing and user/namespace erasure steps, and 503 on write ops during mixed-version rollout when older replicas lack the table. Narrow read-scope tokens are blocked from allknowledge.reports.*ops. Token person resolution for gaps/reports is centralized inserver/knowledge/app/people.py(moved from gaps).Five experimental ops, generated SDK surfaces (Go/Python/Ruby/Rust/TS), rate-limit bucket for
get, dashboard/reach manifest notes (no UI queue yet), and architecture/docs/reference updates accompany the change.Reviewed by Cursor Bugbot for commit 728eb89. Bugbot is set up for automated code reviews on this repo. Configure here.