Repository navigation
Description
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);insidebindExtensions().- 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.mjsusescreateAgentSessionServices/createAgentSessionFromServices, andbindExtensionsappears nowhere inbb-app. - Pi SDK docs state the embedder's duty:
docs/sdk.md:165— "if you use extensions, callruntime.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
pi install npm:pi-mcp-adapter(v2.23.0).- Configure a lazy MCP server, for example
.pi/mcp.json:
{ "mcpServers": { "Atlassian": { "url": "https://mcp.atlassian.com/v1/mcp/authv2" } } }- 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_shutdownfires 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_shutdownfor create + replace, with no network or credentials required. - Verification: with a lazy MCP server and no
lifecyclefield,mcp({})returns server status in a bb thread.
Activity
MPIsaac-Per commentedon Aug 12, 2026
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
mcpinvocation returnsMCP 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_startpath described here.Fix Pi extension lifecycle in native bridge (#1394)