Skip to content

Pi bridge never calls bindExtensions(), so session_start never fires for Pi extensions #1391

Closed

Description

@isw-sdasgupta

Summary

bb's Pi bridge creates agent sessions with createAgentSessionFromServices() and never calls AgentSession.bindExtensions(). Pi emits the session_start event (and resources_discover, and later session_shutdown wiring) from inside bindExtensions(), so in bb threads no Pi extension ever receives session_start. Any extension that performs its initialization in that hook is permanently inert inside bb.

Evidence (from installed [email protected] and its bundled @earendil-works/pi-coding-agent):

  • core/agent-session.js:1761 — await this._extensionRunner.emit(this._sessionStartEvent); inside bindExtensions().
  • First-party modes all call it: modes/interactive/interactive-mode.js:1364, modes/print-mode.js:53, modes/rpc/rpc-mode.js:230.
  • bb does not: host-daemon/dist/bb-pi-bridge.mjs uses createAgentSessionServices / createAgentSessionFromServices, and bindExtensions appears nowhere in bb-app.
  • Pi SDK docs state the embedder's duty: docs/sdk.md:165 — "if you use extensions, call runtime.session.bindExtensions(...) again for the new session".

This is generic to all Pi extensions, not MCP-specific. It is related to but distinct from #1087, which covered provider/model registration during cold-start model listing rather than the missing session_start emit.

Reproduction

  1. pi install npm:pi-mcp-adapter (v2.23.0).
  2. Configure a lazy MCP server, for example .pi/mcp.json:
{ "mcpServers": { "Atlassian": { "url": "https://mcp.atlassian.com/v1/mcp/authv2" } } }
  1. In a bb thread with the native Pi provider, call mcp({}).

Result: MCP not initialized on every call, forever — including mcp({ connect: "Atlassian" }). The adapter's tool metadata cache still works, so the tool description advertises the servers, which makes the failure look like an auth or config problem.

Expected: the adapter initializes, and mcp({}) reports server status.

Workaround

Add "lifecycle": "keep-alive" (or "eager") to each server in the MCP config. That satisfies the adapter's startLoadTimeInitialization() gate, which initializes at module load without depending on session_start. Cost: servers connect at startup and stay resident, so lazy startup is lost.

Fix direction

Call bindExtensions(...) from the Pi bridge on session creation, and again after every session replacement (newSession, switchSession, fork, clone, importFromJsonl), passing the bridge's mode, UI/command context, abort and shutdown handlers, and error listener.

Acceptance criteria

  • A Pi extension registering pi.on("session_start", ...) receives the event in a bb thread, for both a new thread and a resumed thread.
  • session_shutdown fires on session teardown and replacement, so extensions can release resources.
  • After session replacement, extensions are rebound to the new AgentSession (no handlers left attached to the disposed session).
  • Regression test: a fixture extension records session_start / session_shutdown for create + replace, with no network or credentials required.
  • Verification: with a lazy MCP server and no lifecycle field, mcp({}) returns server status in a bb thread.

Activity

  1. MPIsaac-Per commented on Aug 12, 2026

    @MPIsaac-Per
    Contributor

    Confirmed independently on macOS with bb 0.37.0, LM Studio/Qwen 3.6, and pi-mcp-adapter 2.23.0.

    In BB’s native Pi provider, every mcp invocation returns MCP not initialized, including status, connect, auth, and tool calls. The failure persisted after the BB host daemon restarted. The same Pi installation loads the adapter outside BB.

    I inspected the BB session trace and adapter state. No request reached Linear or Twenty. This reproduces the missing bindExtensions() / session_start path described here.

  2. self-assigned this
    on Aug 12, 2026
  3. added a commit that references this issue on Aug 12, 2026
    b6aa4d2
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions