Skip to content

core, backends: honor explicit path scope throughout context assembly #3644

Open

Description

@schlessera

Part of #3640.
Blocked by #3683

Context

Delegated research may require evidence from a defined document set while excluding work handled elsewhere. (assembleContext, packages/core/src/lib/context-assembler.ts:239-371) loads canonical documents, retrieved sections and related neighbours, but callers cannot constrain all these paths explicitly. Turning off canonical inclusion does not prevent the same path from returning as a search hit or neighbour.

Core passes identity/current-focus flags through (contextBriefing, packages/core/src/lib/ops/read.ts:115-130). Pi intentionally disables their automatic injection (async context, packages/ui-backend-pi/src/brain-access.ts:224-243) and exposes fewer parameters (brainContextTool, packages/ui-backend-pi/src/brain-tools.ts:158-174). Preserve that existing distinction for unscoped calls; do not describe both defaults as the same.

Scope

  • Add explicit bounded include/exclude path scope to context assembly and its CLI/MCP/Pi front doors, with clear exact-path/prefix semantics and precedence. An explicit exclusion wins throughout assembly, including automatic canonical content and graph-related enrichment.
  • Allow callers to gather a budgeted briefing from a known set of paths, with query-driven selection where requested, without silently expanding into unrelated content.
  • Return/document enough coverage information to distinguish a scoped briefing from a complete inventory and show what was omitted for budget or availability.

Out of scope

Changing the meaning of unscoped calls, inventing summaries, new query languages/extension seams, provider-history rewriting and broadening access through a caller's include list. Ranked retrieval remains different from exhaustive enumeration, which the discovery child owns.

Acceptance criteria

  • Additive schemas specify bounded inputs, scope combination and canonical/related behavior consistently across the CLI, MCP and Pi. Existing unscoped behavior and budget/monotonicity guarantees remain covered.
  • A fixture excludes context/current-focus.md and projects/_index.md while making both canonical/relevant/linked candidates. Neither file is opened or its content returned through the context operation, including fallback, section expansion and neighbour enrichment.
  • A known include set constrains candidate selection and expansion as documented; exclusions override includes, aliases cannot bypass containment or scope, and unrelated documents never fill spare budget.
  • Every returned excerpt retains its actual source path and selection provenance. Budget exhaustion, unavailable content and omitted requested paths are explicit; completeness is never inferred from a successful briefing.
  • Scope applies before excluded source hydration and consistently to all retrieval lanes. Existing policy/provider masks still dominate caller scope.
  • Keyless real CLI/MCP and Pi tests verify the behavior. Mutations that ignore the scope in the canonical path, search expansion or neighbour path each trigger the intended assertion, then pass after restoration.
  • A scoped project-evidence task is evaluated against targeted individual reads without losing required evidence or claiming the briefing enumerates every project.

Verification

Use pinned-date Odysseus fixtures, sentinel file-open instrumentation and the existing context-assembler.test.ts, MCP/CLI contract, Pi context and provider-history suites. Exercise the actual runtime as well as pure selection tests. Run focused bun run test, typecheck/lint and preflight; keep external model evaluation outside offline tests.

Contract impact

Additive optional CLI/MCP/Pi inputs and any new coverage envelope need the owning contract updates, schema snapshots/API reports, CONTRACT: prefix and minor changeset. Do not change an existing string result into a required object or alter old defaults under an additive label. 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.


Updated 2026-11-08: Everything else in this issue landed on main in #3721 (merge 26b45cb, from sub-PR #3675). One acceptance criterion remains: "A scoped project-evidence task is evaluated against targeted individual reads without losing required evidence." The evaluation ran, but the scoped briefing kept only a snippet of one raft status fact, because section expansion cannot widen a chunk that merged two short sections. Coverage reports that excerpt as a snippet. #3683 is the fix. Once #3683 lands, rerun the project-evidence evaluation from #3675 and close this issue on a full result. Alternatively, a maintainer may accept the honest-coverage result as meeting the criterion.

Activity

  1. added
    type: feat
    area: core
    area: mcp
    area: backends
    contract
    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-3644).

    • Branch: feat/3644-context-path-scope, 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

    Delivered to the epic branch (2026-11-08): #3675 merged into epic/3640-bounded-retrieval as 561091e. Its ready-candidate proof run passed on head 65284ac. This issue stays open until the epic lands on main.

    What shipped:

    • brain context --include/--exclude (repeatable), MCP brain_context include/exclude, and the same Pi parameters, all served by one shared assembler. Each list takes up to 64 entries of 1–512 characters.
    • An entry is an exact path, or a folder when it ends in /. There are no globs. An exclusion always wins over an inclusion, matches any casing and follows the real path, so a symlink cannot get round it.
    • Scope applies before any file is opened, in every lane: canonical, search pool, section expansion and related neighbours. It only narrows what is returned; masks and policy still dominate.
    • A scoped call returns an additive coverage record. It lists each excerpt with its path, lane and form, and each omitted path with a reason: budget, unavailable, not_ranked or excluded. It always says exhaustive: false. The coverage note is bounded to 20 partial excerpts and 20 omissions.
    • Unscoped calls are byte-identical to before, and Pi still never injects identity or current focus.

    Decisions taken within scope:

    • An exact include that the query does not rank is reported as not_ranked rather than loaded anyway.
    • An include list that does not cover the identity or current-focus document leaves that document out.

    Evaluation limit: on the scoped project-evidence task, nothing was lost silently, but one raft status fact was cut. Existing section expansion cannot widen a chunk that merged two short sections, so the briefing kept only a snippet, and coverage marks that excerpt as one. That is filed as #3683.

    Mutation receipts are in #3675: the canonical, search and neighbour lanes each ignoring scope, and the real-path check removed. Each fails its named test before restoration.

  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
  9. added
    blocked
    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: mcpblockedcontractpriority: p2type: feat

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions