Repository navigation
Carry the Pi bridge channel over a socket so every launcher works - #6857
Merged
ymichael merged 2 commits intoNov 2, 2026
Merged
Conversation
…s 3 and 4 bb's Pi extension talked to the bridge over extra stdio descriptors, which cmd.exe shims (pnpm), Bun's pi.exe, and launchers that start pi as a child process do not forward, so the extension failed to load with "Unsupported fd type: UNKNOWN" (#6790, #5332). The bridge now listens on a Unix socket in a private temp directory (a named pipe on Windows) and passes its address and a one-time token through BB_PI_BRIDGE_CHANNEL and BB_PI_BRIDGE_CHANNEL_TOKEN. The extension connects once per pi process, so reloads reuse the connection instead of opening a second reader on the same descriptor. Environment variables survive every launcher, so the Windows npm and Pi installer unwrapping in windows-pi-launch.ts is deleted; the version probe already launches .cmd shims through the host toolchain. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
ymichael
deleted the
bb/fix-pi-bridge-stdio-transport-on-windows-thr_dbjt58x49g
branch
November 2, 2026 22:25
ymichael
added a commit
that referenced
this pull request
Nov 2, 2026
## Human comments ## What was wrong Pi's installers (`pi.dev/install.sh`, `install.ps1`) create a managed install: a launcher in `~/.pi/agent/bin` (on Unix, symlinked from a PATH directory such as `~/.local/bin`) and releases under `~/.pi/agent/install`, marked by `managed-install.json`. Pi updates it with `pi update`. The Pi provider's maintenance bridge only knew Bun and npm global installs. It reported the managed install as `external` but still offered `npm install -g @earendil-works/pi-coding-agent@latest` for any install that wasn't Bun. Running that adds a second, npm-installed Pi and leaves the managed one on the old version. Reproduced with Pi's real installers pinned to 1.4.0 (served from a local API) on macOS with a sandbox `HOME`, and on the Windows 11 ARM64 VM with a sandbox `PI_CODING_AGENT_DIR`. Both called `getPiProviderInstallationStatus` / `getPiProviderInstallationRun` on main: ```text macOS installSource "external" installAction.command "npm install -g @earendil-works/pi-coding-agent@latest" Windows installSource "external" run.command "npm.cmd install -g @earendil-works/pi-coding-agent@latest" (executablePath ...\agent\bin\pi.cmd) ``` ## What changed - **`plugins/provider-pi/src/bridge/pi-managed-install.ts` (new)**: `resolvePiManagedInstallRoot` resolves the `pi` on PATH with `realpath` and reads `<agent>/install/managed-install.json` (BOM tolerated, validated with zod: `kind`, `schemaVersion: 1`, `layout: "releases-v1"`). #6857 removed the earlier Windows-only marker check, so this is now the only one. - **`provider-maintenance.ts`**: chooses the install or update command in this order: 1. Fresh install: npm, as before. 2. Managed install: `pi update --self`. This is checked before npm, so a managed launcher placed in npm's bin directory isn't treated as an npm install. 3. Bun: `bun add -g`, as before. 4. npm global: npm, as before. 5. Anything else: `pi update --self` instead of npm. Pi detects its own npm, pnpm, yarn or Bun install, or a configured update command, and fails with its own instructions when it can't. - **Install gate**: the "older than the supported minimum" message now gives the command that matches the install. - **`installSource` is unchanged.** Managed installs report `external`, as Claude's native installs do, so there's no wire or SDK change and no protocol bump. - README updated. Related to #3166: this stops bb from creating a duplicate npm Pi. It doesn't add the general detection #3166 asks for, which would recognise installs owned by another package manager across all providers. ## How you verified - New `provider-maintenance.install-source.test.ts`: - covers a managed launcher inside npm's bin directory, the installer's relative PATH symlink, an invalid marker layout (still npm), an unclassified install, and the install-gate message; - four of the five tests fail on main; the fifth checks that a real npm install still gets npm. - `pnpm exec turbo run test typecheck lint --filter=bb-plugin-provider-pi`: 39 files, 348 passed, 5 skipped. - **macOS, rebased onto c236529:** the 1.4.0 managed sandbox now offers `pi update --self`. Before the rebase, running that command updated the managed install to 1.5.0 and left the npm Pi at 1.4.0. Status afterwards showed `currentVersion 1.5.0`, `installAction null`. - **Windows VM, before the rebase:** the bundled status reported `pi update --self` for `...\agent\bin\pi.cmd`. `cmd.exe /d /s /c "pi update --self"` updated it from 1.4.0 to 1.5.0, the npm Pi stayed at 1.4.0, and status afterwards was clean. The user PATH was unchanged and the sandbox was removed. > AGENT GENERATED 🤖 Generated with [Claude Code](https://claude.com/claude-code) --------- Co-authored-by: Claude Opus 5.5 <[email protected]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Human comments
What was wrong
bb's Pi extension talked to the bridge over extra stdio descriptors: the bridge spawned Pi with five pipes, and the injected extension read fd 4 and wrote fd 3. Launchers pass on only stdin, stdout and stderr. That includes
cmd.exeshims, Bun'spi.exeshim, and any wrapper that starts Pi as a child process (such as the Pi installer'spi-launcher.js). Behind any of them the extension failed to load withFailed to load extension: Unsupported fd type: UNKNOWN(#6790, #5332). #5271 and #6839 worked around two specific launchers by unwrapping them inwindows-pi-launch.ts. Other launchers were still broken.Reproduced on the Windows 11 ARM64 VM on main 5758191 with Pi 1.4.0 and Node 24.22.0. A harness bundles the bridge with the real extension, waits for the extension's
ready, then sends amodel-scoperequest over the channel and waits for the reply:On macOS, main fails the same way behind the Pi installer's launcher (
extension ready timed out), because it starts Pi as a child process with only standard stdio.What changed
plugins/provider-pi/src/bridge/bridge-channel.ts(new): the bridge listens on a Unix socket in a privatemkdtempdirectory, or on a random named pipe on Windows. It passes the address and a one-time token to Pi inBB_PI_BRIDGE_CHANNELandBB_PI_BRIDGE_CHANNEL_TOKEN.rpc-child.ts: spawns Pi with plain stdio (pipe×3) and routessendChanneland channel lines through the socket. A listen error is appended to the stderr tail and kills the child.bb-pi-extension.ts:globalThis, so the factory runs Pi repeats onctx.reload(),newSession()andswitchSession()reuse it. On main, a second load threwEEXISTopening fd 4 again, so reloads were already broken.Bun.file(4)reader, becausenet.connectworks under Node and Bun.windows-pi-launch.tsand its tests. Env vars reach Pi through every launcher, so the npmpi.cmdand Pi-installer unwrapping (Fix Pi Windows npm shim probing and RPC pipes #5271, Run Pi installer managed launches directly on Windows #6839) is no longer needed. The version probe already launches.cmdshims through the host toolchain (experimental_execHostFile, since One host toolchain for executable discovery, child PATH, and proxy/CA defaults #6194), soresolvePiProcessLaunchis gone too.packages/provider-bridge-protocol/src/testing/replay-provider-child.mjs: thepi-rpcreplay dialect connects to the same socket instead of fds 3 and 4.fake-pi-rpc.mjs): waits for the extension factory, as Pi does, and adds a/reloadprompt that reloads the extension./reload.Killing a session leaves no Pi processes behind, so no unwrapping had to stay:
experimental_killPortableProcess, i.e.taskkill /T /F) kills the shim's whole process tree. Closing stdin also ends Pi throughcmd.exeand Bun's shim.Measured on the VM: pnpm
pi.cmdand Bunpi.exe, each killed by tree kill, by stdin EOF, and by killing the root only, all left zero Pi processes. The managed launcher on macOS also left zero under both kill and graceful close.No wire, CLI, SDK-surface or user-configuration changes. The two new env vars pass between the bridge and its Pi child only.
check-plugin-sdk-version.mjsreports the surface unchanged.Known limitation:
pnpm parityuses one replay child for both checkouts. A Pi parity comparison between a checkout from before this PR and one after it shows the older side as empty. Comparisons where both checkouts include this PR work.How you verified
New tests:
bridge.launchers.test.ts, all platforms:stdio: "inherit"./reload.bridge.launchers.test.ts, Windows only (runs in theplugins-1Windows shard): the same round trip through a pnpm-templatepi.cmd, and through the Pi installer'spi.cmd+pi-launcher.js.bridge-channel.test.ts: a wrong-token connection is closed, gets no data, and its lines are never delivered. Queued messages reach the authenticated connection.Both all-platform launcher tests fail against main's transport: the child-launcher test times out, and the reload test fails with
open EEXIST.The existing Windows npm-shim tests (
bridge.install-gatemodel/list andprovider-maintenance.versionprobe) stay and now run throughcmd.exewithout unwrapping.Commands:
All tasks pass on macOS. The provider-pi run includes the Bun runtime test (Bun 1.3.0).
Recorded Pi sessions: I ran
pnpm parity --provider pimain-vs-main and branch-vs-branch with--dump-dir. Both pass 9/9 cells (1 skipped), anddiff -rof the two dump directories is empty: the normalized events and rows are byte-identical.Native Windows 11 ARM64 VM (Node 24.22.0, Pi 1.4.0, Bun 1.4.4), real Pi with the branch's bridge and extension:
On the same VM I ran vitest directly on the branch source, because Turbo's binary crashes on this ARM64 VM.
bridge-channel,bridge.launchers(all 5, including both Windows-only tests),bridge.install-gate,provider-maintenance.versionandbridge.bun-runtimepass. Threebridge.relocationtests fail there because they shell out tocygpathand the VM has no Git for Windows; this change doesn't touch them.macOS with real Pi 1.4.0, for npm global
pi, the Pi installer launcher andbun cli.js: the channel round trip succeeds under both graceful close and kill, with no leftover processes. On main, the installer launcher fails.Not tested: Volta, which isn't installed on the VM.
Refs #6790, #5332
🤖 Generated with Claude Code