Skip to content

Search under a code scope reads the repository's decisions - #165

Merged
zlareb1 merged 9 commits into
mainfrom
feat/search-code-scope-decisions
Nov 2, 2026
Merged

zlareb1 merged 9 commits into
mainfrom
feat/search-code-scope-decisions

Conversation

@zlareb1

@zlareb1 zlareb1 commented Oct 30, 2026 •

Copy link
Copy Markdown
Member

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

loom_search from an indexed checkout now returns the decisions recorded in the repository's trunk code namespace in its memory section. The caller must be allowed to read that namespace. Rows that loom_search and HTTP search.query withhold from the memory section now leave its reader block too.

Why

A decision written in a repository's trunk code namespace (a memory_type='decision' row) never reached loom_search. The memory leg's all_mine fan-out starts from the caller's own namespaces and keeps only memory-kind namespaces, so a code namespace is never searched. A "why is it done this way" question asked in the checkout came back with nothing, even when the repository had recorded the answer.

The repository's documents already reach the knowledge section this way (knowledge_with_repo_docs + search_repo_docs + merge_hits). This PR gives the memory section the same treatment. Under X-Loom-Code-Scope, memory_with_repo_decisions (server/memory/app/loom_search/repo_decisions.py; fanout.py keeps the assembly) runs one extra in-process handle_memory_search over the scope's trunk code namespace (namespace_scope="this", agent="*", memory_type="decision", the same query, top_k and tags, LLM-free) and merges its hits into the memory section. The gate that admits the namespace also decides the repository-docs leg, so one check covers both legs and capture consent.

Scope and risk

  • Tenant isolation. handle_memory_search performs no authorization, so the leg is gated. repo_namespace_in_scope (server/code/app/repo_scope.py) runs once per request in handle_search. It returns the trunk namespace only when the scope's org is the request's org and row_in_scope(org, trunk_ns, VIEWER) admits it (fail closed). Both repository legs (memory_with_repo_decisions, knowledge_with_repo_docs) take that result and run no gate of their own. The docs leg used to run its own gate, which lacked the same-org check. readable_repo_namespace and trunk_namespace_of (renamed from readable_docs_namespace and docs_namespace_of) moved there from repo_docs.py.
  • Read scope. handle_memory_search pins the token's read scope on the decision pass as on every search. A user- or session-bound token reads only its own rows, and a scope that does not resolve is refused, which the leg treats as no answer.
  • Capture consent. handle_search narrows consent to the most restrictive level of the fan-out namespaces plus the repository namespace, before the legs start. This also closes the gap where the docs leg ran at the home namespaces' level.
  • Additive. A refusal, a timeout (memory_repo_decisions_timeout_s, a new LIVE setting, 1.5 s), an exception or an abstaining decision search adds no hits, and the section answers as before. Only the base search can fail the leg; when it does, the decision pass is cancelled.
  • The decision pass. It is LLM-free and pinned so the code namespace's retrieval_defaults cannot change it: retrieval_budget="fast", search_mode="semantic", hyde=False, rerank="none", legs=["memory"], memory_type="decision", quality_filter=False, floor_mode="drop" (an additive leg adds only rows that clear the floor; padding to top_k is the home search's job). It is served at the stored clip (bodies="full"), because a recorded decision is a statement that ends with its reason, which a 200-character excerpt cuts. Under bodies="none" it serves keys only. The junk filter is off because it targets captured session rows, and two decisions under different keys stay two decisions however alike they read. Only hits with memory_type == "decision" and source == "fact" are kept.
  • Credit and traces. The pass is marked _merged_into_parent and writes no trace row, exposure, recall credit or page of its own. After the merge, credit_merged_hits records exposure and recall credit once for the decisions that were merged in. It uses the pass's settled input (MemorySearchOutput._settled_input), so the token's user pin and the namespace's auto_touch apply.
  • Merge. Base hits keep their order. Each decision goes after the last base hit whose similarity is at least its own, because rank scores of two searches do not compare. Hits are deduplicated per (namespace, memory_key). Decisions do not count against top_k: at most the pass's own top_k join, and a home row pushed past the cut would be served on no page, because the parked tail starts after the home search's own rows. candidates_total is the home count plus the decisions added. If the home search abstained and a decision answers, the section carries the decision search's calibration. Later pages continue the home search alone and count its matches only. Under explain=true, every served row gets a why line, decisions above top_k included.
  • Withheld rows leave the reader block. answer_first and its precision floor removed rows from memory.results, but the reader block still printed them. This applied to any row, on MCP loom_search and HTTP search.query alike. search_sections now renders the block once, from the models of the rows that remain. A served row that has no model raises an error instead of silently leaving the block. No paired benchmark was run for this: the block now holds exactly the rows the section already served, so a reader sees no row the results withheld; the change removes text, not ranking.
  • Read-your-writes trade-off. The merged pass skips the empty-pool and fresh-hit re-reads, so a decision written moments ago through another replica can be missed until replication catches up (docs/features/unified-search.md, Limits).
  • Cost (indicative). Measured with a throwaway script that sent 300 MCP tools/call loom_search requests per run, one fresh connection per call, to a private server from source (fake providers, auth off), with and without X-Loom-Code-Scope, two runs each: the code scope adds 9 to 26 ms at p50 with an empty trunk and 0 to 14 ms with one matching decision. The p99 differences are within run-to-run noise, far below the 3500 ms search.query budget. No ranking benchmark was run.
  • Left alone. answer_first's rules, context.pack, prompt recall and the session primer.

Compatibility, rollout and rollback

  • Wire: no op, field or default changes. The MCP loom_search description names the repository's docs and decisions, and its paging sentence follows memory.next_page. New setting LOOM_MEMORY_REPO_DECISIONS_TIMEOUT_S (live, 1.5); the generated reference, settings schema and example file follow.
  • Operator steps: none. Rollback: revert; nothing is stored.

Tests

  • tests/unit/test_loom_search_repo_decisions.py:
    • Placement by similarity and the never-displaces rule.
    • Dedupe, and no home row pushed out (the base search's role ceiling stands, decisions ride above it).
    • Abstain cleared with the decision calibration.
    • Credit for merged decisions only.
    • candidates_total and the paging text.
    • Pinned inputs through the real resolver: no model call, the token's pin and the namespace defaults.
    • bodies="none" passed through, quality_filter off, and a failing base search cancelling the pass.
    • Failing, slow or abstaining decision searches.
    • Block re-rendering after answer_first and the flags, and a withheld decision absent from the MCP text.
    • Later pages, and consent narrowing.
  • tests/unit/test_repo_docs.py: the shared gate and the docs leg's use of it.
  • tests/integration/test_cross_principal_leakage.py:
    • Setup: a decision canary recorded through decision.record in the deployment's code namespace (LOOM_CODE_ORG / LOOM_CODE_NAMESPACE, as CI sets them), deleted afterwards.
    • Positive cases: a reader finds the canary under the code scope, and not without it or over HTTP.
    • Negative cases: a same-org non-reader and another org never see it. The same-org case asserts that its principal cannot read the row directly (CI's code namespace is not org-readable), so it runs rather than skips.
    • Mutation check (an earlier revision): with the ungated namespace lookup, the same-org case fails.
  • Rebased onto main after the decision-record changes (decision rows are statements). The full tests/unit passed at 8dd351c4 (24541 passed, 20 skipped, 1 xfailed); the last commit rewords a comment and inlines a test helper. The integration file passed against a private server, auth off and on, before the rebase and the canary change; it has not been re-run since.

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 gate runs before any read of the trunk namespace, and the mutation check above.

  • 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. (Format, lint, typecheck and the full unit suite pass; the integration file has not been re-run since the canary change, see Tests.)
  • 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) and the Codex plugin copies (python3 scripts/codegen/agent_plugin_sync.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.

🤖 Generated with Claude Code

@zlareb1
zlareb1 force-pushed the feat/search-code-scope-decisions branch from d2fbf27 to abf00d1 Compare November 2, 2026 03:13
@zlareb1
zlareb1 force-pushed the feat/search-code-scope-decisions branch from 42363f5 to 8dd351c Compare November 2, 2026 05:20
@zlareb1
zlareb1 merged commit 06ed000 into main Nov 2, 2026
21 of 22 checks passed
@zlareb1
zlareb1 deleted the feat/search-code-scope-decisions branch November 2, 2026 05:49
@pufit pufit mentioned this pull request Nov 2, 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