Skip to content

The knowledge factory example reports the problem against the revision it read - #2370

Merged
zlareb1 merged 5 commits into
mainfrom
feat/knowledge-factory-report
Dec 6, 2026
Merged

zlareb1 merged 5 commits into
mainfrom
feat/knowledge-factory-report

Conversation

@zlareb1

@zlareb1 zlareb1 commented Dec 6, 2026 •

Copy link
Copy Markdown
Member

Related: #1185
Related: #1232

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

The knowledge factory example (sdk/python/examples/knowledge_factory.py) files a problem report against the revision of the definition it read, sends it a second time to show that one problem is one report, and resolves it with the published revision. Its coverage entries report and repeated_report read exercised.

Why

The example started its correction from a finding the script made up: nothing in Loom said which revision was wrong, and the link from the failed run to the correction was text in the promotion's rationale. knowledge.reports.* holds both, so the report stage runs:

  • The reporter reads the definition's source row (memory.get) and files knowledge.reports.submit with that read's version_text as target_version and its content_sha256 as target_sha256, the failed run in run_id, and run:<run 1> and reflection:<run 1> as evidence.
  • The same request sent a second time answers the same report_id, state and version.
  • The reviewer takes the report. Its resolve that names the reported revision answers 422 VALIDATION_FAILED ("the target has no revision newer than reported revision N"), and the report stays taken at version 2.
  • Only its reporter and an administrator read a report, so the reviewer reads it and hands the curator the target it names and the report id. The curator holds writer, reads that revision and calls no report op.
  • After the promotion the reviewer resolves the report with the version_text memory.get served, and the reporter reads its report back as resolved with that resolution_revision.

The result's problem_to_correction link is the report, held by Loom, in place of the rationale text.

Two facts of the report ops shape the example, and the guide states both:

  • knowledge.reports.update compares resolution_revision with the version memory.get serves for the source row, not with a promotion. A candidate that awaits review is a newer revision, so the refusal the example reads is sent before the candidate exists, and the guide lists as a limit that an administrator can resolve a report before its correction is published.
  • Agent.call sends - for a run_id the caller leaves unset, and knowledge.reports.submit reads it as a run: the call answers 422 with evidence 'run:-' was not found. The example names the failed run. Filing through the Python SDK without a run is refused until the op or the SDK treats - as unset; this change does not touch either.

Scope and risk

The example, its fixture's expected.json, its guide, its entry in the examples README and its tests. No server, generated SDK or dashboard file changes.

  • expected.json: the report stage with its revision and handoff, nine checks, the problem_to_correction link, ids.report_id, and the coverage entries report and repeated_report. qualified stays false: the four curation-pass entries are not exercised.
  • Preflight asks the deployment for knowledge.reports.submit, .get and .update with the fields the run sends, so a deployment without them ends unavailable (exit 4) before any write.
  • The example needs a deployment whose every replica runs the migration that adds loom.knowledge_reports: during a rolling upgrade the report ops answer 503, and a run that reaches the report stage ends failed there.
  • A token narrowed below the namespace is refused every knowledge.reports.* op. The guide's mint commands and the tests mint tokens with the default namespace scope.

Not in this change: the curation pass and the recurrence check.

Compatibility, rollout and rollback

  • Wire: none. The example calls three ops it did not call: knowledge.reports.submit, knowledge.reports.get, knowledge.reports.update.
  • Operator steps: none.
  • Rollback: reverting leaves nothing behind. A run's report is erased with its namespace by cleanup.

Tests

Against a ClickHouse and a server started for this change, with fake providers and workers off:

  • pytest tests/integration/test_sdk_example_knowledge_factory.py -p no:randomly: 19 passed, 1 error at setup. The server that test_returned_lists_labelled_reads_when_the_trace_log_is_on spawns refused to start because the local run set no LOOM_INSTANCE_LABEL, which CI sets; run alone with the label set, that test passed. The live result equals expected.json, with the trace log off and on. test_the_report_names_the_revision_read_and_the_revision_that_resolved_it reads the report as the reviewer and as the reporter (revision, evidence, reporter, assignee, resolved, version 3), finds one report about the definition in the queue, and checks that the curator reads no report and is refused the queue and an update with 403. test_a_resolution_names_a_revision_newer_than_the_reported_one pins both refusal messages and the limit above.
  • pytest tests/unit/test_sdk_example_knowledge_factory.py tests/unit/test_knowledge_factory_example.py -n 2: 216 passed. test_the_report_names_the_revision_that_was_read, test_a_second_submit_returns_the_same_report and test_a_resolve_before_publication_is_refused failed before the stage existed. The scripted server refuses a run_id that names no run, as the real one does. Each of the nine checks has a fault row that fails it.
  • pytest tests/unit/test_session_content_senders.py tests/unit/test_public_copy.py tests/unit/test_doc_links.py tests/unit/test_help_docs.py tests/unit/test_agent_instructions.py tests/unit/test_package_contracts.py tests/unit/test_op_transport_contract.py tests/unit/test_tunable_constants.py tests/unit/test_store_names_refused.py tests/unit/test_degraded_unnoted.py -n 2: 656 passed, 10 skipped. The session-content census names no file of this change.
  • LOOM_ENV_FILE= pytest tests/analyzer -n 2: 10 passed, 2 skipped. No statement changes.
  • ruff format --check and ruff check on the changed files, make typecheck, scripts/gates/function_length_gate.py: clean.
  • --check of scripts.codegen.sdk_py_gen, .sdk_py_client_gen, .docs_reference and .op_reach_census: no output moves.
  • npx prettier@3.9.9 --check on the guide, the README and expected.json: clean.
  • After the merge of main, which changed no file of the example: pytest tests/unit/test_session_content_senders.py tests/unit/test_sdk_example_knowledge_factory.py tests/unit/test_knowledge_factory_example.py -n 2: 234 passed. The other commands ran on the tree before that merge.
  • After the rewording of the guide's rollout limit, which changes text only: pytest tests/unit/test_sdk_example_knowledge_factory.py tests/unit/test_package_contracts.py tests/unit/test_op_transport_contract.py tests/unit/test_tunable_constants.py tests/unit/test_store_names_refused.py tests/unit/test_degraded_unnoted.py tests/unit/test_public_copy.py tests/unit/test_doc_links.py tests/unit/test_agent_instructions.py -n 2: 816 passed, 10 skipped, 1 failed. The failure is test_degraded_unnoted.py, on server/code/app/index/review_brief_build.py::_history_section::gather::1: main fails it the same way, and this change edits no file the scan reads. LOOM_ENV_FILE= pytest tests/analyzer -n 2: 10 passed, 2 skipped. ruff check, make typecheck and the prettier check on the guide: clean.

