Skip to content

backends: pi owns its web-search configuration helpers behind a public Settings adapter #1374

Open

Description

@schlessera

Part of #1345.

Context

Delivered prerequisite outputs: #1399 (merged in #1461). RTK rewriting is already public toolkit under the later #1345 ruling and #1399; do not reopen it.

This issue originally classified four families of ui-sdk helpers that are not wire protocol. All four are ruled (2026-10-09, see comments). On 2026-10-24 it was split so each ruled family has its own task:

Push handlers are not a remaining family: they stay at the public SDK ./push-handlers entry (ruling below) and are a constraint, not work.

Where web-search lives today (a6b945b). The pi-specific catalog, path, routing, override and brief logic is in packages/ui-sdk/src/server/web-search.ts and reaches its consumers through SDK /internal (packages/ui-sdk/src/internal.ts:15):

  • pi imports it from @schlessera/brain-ui-sdk/internal (packages/ui-backend-pi/src/config/env.ts:23-29), against the extension public-only rule; this is why ci: extension packages may import only public entry points #1400 is blocked by this issue.
  • ui-server's Settings route imports it the same way (packages/ui-server/src/routes/web-search.ts:35-44).
  • Only the neutral WebSearchBrief type is public (packages/ui-sdk/src/server/index.ts:113).

The "cache invalidation" behaviour is currently a no-op. After a Settings PUT the route calls mod.invalidateExtensionCache?.() on the loaded pi module (packages/ui-server/src/routes/web-search.ts:309-320). #1052 removed that export from the pi root (docs/decisions/public-export-boundary.md:247; packages/ui-backend-pi/src/index.ts:10-31), so the optional call does nothing and raises nothing. packages/ui-backend-pi/src/extension-cache.ts:18 has no importer, and the route test passes only because it injects a fake module that has the export (packages/ui-server/tests/web-search-routes.test.ts:58). Pi sessions now run in worker processes (launchAgentWorker, packages/ui-backend-pi/src/worker-session.ts:181), so clearing the server process's module cache may not affect a new session even if it ran.

Maintainer decision — web-search A (2026-10-09)

Pi owns its configuration helpers, with a public configuration adapter for Settings. Move pi-specific catalog/path/routing/override/brief logic into the pi backend and expose the narrowly documented public adapter ui-server needs. UI-server uses the existing optional lazy backend loading path and keeps unrelated startup working without pi. Pi must not consume SDK /internal. Retain the public neutral WebSearchBrief prompt input if still needed by SDK prompt composition; do not move unrelated prompt-builder APIs merely because they accept that type.

Preserve configuration-file semantics, precedence, provider ordering, credential-presence reporting without key disclosure and unmanaged-key retention. This is ownership refactoring, not permission to alter search behavior, billing policy, paths or host configuration format. Inventory current public SDK exports before removal; any public removal needs explicit migration classification and documentation.

Push (2026-10-09, unchanged): keep registerPushHandlers, PushHandlerOptions and PushCapableScope at the public SDK ./push-handlers entry with their signatures and listener/notification/deep-link/renewal behavior. Nothing here moves or retypes them.

Scope

  • Move the web-search configuration helpers from packages/ui-sdk/src/server/web-search.ts into packages/ui-backend-pi, keeping WebSearchBrief in the SDK where prompt composition needs it.
  • Expose a narrow, documented public pi configuration adapter that the Settings route loads through the existing optional lazy backend loading path (loadBackendModule), and point packages/ui-server/src/routes/web-search.ts at it instead of SDK /internal.
  • Configuration refresh, not the obsolete call. First establish whether a new pi session already re-reads web-search.json after a Settings PUT under per-session workers. If it does, delete extension-cache.ts and the route's invalidateExtensionCache call, and record the evidence in the PR. If it does not, put the refresh behind the new adapter and make the route call it. Either way, a test against the real pi package proves the refreshed configuration reaches the next session.
  • Remove the moved names from SDK /internal; update the API reports, docs/decisions/backend-authoring-toolkit.md, docs/decisions/public-export-boundary.md and the pi README together.

Out of scope

Acceptance criteria

  • git grep -nE 'readWebSearch|resolveWebSearchConfigPath|webSearchProvider|WEB_SEARCH_PROVIDER' -- packages/ui-backend-pi/src packages/ui-server/src shows no import from @schlessera/brain-ui-sdk/internal.
  • Real Settings GET/PUT tests against the real pi package keep configuration precedence, provider ordering, unmanaged keys and key-presence reporting; no credential value appears in any response.
  • A test that loads the real pi package (no injected fake module) proves a Settings PUT is visible to the next pi session, or the PR records the evidence that it already is and the dead extension-cache.ts and route call are deleted. packages/ui-server/tests/web-search-routes.test.ts no longer injects invalidateExtensionCache.
  • UI-server loads the pi adapter optionally/lazily: a no-pi packed startup and unrelated features still work, and a configured-but-missing or incompatible adapter gives an explicit, tested result.
  • Push handlers remain at ./push-handlers with unchanged signatures; api-report shows no push change.
  • A mutation that breaks precedence in the moved helpers fails a named Settings assertion, recorded in the PR.

