Skip to content

core, backends: qualify bounded multi-read contracts against parallel retrieval #3641

Closed

Description

@schlessera

Part of #3640.

Context

Bounded multi-document reads may reduce overhead and improve response budgeting, but current tools can already execute concurrently. Establish the correct baseline and a concrete contract before shipping a new tool. The deliverable is a written decision and reproducible evidence; a no-go or explicitly inconclusive result is valid.

Read (readDocument, packages/core/src/lib/ops/read.ts:139-147), (brainReadTool, packages/ui-backend-pi/src/brain-tools.ts:178-221), (brainReadBaseResult, packages/ui-sdk/src/server/brain-read-base.ts:58-100), and (toolObservation, packages/ui-server/src/brain/tool-observation.ts:37-42). Core MCP registration is (registerReadTools, packages/core/src/mcp-server.ts:212-414). The existing search/context evaluation guide is docs/evaluating-search.md; it measures retrieval quality, not agent tool selection.

Scope

  • Specify a candidate brain_read_many contract: explicit path/section requests, maximum item count, per-item and aggregate serialized-output budgets, raw-read/work limits, outline/partial/continuation semantics, duplicate handling and item errors. Define byte/character/token units accurately and include metadata/escaping in the aggregate bound.
  • Compare equivalent sequential individual reads, parallel individual reads and bounded batches, including outline-to-section follow-ups. Separate known-path retrieval from discovery and later dependent reads.
  • Measure the actual CLI/MCP and Pi paths and host-inclusive overhead where the native fixture is available. Record cancellation, journal scheduling, load/runtime/package identities and transport boundaries without weakening protections.
  • Assess model usability with the same tasks, especially gpt-6.1-terra, when authorized model access is available. Keep live provider experiments outside offline tests; report unavailable evidence honestly.

Out of scope

Production tool/schema changes, new dependencies/seams, changed ranking, relaxed journal/permission guards and claims that every repeated path is redundant. Do not make an API key or external network a test requirement.

Acceptance criteria

  • A source-grounded contract proposal specifies every bound, unit, output discriminator, error and continuation behavior and preserves old single-read semantics. It compares a distinct tool with an overload and explains the choice.
  • Reproducible Odysseus scenarios cover small files, large frontmatter, many headings, huge lines, mixed scripts, late-document updates, missing/refused paths, sections and aggregate overflow. Use the pinned 2026-07-12 date.
  • Equivalent comparisons report evidence coverage/attribution, correctness, tool calls, actual provider-request grouping where observable, returned bytes, input/output/cache tokens where reported, latency and cost. Missing dimensions remain unavailable; timing overlap is not silently equated to provider-response identity.
  • At least one real keyless MCP/runtime exercise and one Pi exercise establish the mechanics. Scripted provider responses are identified as such and do not count as evidence that Terra chooses or understands the tool.
  • Repeated model trials, if run, retain their exact model/route/settings and task/fixture identities; their absence prevents a model-usability claim, not the independent keyless work.
  • The issue receives a decision explaining go/no-go, evidence limits, proposed safe defaults and rollout/verification gates. A positive decision supplies the inputs the production-read child needs; closure alone is not approval to ship an unsupported contract.

Verification

Reuse the repository's offline harness and real stdio MCP fixtures; place harness-only tests in experiments/ under docs/process/testing.md. Run the focused harness command through bun run test and record the exact commands and raw/aggregate evidence locations. If fixture prerequisites prevent a dimension, finish independent work and state what remains unqualified. Never reproduce a private corpus in committed evidence.

Contract impact

None for a written spike and private prototype. Any supported production API/CLI or exported contract change belongs to the implementation child and requires its contract update and changeset. No release milestone is assigned.

Triage 2026-11-08 at main 1619741f291f525d17cde4970a5ada40644117c1: Verified the cited shared operations and concrete Pi adapters. The independent brief is complete; p2 reflects wanted unscheduled work. External model evidence is optional and does not block the specified keyless work.

Activity

  1. added
    type: spike
    area: core
    area: mcp
    area: backends
    on Nov 6, 2026
  2. added
    priority: p2
    agent-ready
    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-3641).

    • Branch: spike/3641-bounded-read-contract, PR targeting the epic integration branch epic/3640-bounded-retrieval; the epic lands on main as one batch.
    • Readiness check (2026-11-08, origin/main 1619741): every code citation in this body still points at its named anchor.
    • Collision check over the cited files: no path collisions with open PRs; only shared test-category closure overlaps.
  5. schlessera commented on Nov 8, 2026

    @schlessera
    OwnerAuthor

    Spike decision (2026-11-08): go for a distinct, bounded brain_read_many, justified by bounding and attribution, not efficiency. Model usability is inconclusive because it was not measured.

    Delivered in #3674, merged into epic/3640-bounded-retrieval as 8843b7b. The record is docs/decisions/bounded-multi-read.md, the harness experiments/bounded-read-contract.test.ts, and the reusable helpers sit under experiments/bounded-read/.

    Go: a separate tool, not an overload of brain_read. It gives:

    • a cap on the whole answer and on each item;
    • per-item kinds (full, outline, partial, duplicate, error) with continuation;
    • a per-file sha256, so a file that changed between an outline and its follow-up surfaces as source_changed;
    • folded duplicates, with each file read once per call;
    • one envelope, one warning set and one journal observation instead of one per read.

    Today brain_read over MCP has no cap: a 70,612-char line came back whole, and parallel reads add up without a limit.

    The overload was rejected because it would:

    No efficiency claim. For the same content the batch is larger:

    • MCP: 4,530 vs 3,540 chars for four small files, because per-item metadata (~170 chars) costs more than the 74-char envelope it replaces.
    • Pi transcript: 4–12% more.
    • Parallel brain_read calls already come back in one assistant message and one follow-up request.
    • A dependent outline-then-section read still takes two rounds.

    Safe defaults for #3642:

    • up to 20 requests per call;
    • max_total_chars 24,000 (allowed 2,000–40,000), counted as JSON.stringify(result).length, metadata and escaping included;
    • max_item_chars 8,000 (minimum 512);
    • raw-read limits of 4 MiB per file and 16 MiB per call;
    • invalid input is refused, never clamped;
    • text-only MCP output;
    • the journal keeps observing the tool as unproven;
    • paging that reproduces the requested scope exactly.

    Rollout gates:

    • MCP and Pi ship together in one CONTRACT: commit with the schema snapshot, roster fixtures and a minor changeset.
    • This harness's tests and mutation set are rerun against the real tool.
    • The provider-history guard passes.
    • Skills and prompts do not steer agents toward the tool until a recorded real-model trial shows models choose and use it correctly.

    Evidence limits: offline mechanics only, through the real stdio MCP server and Pi's agent loop with a scripted faux provider. Provider tokens, cache, cost, real request grouping and model usability are unavailable. No real-model trial was authorized.

    Follow-ups filed: #3680 (host path in the brain_read error), #3681 (a same-content rewrite stays stale), #3682 (Pi clip units). #3642 is unblocked by this decision; the dependency is satisfied once this issue closes.

  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

    agent-readyarea: backendsarea: corearea: mcppriority: p2type: spike

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions