Skip to content

Run Pi installer managed launches directly on Windows - #6839

Merged
ymichael merged 1 commit into
mainfrom
bb/triage-and-resolve-issue-6790-thr_6qgdqaqcbi
Nov 2, 2026
Merged

ymichael merged 1 commit into
mainfrom
bb/triage-and-resolve-issue-6790-thr_6qgdqaqcbi

Conversation

@ymichael

@ymichael ymichael commented Nov 2, 2026

Copy link
Copy Markdown
Collaborator

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.cmd runs cmd.exe, then node pi-launcher.js, which re-spawns the Pi CLI with stdio: "inherit". On Windows neither hop forwards descriptors 3 and 4, which bb's Pi bridge extension uses, so the extension fails with Unsupported fd type: UNKNOWN and neither the model catalog nor Pi threads can start. #5271 bypassed only npm's own pi.cmd template, so managed launchers still went through the broken chain. Unix managed launchers are unaffected: exec and spawnSync inherit the descriptors there (checked on macOS).

What changed

plugins/provider-pi only. No host protocol, SDK, CLI or configuration changes.

  • windows-pi-launch.ts: resolvePiManagedLauncher recognises a managed pi.cmd by Pi's own marker (<agent>\install\managed-install.json with kind: "pi-managed-install", schemaVersion: 1, layout: "releases-v1") plus the sibling pi-launcher.js. It resolves the active release CLI the same way pi-launcher.js does (current-version, the package bin, containment check), and selects the same Node: %LOCALAPPDATA%\pi-node\current\node.exe when the launcher references it and it exists, otherwise node.exe from the child's PATH. The package-CLI resolution is shared with the existing npm shim path.
  • The resolved launch now carries its child env. Managed launches add PI_MANAGED_INSTALL_ROOT, as pi-launcher.js does; Pi's startup uses it to clean up managed installs. rpc-child.ts and the version probe in provider-maintenance.ts spawn with that env.
  • Anything unrecognised launches exactly as before.

How you verified

  • Tests: unit tests for managed-launcher resolution, standalone-Node selection (case-insensitive 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 real pi.cmd and pi-launcher.js (fixture contents copied from install.ps1), and asserts that PI_MANAGED_INSTALL_ROOT reaches 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).
  • Native Windows 11 ARM64 VM (Node 24.22.0, Pi 1.4.0): built a managed install with the installer's exact launcher files and ran a standalone bundle of this branch's getPiCatalog with the real bb Pi extension:
Case Before After
Managed pi.cmd via BB_PI_BRIDGE_COMMAND CATALOG FAILED: … Unsupported fd type: UNKNOWN CATALOG OK, version probe 1.4.0
Managed pi.cmd found on Path (same failure) CATALOG OK, version probe 1.4.0
npm global pi.cmd (control) CATALOG OK CATALOG OK

I did not run a full thread turn on Windows (the VM's Pi has no models configured). Thread start uses the same PiRpcChild launch path.

Fixes #6790

AGENT GENERATED

🤖 Generated with Claude Code

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
ymichael merged commit 5758191 into main Nov 2, 2026
82 of 83 checks passed
@ymichael
ymichael deleted the bb/triage-and-resolve-issue-6790-thr_6qgdqaqcbi branch November 2, 2026 19:52
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]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG] Pi provider unusable on Windows execution machines: bridge extension fails with "Unsupported fd type: UNKNOWN" (bb 0.48.1, pi 1.4.0)

1 participant