Verification

bun run test packages/ui-sdk packages/ui-backend-pi packages/ui-server/tests/web-search-routes.test.ts
bun run api-report
bun run typecheck

Contract impact

Additive public pi configuration adapter (@experimental unless the decision record says otherwise): contract label, CONTRACT: commit, API report and integration contract in the same commit, minor changeset. The moved names leave SDK /internal only; no public SDK name is removed. If the inventory finds a public SDK web-search name that must go, stop and classify it on this issue first.

2026-10-24: split the geo, link-policy and execWrapperSpawnOptions families into #2770, #2771 and #2772; narrowed this issue to pi web-search ownership; folded in the 2026-10-22 finding that cache invalidation is a no-op and required real-package configuration refresh instead; removed breaking (the approved break moved to #2770); raised to p2 because #1400 depends on it.

Activity

  1. added
    type: refactor
    area: ui-sdk
    priority: p3
    needs: decision
    on Oct 9, 2026
  2. added
    blocked
    on Oct 9, 2026
  3. schlessera commented on Oct 9, 2026

    @schlessera
    OwnerAuthor

    Decision (maintainer, 2026-10-09): web-search family A

    Move pi web-search configuration ownership into ui-backend-pi, exposing a narrow public configuration adapter for Settings. UI-server consumes it through optional lazy loading; pi no longer imports these helpers from SDK /internal. Preserve existing paths/config precedence, provider ordering, credential-presence semantics, unmanaged fields and cache invalidation. Keep neutral SDK prompt types where still needed.

    The body records this family’s home and compatibility inventory requirement. RTK is already ruled public toolkit in #1399. Push handlers, geo compatibility exports and link-policy ownership remain unresolved; retain needs: decision and the #1399 blocker.

  4. schlessera commented on Oct 9, 2026

    @schlessera
    OwnerAuthor

    Classification evidence (2026-10-09): push handlers

    Keep the service-worker helpers at the existing public SDK ./push-handlers entry. The package exports it and docs/http-api.md explicitly documents its renewal dependency on the supported push-subscription lifecycle. It is SDK client-integration logic for independent PWA shells; it need not be wire schema to remain public.

    This follows the existing supported boundary rather than reopening it. Preserve signatures and notification/deep-link/renewal behavior; any typing cleanup must retain real service-worker compatibility. The body now records push as resolved. Geo compatibility exports and link-policy ownership remain open; keep needs: decision.

  5. added
    contract
    breaking
    on Oct 9, 2026
  6. schlessera commented on Oct 9, 2026

    @schlessera
    OwnerAuthor

    Decision (maintainer, 2026-10-09): geo aliases A

    Remove SDK geo compatibility re-exports; consumers import directly from the canonical public brain-geo entries. This approves a breaking import migration, with exact old-to-new import documentation and API-report/contract updates, without deprecated SDK aliases. Geometry behavior stays unchanged. Remaining protocol/implementation use of geo is not removed merely because aliases disappear.

    The body now records the geo home and migration. Refreshed main already puts shared link policy in render-template’s public /links entry, with UI-kit forwarding to it; SDK still depends on UI-kit for that policy. The dependency edge is the remaining choice. Retain needs: decision and #1399 blocker; add contract/breaking for the approved alias removal.

  7. added
    agent-ready
    and removed
    needs: decision
    on Oct 9, 2026
  8. schlessera commented on Oct 9, 2026

    @schlessera
    OwnerAuthor

    Decision (maintainer, 2026-10-09): link policy A and completed classification

    SDK consumes the existing public render-template /links implementation directly. Approve SDK→render-template, migrate SDK imports and remove SDK→ui-kit from its manifest/allowed edges once no uses remain. Keep UI-kit’s /links compatibility export and preserve one policy implementation and identical handler/card verdicts.

    The body consolidates all family homes: pi owns web-search through a public Settings adapter; push remains its documented public SDK integration; SDK geo aliases are removed with a breaking migration; link policy remains in render-template; RTK is already public toolkit under #1399. It includes source/packed/optional-install and behavioral verification requirements and documentation updates.

    No classification decision remains: remove needs: decision and add agent-ready, keeping blocked on #1399 and contract/breaking. No implementation is claimed complete.

  9. schlessera commented on Oct 10, 2026

    @schlessera
    OwnerAuthor

    Unblocked: #1399 is closed, so scripts/sync-project.ts is removing the blocked label.

  10. removed
    blocked
    on Oct 10, 2026
  11. schlessera commented on Oct 10, 2026

    @schlessera
    OwnerAuthor

    Unblocked: #1399 merged in #1461 (02fd0b9). The helpers both backends import are now public on @schlessera/brain-ui-sdk/server. execWrapperSpawnOptions (host + pi), bashCommand (Claude only), SUBPROCESS_ENV (host only), GIT_LOCK_KEY and canonicalModelId stay in /internal; see the inventory in docs/decisions/backend-authoring-toolkit.md.

  12. schlessera commented on Oct 21, 2026

    @schlessera
    OwnerAuthor

    New evidence from a repository review on 2026-10-22: preserving extension-cache invalidation currently preserves a no-op.

    • CONTRACT: refactor(packages): curate public exports and align the 1.0 stability contract #1052 (825cd044e, released in 0.41.0) removed invalidateExtensionCache from the @schlessera/brain-backend-pi root (docs/decisions/public-export-boundary.md:247). It is in neither the root (packages/ui-backend-pi/src/index.ts:9-19) nor ./internal (packages/ui-backend-pi/src/internal.ts:6-8).
    • The Settings PUT still calls it optionally (packages/ui-server/src/routes/web-search.ts:313-317), so mod.invalidateExtensionCache?.() does nothing and no error is raised. packages/ui-server/tests/web-search-routes.test.ts:58 injects a fake that has it, so the test passes.
    • packages/ui-backend-pi/src/extension-cache.ts has no importer in any src/.
    • Pi sessions now run in worker processes (launchAgentWorker, packages/ui-backend-pi/src/worker-session.ts:180), so clearing the server process's module cache may not affect a new session even when it does run.

    When this issue implements the web-search acceptance criterion "cache invalidation", please first establish whether a server-side invalidation is still meaningful under per-session workers. If it is, export it through the new pi adapter and cover it with a test that loads the real package. If it is not, delete extension-cache.ts and the route call, and record why in the PR.

    The same export cut also broke createPiAuth and with it every /api/pi-auth/* route. That is filed as a separate bug from the same review.

  13. schlessera commented on Oct 21, 2026

    @schlessera
    OwnerAuthor

    Repository review on 2026-10-22 (main dcf5341aa): the SDK→UI-kit edge this issue's link-policy A removes is still there, and it costs more than the link helper suggests. Current evidence, for whoever picks this up:

    • The only SDK source import of the kit is still packages/ui-sdk/src/server/bridge-tools/show-block.ts:1 (classifyLink, refusalSentence from @schlessera/brain-ui-kit/links), and packages/ui-sdk/package.json:105 still declares @schlessera/brain-ui-kit as a runtime dependency. packages/ui-sdk/src/tool-contracts/blocks.ts:423 still names @schlessera/brain-ui-kit/links as the classifier's home in a comment.
    • packages/ui-kit/src/links.ts:2 already only re-exports @schlessera/brain-render-template/links, so the SDK reaches render-template through the kit.
    • React peer leak. packages/ui-kit/package.json:82-85 declares react and react-dom as required peers (no peerDependenciesMeta), and :78-81 adds lucide-react as a dependency. Through the SDK's dependency on the kit, a server-only consumer such as a backend inherits a required React peer. That contradicts the SDK README's statement that its own optional react peer "is only exercised by ./client".
    • Workspace cycle. packages/ui-kit/package.json:88 devDepends on @schlessera/brain-ui-sdk, so today the manifests form ui-sdk → ui-kit → (dev) ui-sdk. Removing the SDK's runtime edge as approved here also removes that cycle.

    Suggested additions to the acceptance criteria, all checkable after the change:

    • git grep -n 'brain-ui-kit' packages/ui-sdk/src packages/ui-sdk/package.json returns no import and no dependency (comments updated to name render-template).
    • No package in ui-sdk's runtime dependencies declares a required react or react-dom peer (check each dependency's package.json; render-template declares none today).

    Found by a repository review on 2026-10-22.

  14. added
    area: backends
    area: ui-server
    priority: p2
    and removed
    priority: p3
    breaking
    on Oct 24, 2026
  15. changed the title [-]ui-sdk: classify the server helpers that are not wire protocol[/-] [+]backends: pi owns its web-search configuration helpers behind a public Settings adapter[/+] on Oct 24, 2026
  16. schlessera commented on Oct 24, 2026

    @schlessera
    OwnerAuthor

    2026-10-24: split and rewritten.

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: ui-sdkarea: ui-servercontractpriority: p2type: refactor

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions