Repository navigation
Run Pi installer managed launches directly on Windows - #6839
Merged
Merged
Conversation
Pi 1.4.0's installer (pi.dev/install.ps1) puts a managed pi.cmd in ~/.pi/agent/bin that runs cmd.exe, then pi-launcher.js, which re-spawns the CLI with stdio "inherit". On Windows neither hop forwards descriptors 3 and 4, so bb's Pi extension failed with "Unsupported fd type: UNKNOWN" and neither the model catalog nor threads could start. Recognise the managed launcher by Pi's own install marker (releases-v1 layout), resolve the active release's CLI the way pi-launcher.js does, pick the same Node, and set PI_MANAGED_INSTALL_ROOT as the launcher would. Fixes #6790 Co-Authored-By: Claude Opus 5.5 <[email protected]>
ymichael
added a commit
that referenced
this pull request
Nov 2, 2026
) ## 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.exe` shims, Bun's `pi.exe` shim, and any wrapper that starts Pi as a child process (such as the Pi installer's `pi-launcher.js`). Behind any of them the extension failed to load with `Failed to load extension: Unsupported fd type: UNKNOWN` (#6790, #5332). #5271 and #6839 worked around two specific launchers by unwrapping them in `windows-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 a `model-scope` request over the channel and waits for the reply: ```text pnpm pi.cmd CHANNEL FAILED: pi exited (code 1, signal null): Error: Failed to load extension "...\bb-pi-extension.mjs": Failed to load extension: Unsupported fd type: UNKNOWN bun pi.exe CHANNEL FAILED: pi exited (code 1, signal null): Error: Failed to load extension "...\bb-pi-extension.mjs": Failed to load extension: Unsupported fd type: UNKNOWN ``` 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 private `mkdtemp` directory, or on a random named pipe on Windows. It passes the address and a one-time token to Pi in `BB_PI_BRIDGE_CHANNEL` and `BB_PI_BRIDGE_CHANNEL_TOKEN`. - It accepts only a connection whose first line is the token. Named pipes are listable, and other users can read them by default. - It queues bridge-to-extension messages until that connection arrives, then stops listening. - It closes the socket and removes the directory when Pi exits. - **`rpc-child.ts`**: spawns Pi with plain stdio (`pipe` ×3) and routes `sendChannel` and channel lines through the socket. A listen error is appended to the stderr tail and kills the child. - **`bb-pi-extension.ts`**: - Reads both env vars and removes them, so Pi's own child processes don't inherit them. - Waits for the connection before finishing its load; Pi 0.84 and 1.4 both wait for extension loading. - Keeps one connection per Pi process on `globalThis`, so the factory runs Pi repeats on `ctx.reload()`, `newSession()` and `switchSession()` reuse it. On main, a second load threw `EEXIST` opening fd 4 again, so reloads were already broken. - Drops the Bun-only `Bun.file(4)` reader, because `net.connect` works under Node and Bun. - **Deleted `windows-pi-launch.ts` and its tests.** Env vars reach Pi through every launcher, so the npm `pi.cmd` and Pi-installer unwrapping (#5271, #6839) is no longer needed. The version probe already launches `.cmd` shims through the host toolchain (`experimental_execHostFile`, since #6194), so `resolvePiProcessLaunch` is gone too. - **`packages/provider-bridge-protocol/src/testing/replay-provider-child.mjs`**: the `pi-rpc` replay dialect connects to the same socket instead of fds 3 and 4. - **Fake Pi** (`fake-pi-rpc.mjs`): waits for the extension factory, as Pi does, and adds a `/reload` prompt that reloads the extension. - **README**: documents the bridge channel and `/reload`. Killing a session leaves no Pi processes behind, so no unwrapping had to stay: - **Windows**: bb's kill path (`experimental_killPortableProcess`, i.e. `taskkill /T /F`) kills the shim's whole process tree. Closing stdin also ends Pi through `cmd.exe` and Bun's shim. - **POSIX**: kill signals the launcher, and Pi exits on stdin EOF, because bb closes stdin before signalling. Measured on the VM: pnpm `pi.cmd` and Bun `pi.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.mjs` reports the surface unchanged. Known limitation: `pnpm parity` uses 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: - A dynamic-tool round trip through a Node launcher that starts Pi as a child with `stdio: "inherit"`. - The same round trip after `/reload`. - `bridge.launchers.test.ts`, Windows only (runs in the `plugins-1` Windows shard): the same round trip through a pnpm-template `pi.cmd`, and through the Pi installer's `pi.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-gate` model/list and `provider-maintenance.version` probe) stay and now run through `cmd.exe` without unwrapping. Commands: ```sh pnpm exec turbo run typecheck lint test --filter=bb-plugin-provider-pi --filter=@bb/provider-bridge-protocol --filter=@bb/provider-parity node .github/workflows/check-plugin-sdk-version.mjs # Plugin SDK surface unchanged. ``` 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 pi` main-vs-main and branch-vs-branch with `--dump-dir`. Both pass 9/9 cells (1 skipped), and `diff -r` of 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: ```text npm pi.cmd graceful CHANNEL OK VERSION PROBE 1.4.0 leftover pi processes=0 managed pi.cmd graceful CHANNEL OK VERSION PROBE 1.4.0 leftover pi processes=0 pnpm pi.cmd graceful CHANNEL OK VERSION PROBE 1.4.0 leftover pi processes=0 bun pi.exe graceful CHANNEL OK VERSION PROBE 1.4.0 leftover pi processes=0 node cli.js graceful CHANNEL OK VERSION PROBE 1.4.0 leftover pi processes=0 bun.exe cli.js graceful CHANNEL OK VERSION PROBE 1.4.0 leftover pi processes=0 (same six with kill: CHANNEL OK, leftover pi processes=0) ``` 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.version` and `bridge.bun-runtime` pass. Three `bridge.relocation` tests fail there because they shell out to `cygpath` and 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 and `bun 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 > 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
Pi 1.4.0's Windows installer (
irm https://pi.dev/install.ps1 | iex) creates a managed install, not an npm global one.~\.pi\agent\bin\pi.cmdrunscmd.exe, thennode pi-launcher.js, which re-spawns the Pi CLI withstdio: "inherit". On Windows neither hop forwards descriptors 3 and 4, which bb's Pi bridge extension uses, so the extension fails withUnsupported fd type: UNKNOWNand neither the model catalog nor Pi threads can start. #5271 bypassed only npm's ownpi.cmdtemplate, so managed launchers still went through the broken chain. Unix managed launchers are unaffected:execandspawnSyncinherit the descriptors there (checked on macOS).What changed
plugins/provider-pionly. No host protocol, SDK, CLI or configuration changes.windows-pi-launch.ts:resolvePiManagedLauncherrecognises a managedpi.cmdby Pi's own marker (<agent>\install\managed-install.jsonwithkind: "pi-managed-install",schemaVersion: 1,layout: "releases-v1") plus the siblingpi-launcher.js. It resolves the active release CLI the same waypi-launcher.jsdoes (current-version, the packagebin, containment check), and selects the same Node:%LOCALAPPDATA%\pi-node\current\node.exewhen the launcher references it and it exists, otherwisenode.exefrom the child's PATH. The package-CLI resolution is shared with the existing npm shim path.PI_MANAGED_INSTALL_ROOT, aspi-launcher.jsdoes; Pi's startup uses it to clean up managed installs.rpc-child.tsand the version probe inprovider-maintenance.tsspawn with that env.How you verified
LOCALAPPDATA), and rejection of an unknown layout, a missing launcher script, and an escaping version. A Windows-only round-trip test sends RPC plus both extra pipes through the installer's realpi.cmdandpi-launcher.js(fixture contents copied frominstall.ps1), and asserts thatPI_MANAGED_INSTALL_ROOTreaches the child. Without the fix it would hit the descriptor loss.pnpm exec turbo run typecheck lint test --filter=bb-plugin-provider-pi: 333 passed, 8 skipped (Windows-only tests skipped on macOS; they should run in the Windows CI plugin shard).getPiCatalogwith the real bb Pi extension:pi.cmdviaBB_PI_BRIDGE_COMMANDCATALOG FAILED: … Unsupported fd type: UNKNOWNCATALOG OK, version probe1.4.0pi.cmdfound onPathCATALOG OK, version probe1.4.0pi.cmd(control)CATALOG OKCATALOG OKI did not run a full thread turn on Windows (the VM's Pi has no models configured). Thread start uses the same
PiRpcChildlaunch path.Fixes #6790
🤖 Generated with Claude Code