Skip to content

A request that joined a per-reader mirror records no knowledge miss - #2343

Merged
zlareb1 merged 1 commit into
mainfrom
fix/mirror-request-records-no-miss
Dec 6, 2026
Merged

zlareb1 merged 1 commit into
mainfrom
fix/mirror-request-records-no-miss

Conversation

@zlareb1

@zlareb1 zlareb1 commented Dec 6, 2026 •

Copy link
Copy Markdown
Member

Related: #2152

Changelog category (leave one):

  • Bug Fix (user-visible misbehavior in a release)

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

A request that joined a per-reader mirror records no knowledge miss. With auth on, a knowledge.search or loom_search over a namespace with an active mirrored source records none, so the knowledge gaps of such a namespace form from the memory.search calls a caller invokes.

Why

Nothing a request that touched a mirror writes outside the mirror may depend on what the mirror holds (document sources: the mirror), and a knowledge miss is judged on the answer a search returned. So a marked request records none.

record_miss (server/knowledge/app/gaps.py) returns first inside its try:, before the settings read, the row and both counters, when request_work.mirror_marked() or not public_diagnostics(). This is the expression of the read-receipt gate (_record in server/memory/app/read_receipts.py).

  • Both halves: mirror_marked() reads the bound bag. public_diagnostics() is false under private_work(), on a marked HTTP owner whose current bag is fresh, and when the mark cannot be read, so it catches a call made inside a marked request under a bag of its own.
  • The check sits in record_miss, not in its three callers (knowledge.search, loom_search, memory.search), so every caller gets it.

With auth on:

  • a knowledge.search or loom_search over a namespace with an active mirrored source records no miss;
  • a loom_search whose live leg ran records none;
  • a search the assistant runs for an answer in such a namespace records none;
  • a memory.search the caller invokes is not marked and records its misses;
  • a mark that cannot be read records none. A context with no request bag (a worker, the CLI) reads as ordinary and is refused by _invoked(op).

The refusal writes no log line, metric or counter and takes no in-flight slot.

Scope and risk

  • Touches: two imports and one statement in server/knowledge/app/gaps.py, two tests in tests/unit/test_knowledge_gaps.py, four docs pages.
  • Left alone: _record_gap_miss's if payload.get("live"): return in server/memory/app/loom_search/handler.py, the three callers, the worker and knowledge.gaps.list. Judging a marked request's miss on its ordinary answer is not built: gaps in a namespace with an active mirrored source form from memory.search.
  • Tenant isolation: the check reads the request's own bag and context. No row, read or scope changes, and a row that is written carries the same identity tuple.
  • Fail closed: an unreadable mark records no miss. No new broad except; tests/unit/degraded_unnoted.txt keeps its one record_miss line.
  • Stored data: loom.search_misses gets fewer rows. No table, erasure step or census row changes.
  • What could break: a deployment that reads the gaps of a namespace with an active mirrored source sees fewer of them, since only memory.search contributes there.
  • Other records a request writes outside the mirror, as the system is: loom.search_misses has one writer, _insert, scheduled only by record_miss. A marked request's agent_events row is written to loom.agent_events_private with reduced arguments and no memory key. memory.ask skips its cited-used credit, contradiction record and deferred consistency when its plan is marked. Spans, metrics, log records and captured generation text are dropped under private_work(), and the caches shared across readers are bypassed for text a mirror leg gave. The docs page linked above states the rule for each.
  • The open pull request Agents report wrong, outdated or missing knowledge with knowledge.reports.* #1947 edits other hunks of server/knowledge/app/gaps.py, docs/features/knowledge.md and tests/unit/test_knowledge_gaps.py. git merge-tree of its head with this branch merges those three files without conflict, so either order merges.

Compatibility, rollout and rollback

  • Wire: none. No op, field, default, setting, error code, CLI command, MCP listing or dashboard view changes; docs/reference/status.md stays at 419 operations, 305 of them experimental.
  • Operator steps: none.
  • Rolling upgrade: no schema or wire change; a replica on N-1 records until it is replaced.
  • Rollback: reverting leaves no row, migration or generated file behind.

Tests

No ClickHouse or server was started: no statement changes, and the tests are unit tests on the file's scheduled fixture.

  • New: test_a_request_that_joined_a_mirror_records_no_miss, parametrized over a marked bag, private_work() alone, a mark on the HTTP owner with a fresh bag, and http_mirror_marked raising. It fails when a shape schedules an insert, counts a drop at knowledge_gaps_max_in_flight = 0, or takes an in-flight slot; each case ends with the same call outside the request, which records one row.
  • New: test_a_loom_search_that_joined_a_mirror_records_no_miss fails when handler._record_gap_miss schedules a row under a marked bag, or records none outside it.
  • Both fail on the unchanged record_miss (5 failed) and pass with the change (5 passed).
  • pytest -n 2 -p randomly tests/unit/test_knowledge_gaps.py tests/unit/test_live_source_search.py tests/unit/test_source_search_handler.py tests/unit/test_source_search_provider_boundaries.py tests/unit/test_loom_search_fanout_kinds.py tests/unit/test_loom_search_mcp_render.py tests/unit/test_loom_search_repo_decisions.py tests/unit/test_loom_search_tracker_general.py tests/unit/test_search_op.py tests/unit/test_admission_parity.py tests/unit/test_memory_search_kinds.py tests/unit/test_read_receipts.py tests/unit/test_memory_search_handler_gates.py: 564 passed, 1 xfailed.
  • pytest -n 2 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 tests/analyzer: 614 passed, 12 skipped (the analyzer's live cases skip without a ClickHouse).
  • ruff format --check . and ruff check server extractor sdk/python tests scripts .claude: clean. make typecheck: clean. scripts/gates/function_length_gate.py: at its baseline.
  • python -m scripts.codegen.docs_reference --check: every page current. prettier@3.9.9 --check on the four docs pages: clean.
  • No integration test: the shared test server records no misses, and no read or write path is added.

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 by hand: where the mark is set for a mirror leg, the live leg and the assistant's answer; that memory.search prepares no mirror plan; that loom.search_misses has one writer; and that both new tests fail on the unchanged function.

  • 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


Note

Low Risk
Narrow recording gate on background gap inserts; namespaces with mirrored sources will show fewer gaps unless callers use memory.search.

Overview
Mirror-marked requests no longer write knowledge-gap misses. record_miss in gnowledge/app/gaps.py returns immediately when request_work.mirror_marked() or not public_diagnostics(), matching the mirror rule that nothing outside the mirror may depend on mirrored content—and a miss is tied to the search answer, not a hidden leg.

With auth on, knowledge.search, loom_search, and assistant-driven searches in namespaces with an active mirrored source stop contributing to loom.search_misses; gaps there come only from caller-invoked memory.search. The check lives in one place so all three callers stay aligned.

Docs (document-sources, knowledge-gaps, curation-loop-design, knowledge feature) document the rule and invariants. Unit tests cover marked bags, private_work, HTTP-owner marks, unreadable marks, and loom_search's _record_gap_miss.

Reviewed by Cursor Bugbot for commit 49e94d7. Bugbot is set up for automated code reviews on this repo. Configure here.

`record_miss` returns before it reads a setting, builds a row or touches a counter
when the request is marked as touching a mirror, or runs inside such a request.
Nothing a marked request writes outside the mirror depends on what the mirror holds,
and a miss is judged on the answer.

With auth on, a `knowledge.search` or `loom_search` over a namespace with an active
`mirrored` source, a `loom_search` whose live leg ran, and a search the assistant runs
for an answer in such a namespace record none. A `memory.search` the caller invokes is
not marked and records its misses. A mark that cannot be read records none.

No op, field, setting, CLI command, MCP listing or dashboard view changes.

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

Request Review

@zlareb1
zlareb1 merged commit 3f60986 into main Dec 6, 2026
83 checks passed
@zlareb1
zlareb1 deleted the fix/mirror-request-records-no-miss branch December 6, 2026 03:05
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