Left to CI: the full unit and integration suites.

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 three ops' handlers, rules and wire models read before the example was written; each answer the example asserts was first read from a live server; the commands above.

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

🤖 Generated with Claude Code

zlareb1 and others added 2 commits December 6, 2026 08:40
…n it read

The example started its correction from a finding the script made up. Its
report stage is exercised: the reporter reads the definition's source row and
files knowledge.reports.submit with that read's version_text and
content_sha256, the failed run in run_id, and run: and reflection: references
as evidence. The same request sent a second time answers the same report. The
reviewer takes the report, its resolve that names the reported revision
answers 422, and it hands the curator the target the report names and the
report id. The curator holds writer and calls no report op. After the
promotion the reviewer resolves the report with the published revision, which
the reporter reads back, so the result's link from the problem to the
correction is held by Loom.

The coverage entries report and repeated_report read exercised. qualified
stays false until a curation pass is exercised.

Agent.call sends "-" for a run_id the caller leaves unset, and
knowledge.reports.submit reads that as a run and refuses it, so the example
names the run.

Signed-off-by: Mohammad Lareb Zafar <lareb.zafar@clickhouse.com>
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
The branch holds main at a01c25e. Main changed no file of the knowledge
factory example, and the merge has no conflict.

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

Request Review

zlareb1 and others added 3 commits December 6, 2026 09:22
… them

- A token minted with --read-scope below the namespace fails the run, and not
  at the report stage: the reviewer needs memory.promote in setup, the reporter
  run.reliance in run_1, and the curator calls no report op. Loom refuses a
  narrowed token both ops and every knowledge.reports.* op, and bounds its
  reads to one user or session.
- Only an administrator takes, resolves or dismisses a report. Its reporter
  adds evidence with knowledge.reports.evidence, which needs writer, so a
  report does not change through an administrator alone.
- While a live replica runs a schema below the migration that adds the reports
  table, knowledge.reports.submit and knowledge.reports.update answer 503 and
  the run ends failed at the report stage, after setup registered both
  namespaces.

Signed-off-by: Mohammad Lareb Zafar <lareb.zafar@clickhouse.com>
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
…hy a report read is not repeated

- Every stage entry of COVERAGE is exercised, so no stage can read
  not_exercised. new_result and run() hold no branch for that status, and the
  tests accept only not_run for a stage after a stop.
- The two knowledge.reports.get reads are single reads: Loom reads a report
  with sequential consistency, so each shows the last acknowledged change. A
  comment says so at the first read and at the LAGS table of the tests.
- The docstring of evidence() names the report it reads.

Signed-off-by: Mohammad Lareb Zafar <lareb.zafar@clickhouse.com>
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
…o a run that reaches it

While a live replica runs a schema below the migration that adds the reports
table, `knowledge.reports.submit` and `knowledge.reports.update` answer 503, and a
run that reaches the `report` stage ends `failed` there.

Not every such run reaches it. Read receipts are written only when every live
replica runs the read receipts migration, which is older than the reports
migration. With a replica below both, `run.reliance` lists no version, the
`run_1_revision_recorded` check fails and the run ends at `run_1`, with no report
op sent. The guide's limit named `report` as the stage for every run.

Signed-off-by: Mohammad Lareb Zafar <lareb.zafar@clickhouse.com>
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
@zlareb1
zlareb1 merged commit 54c149c into main Dec 6, 2026
80 of 82 checks passed
@zlareb1
zlareb1 deleted the feat/knowledge-factory-report branch December 6, 2026 10:20
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