Skip to content

backends: the pi backend still reads the brain through core's internal entry #1398

Open

Description

@schlessera

Part of #1345.

Blocked by #2523

Context

Delivered prerequisite outputs: #1349. Their output references remain relevant, but they are no longer active blockers.

The in-process pi backend imports core's internal entry for index and document operations. Under the ruling on #1345 (extension packages consume public entries only), these must go. #698 already moved its link and listing reads onto ./queries.

#2523 deletes pi's unused application writers first (BrainAccess.add/update/archive and the applyBrain-less fallback). Production never runs them: the worker always installs applyBrain (packages/ui-backend-pi/src/worker-entry.ts:196-201) and the fallback runs only without it (packages/ui-backend-pi/src/tools.ts:872-874). This issue therefore does not build replacement transports for add/update/archive; it migrates only the internal imports that survive that deletion. On a6b945b those are:

  • packages/ui-backend-pi/src/brain-access.ts:21-29 and :32-47: hybridSearch, assembleContext, indexAll, loadVecSupport, openDatabase, estimateTokens, initContext, resolveEmbeddingProvider, rerankSetup, safeResolve and the related types (minus whatever backends: pi keeps in-process copies of core's brain writers that production never runs #2523 leaves unused: ingest, archiveDocument, updateDocument, relevanceOnArchive).
  • packages/ui-backend-pi/src/tools.ts:49: isIsoDate, readDocumentPart, SEARCH_SORTS, SearchOptions.
  • packages/ui-backend-pi/src/worker-session.ts:3: safeResolve.

Re-run the inventory after #2523 merges; the list above is the starting point, not the final set.

Maintainer decision — 2026-10-10

Option B: pi performs brain operations through existing supported MCP/CLI contracts, retaining existing public query access where appropriate. Do not publish a new in-process operations API for this issue. The extension-package public-only rule remains binding.

Scope

  • Inventory every internal import remaining in packages/ui-backend-pi/src after backends: pi keeps in-process copies of core's brain writers that production never runs #2523, including operation types, parsing/validation helpers, provider resolution and initialization.
  • Replace the surviving read/context operations (search, context, and any index access they need) with thin adapters over existing MCP/CLI contracts. Use MCP for operations without an equivalent supported CLI command; do not add missing CLI operations merely to complete this migration.
  • Replace or remove residual helper/type imports (safeResolve, isIsoDate, readDocumentPart, SEARCH_SORTS and types) with public entries or local code that does not duplicate a core policy.
  • Retain existing public query entry usage where appropriate; remove every @schlessera/brain/internal import from packages/ui-backend-pi/src.
  • Preserve pi's outward tool names, schemas, results, error behavior and permission checks. Do not bypass approval, root/path constraints or execution-wrapper/environment restrictions when introducing subprocess/transport calls.
  • Define transport ownership, bounded cancellation and shutdown so abandoned calls cannot leak children/connections. Avoid a process/connection per call where a safely owned existing transport can be reused.
  • Keep indexing, search degradation and configured provider resolution within core's supported operation path; do not recreate those policies in pi.

Out of scope

Acceptance criteria

  • grep -rn "@schlessera/brain/internal" packages/ui-backend-pi/src returns nothing.
  • runBackendContract passes for pi unchanged.
  • A per-operation inventory (in the PR) maps every internal import present after backends: pi keeps in-process copies of core's brain writers that production never runs #2523 to a supported MCP/CLI or existing public query path, with explicit shape/error adaptation and no new public core operations API.
  • Real offline/keyless adapter integration tests exercise search/context/read/list/graph against a temporary fictional brain, checking observable results and index effects.
  • Write tools still route through applyBrain and assert the exact request (regression coverage only; the routing itself is not migrated here).
  • Tests cover missing/incompatible index, keyless search degradation, operation failures, cancellation and owned transport/child shutdown; permission and exec-wrapper boundaries remain enforced.
  • A targeted mutation proves an adapter/permission/operation regression fails the intended behavioral assertion, then passes after restoration.

Verification

grep -rn "@schlessera/brain/internal" packages/ui-backend-pi/src
bun run test packages/ui-backend-pi packages/core
bun run test tests/pi-worker-runtime.test.ts
bun run typecheck

Contract impact

No supported surface change intended. Existing CLI/MCP contracts and pi outward tool contracts remain unchanged; investigate and report any unavoidable mismatch rather than silently changing behavior. No new public operations API. Include any required user-visible/runtime changeset according to repository policy.

2026-10-24: narrowed to migrating the internal imports that survive #2523's deletion of pi's unused writers (no add/update/archive transports), added Blocked by #2523, and refreshed the import inventory to a6b945b. Earlier update history is in the comments.

Activity

  1. added
    type: refactor
    area: core
    area: backends
    priority: p2
    needs: decision
    blocked
    on Oct 9, 2026
  2. schlessera commented on Oct 9, 2026

    @schlessera
    OwnerAuthor

    Decision (maintainer, 2026-10-10): Option B — use existing supported MCP/CLI contracts for pi's brain operations, retaining existing public query access where appropriate. Do not publish a new in-process core operations API. Operations without a supported CLI equivalent use MCP rather than expanding the CLI as part of this migration.

    Remove all core internal helper/type imports as well as operation imports, preserve tool schemas/results and permission posture, and verify execution-wrapper, cancellation and owned transport lifecycle behavior. The body now includes the operation mapping and behavioral proof requirements.

    No decision questions remain. Remove needs: decision, add agent-ready, and retain blocked for #1349.

  3. added
    agent-ready
    and removed
    needs: decision
    blocked
    on Oct 9, 2026
  4. schlessera commented on Oct 10, 2026

    @schlessera
    OwnerAuthor

    Unblocked: #1349 merged in #1468 (62cf4d6), its only listed blocker.

  5. added
    blocked
    on Oct 23, 2026
  6. schlessera commented on Oct 23, 2026

    @schlessera
    OwnerAuthor

    Body history before the 2026-10-24 rewrite, kept here because the body now carries only the current specification:

    2026-10-24: #2523 owns deleting pi's unused add/update/archive writers. This issue now migrates only the internal imports that survive that deletion, and is blocked by #2523.

  7. changed the title [-]backends: the pi backend reads and writes the brain through core's internal entry[/-] [+]backends: the pi backend still reads the brain through core's internal entry[/+] on Oct 24, 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: coreblockedpriority: p2type: refactor

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions