Skip to content

core, backends: add bounded multi-document and section reads #3642

Closed

Description

@schlessera

Part of #3640.
Blocked by #3641

Context

Agents that already know several document paths or section requests currently issue one brain_read per item. A bounded aggregate operation can reduce per-call overhead and give the caller one total output budget. Implement only after the evaluation child supplies a positive contract decision and qualification gates; do not interpret a closed but negative/inconclusive spike as a go-ahead.

Current shared reading is (readDocument, packages/core/src/lib/ops/read.ts:139-147); the core wrappers are (registerReadTools, packages/core/src/mcp-server.ts:212-414) and Pi uses (brainReadTool, packages/ui-backend-pi/src/brain-tools.ts:178-221). (brainReadBaseResult, packages/ui-sdk/src/server/brain-read-base.ts:58-100) is an existing example of honest paging, but is a separate hosted-write base contract. Read the parent constraints and docs/integration-contract/mcp.md.

Scope

  • Implement the approved bounded read-many operation once in core with a CLI --json front door, MCP brain_read_many and Pi adapter, unless the spike's explicit decision chooses another additive naming shape.
  • Accept a bounded list of document/section requests, label each result with its path and selection, and enforce per-item plus complete serialized-response caps. Report full/outline/partial/error outcomes and continuation or unreturned requests without silently losing items.
  • Apply each member's existing containment/provider restrictions and cancellation, with bounded I/O/work and deterministic ordering. An unavailable member must not discard successful reads.
  • Integrate static tool rosters, read allowlists, voice/restricted postures and lock classification in both backends. Keep journal observation conservative unless the actual execution path proves the required capability; an annotation alone proves nothing.

Out of scope

Implicit recursive/glob ingestion, automatic traversal of related files, write batching, a generic batch executor, provider migration and treating a retrieval response/page hash as a hosted write-base authorization. Existing single-file calls and their output/defaults remain unchanged.

Acceptance criteria

  • CLI, MCP and Pi expose the approved schema and equivalent selection/error/budget semantics, using a shared operation rather than independent implementations.
  • Each requested item is accounted for and traceable. Missing/refused items, duplicates, invalid sections, insufficient aggregate budget and cancellation have deterministic documented behavior.
  • Hard bounds hold for file count, raw-read/work limits, selected content and serialized model-visible output, including metadata, warnings, escaping, large frontmatter/headings and non-ASCII text. Continuation makes progress and detects relevant source changes as specified.
  • Traversal, escaping symlinks, masked content and out-of-scope files remain refused per member. Mixed success/failure batches preserve the same authority as individual reads.
  • All legacy read and hosted brain_read_base contracts remain intact, including opt-in outline thresholds, exact section bytes and whole-document base receipts.
  • Real keyless MCP and Pi runtime proof exercises multi-item results, policy gating, concurrent callers and cancellation. Mutating a cap or containment check makes a named test fail on the expected assertion before restoration.
  • Evaluation compares the delivered operation with existing parallel reads under the spike's gates, reporting quality and request/token/latency evidence without assuming a speedup proportional to tool count.

Verification

Use Odysseus fixtures and the pinned date. Extend the real MCP contract/schema snapshots, CLI contract and Pi read/runtime tests as applicable. Run focused bun run test commands, the provider-history guard for both backends, typecheck/lint and bun run check:pr --base origin/main; preserve failing-first/restored receipts. Keep provider-cost experiments outside tests.

Contract impact

Additive CLI JSON/MCP/backend surface: update the relevant integration-contract components, schema snapshots and API reports in the same CONTRACT: commit, with contract and a changeset for a minor release. A legacy default-cap change is excluded by #383. Release scheduling follows the positive decision and is not assigned here.

Remaining contract decision

The maintainer must accept the positive contract and qualification gates from #3641 before implementation: distinct-tool/overload shape, units, numeric caps, partial/continuation and error semantics. Fold that selected result into this body. A closed negative or inconclusive spike does not satisfy this prerequisite. Recommendation: keep the additive distinct-tool candidate only if #3641 supports it; this is not approval. Keep needs: decision and blocked until the actual output is verified.

Triage 2026-11-08 at main 1619741f291f525d17cde4970a5ada40644117c1: Verified still-open #3641 and current read adapters. Priority p2 reflects wanted unscheduled work; readiness waits on the contract ruling.

Activity

  1. added
    type: feat
    area: core
    area: mcp
    area: backends
    blocked
    contract
    on Nov 6, 2026
  2. added
    priority: p2
    needs: decision
    on Nov 8, 2026
  3. self-assigned this
    on Nov 8, 2026
  4. schlessera commented on Nov 8, 2026

    @schlessera
    OwnerAuthor

    Claimed as part of the #3640 epic run (claim token c3640-ec699b9a-3642).

  5. schlessera commented on Nov 8, 2026

    @schlessera
    OwnerAuthor

    Delivered to the epic branch (2026-11-08): #3702 merged into epic/3640-bounded-retrieval as c40d04d. Its ready-candidate proof passed on head 26b15eb. This issue stays open until the epic lands on main.

    What shipped:

    • brain_read_many on MCP and Pi, plus brain read-many --json. All three are thin adapters over one core operation (readMany, packages/core/src/lib/ops/read-many.ts), built to the core, backends: qualify bounded multi-read contracts against parallel retrieval #3641 contract.
    • Limits:
      • up to 20 requests;
      • max_total_chars 24,000 (2,000–40,000) and max_item_chars 8,000 (min 512), both counted as JSON.stringify(result).length;
      • 4 MiB per file and 16 MiB per call for raw reads;
      • invalid input refused, never clamped.
    • Items:
      • each is full, outline, partial, duplicate or error;
      • each carries a sha256, and a continuation with a stale hash reports source_changed;
      • duplicates are folded;
      • errors carry codes and never host paths;
      • order is deterministic;
      • a cancel stops work between files.
    • MCP output is text only.
    • Authority per member equals an individual read: containment, symlinks out of the root, masks and policy are all checked.
    • The tool is in both backends' default read allowlists, the Claude voice posture (recorded in voice-permission.md), the no-lock reads and the index barrier.
    • Journal observation stays conservative: the tool is unproven and is not in HOST_READS. It is not in schedules (ui-server: scheduled jobs cannot use brain_read_many #3712), server instructions or skills, per the rollout gate that requires a recorded real-model trial first.
    • Legacy brain_read, readDocument and the hosted brain_read_base are unchanged.

    Evaluation: the #3641 harness was rerun against the real tool and passes 26/26. No speedup is claimed:

    • for the same content the batch is larger (four small files: 4,362 chars against 3,540);
    • it is smaller only where its cap cut content (20 notes: 23,921 against 29,022, with 5 items cut for budget).

    Provider tokens, cost and model usability are not measured. Choices made where the decision record left details open are listed in its "Delivered in #3642" section. The 14 mutation receipts are in #3702.

  6. added this to the 0.45.0 milestone on Nov 8, 2026
  7. removed their assignment
    on Nov 8, 2026
  8. added a commit that references this issue on Nov 8, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    area: backendsarea: corearea: mcpblockedcontractneeds: decisionpriority: p2type: feat

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions