Skip to content

One host toolchain for executable discovery, child PATH, and proxy/CA defaults - #6194

Merged
ymichael merged 21 commits into
mainfrom
bb/swing-5-one-host-toolchain-path-and-proxy-resolv-thr_ak8mbqqesh
Oct 27, 2026
Merged

ymichael merged 21 commits into
mainfrom
bb/swing-5-one-host-toolchain-path-and-proxy-resolv-thr_ak8mbqqesh

Conversation

@ymichael

@ymichael ymichael commented Oct 23, 2026 •

Copy link
Copy Markdown
Collaborator

Human comments

What was wrong

bb launches child processes from many places (server, daemon, desktop, launcher, plugins), and each one found executables and built PATH its own way. Under a macOS launchd service or a GUI launch, PATH is minimal, so several things broke:

What changed

  • One resolver: HostToolchain in packages/process-utils/src/host-toolchain.ts owns executable lookup, the child PATH and proxy/CA environment, npm selection, and replacement of a deleted Node.
    • It reads the login-shell PATH, or the user and machine registry PATH on Windows, plus proxy variables from the shell.
    • It adds the running Node runtime's directory (never the Electron app's) and standard user tool directories (~/.local/bin, mise/asdf shims, Volta, and Homebrew on macOS).
    • Discovery runs in the background and is coalesced. Launches never wait for it.
    • ENOENT, exit 127 and lookup misses start a background refresh. Commands are never replayed.
  • Launch helpers: spawnHostProcess, forkHostProcess, execHostFile, execHostFileCallback, execHostFileBuffer and prepareHostPtyCommand in host-process.ts use the resolver. Core call sites across the server, daemon, desktop, CLI, launcher, host-workspace, host-watcher, local-open-targets and the provider kits now use these helpers instead of node:child_process. The per-package lookup code is deleted: desktop desktop-shell-path, daemon runtime-shell-env shell/registry parsing, selectResolvedExecutable, and the plugin-local bb/claude candidate lists.
  • Child environments:
    • Every child PATH gets the login-shell PATH and the standard tool folders. When the PATH is the one bb started with, the login-shell PATH comes first; when a caller passes a different PATH, the caller's entries stay first. bb never infers that a PATH was meant to be exact.
    • Scripts that start with #!/usr/bin/env node run with the node on PATH.
    • npm and npx run as found on PATH. Daemon self-update instead runs npm-cli.js with the Node installation that owns it (hostToolchain.npmCli), which avoids version-manager wrappers. Inside the Electron desktop runtime, bb never substitutes its own runtime for npm.
  • Network defaults: the packaged server/daemon launchers start bb's own Node processes with --use-system-ca and --use-env-proxy (@bb/config/node-network), each only when the runtime accepts it, and bb's forked workers and provider bridge workers inherit them. They are flags rather than exported variables, so terminals, provider CLIs and agent shells keep the user's own Node networking settings. Setting NODE_USE_SYSTEM_CA=0 or NODE_USE_ENV_PROXY=0 opts out. bb-app env set treats the proxy and CA keys as startup-only.
  • Startup: the daemon and the packaged desktop app wait for discovery at startup. The server starts it in the background. The bb CLI never runs it.
  • Plugin SDK: new @get-bb/plugin-sdk/process entry point exports experimental_hostToolchain, experimental_spawnHostProcess, experimental_forkHostProcess, experimental_execHostFile and experimental_execHostFileCallback. Core uses the same implementation.
    • SDK bumped to 0.6.86. Plugins that import the entry point now require >=0.6.86.
    • check-plugin-sdk-version.mjs now watches src/process.ts.
    • Added an entry to docs/api_to_audit.md and the Plugin Guide's Provider bridges card.
  • Plugins: MCP, automations, browser automation, GitHub, keep-awake, storage retention (including the external worktree scanner), account pool, and the Claude Code, Codex and Pi providers use the SDK helpers.
  • CLI startup: the bb entry imports @bb/process-utils/host-process rather than the package barrel, so startup does not load execa.
  • Docs: docs/configuration.md covers proxies and certificates and how executable discovery works.
  • No wire changes: HOST_DAEMON_PROTOCOL_VERSION is unchanged.

Behavior differences from main:

  • Proxy variables set in the user's login shell now reach child processes when the caller's environment does not set them.
  • Children receive the caller's PATH extended with the login-shell PATH and the standard tool directories.

Not addressed:

This supersedes #6081, #6083, #5997 and #5948.

How you verified

  • New process-utils tests (host-toolchain.test.ts, host-toolchain-windows.test.ts) cover:
  • bb-app tests start the server and daemon with real environment proxies and check that NO_PROXY bypasses them (bb's own outbound fetch() ignores HTTP_PROXY/HTTPS_PROXY: provider usage and Codex subscription calls fail (HTTP 403) behind a mandatory proxy #3239), and that explicit opt-outs are kept (Desktop app can't reach getbb.app behind TLS-inspecting proxies (Zscaler): trust the OS certificate store #5260).
  • Reproduced before these fixes, and verified after:
    • The launcher's bb --version took 1.7 s because of a synchronous login-shell probe. It now takes 0.08 s.
    • A binary git blob came back corrupted (64 bytes in, 121 out). It now comes back byte-exact.
  • pnpm exec turbo run typecheck lint --filter='...[origin/main]' passes.
  • pnpm exec turbo run test --filter='[origin/main]' passes for every changed package except the desktop Electron smoke test below. Under that parallel load, the MCP timeout test and the server builtin hot-reload test missed their timing windows; both pass when run alone.
  • check-plugin-sdk-version.mjs and oxfmt --check pass.
  • Desktop preload-build (Electron smoke) times out locally with both this branch's and main's desktop sources, so it is environmental.
  • Manual checks on real installs:
    • Windows 11 ARM64 VM (bb-app from this branch, started by its sign-in scheduled task): Codex (codex.exe), Claude Code (claude.exe) and Pi (pi.cmd) are detected with their on-disk names. Updating Pi through bb (bb machine provider-cli install <host> pi --action update) ran npm.cmd in a pty and moved Pi from 1.3.0 to 1.4.0. Signed-in Claude Code and Codex turns run node, npm and bb, and where.exe finds node, npm, bb, claude, codex and pi. A bb terminal resolves codex, claude, pi, node and npm from the registry PATH.
    • Packaged macOS desktop app launched with launchd's environment (PATH=/usr/bin:/bin:/usr/sbin:/sbin): the server and daemon receive the login-shell PATH; Codex under ~/.bun/bin and Pi under nvm are detected; Claude Code, Codex and Pi turns each run git --version, node --version and bb --version successfully. The packaged bb CLI runs with PATH=/usr/bin:/bin (LaunchAgent server has no node on PATH, so the MCP server (and other plugins) can't run the bb CLI #5807). This check found that exporting NODE_USE_* made bb --version inside agent shells print proxy warnings and system-certificate errors; switching to flags fixed it.
    • Main vs branch environment diff (both packaged apps launched with launchd's environment): in a bb terminal, Claude Code and Codex agent shells, and the server, daemon, bridge, Claude and Codex processes, the only differences are the added PATH fallbacks and the network flags on bb's own processes. node, npm, git, bb, codex, claude and pi resolve to the same files. This check found the Electron app directory on child PATHs; it is now excluded.
    • Proxy: with HTTPS_PROXY in the data directory's env.json, the branch routes the server's npm version check and the bridge workers' Claude, Codex, Cursor and OpenCode usage fetches through the proxy; main sends the same requests directly. On Linux, a TLS-intercepting mitmproxy whose CA is only in the system store works with the default flags and fails with NODE_USE_SYSTEM_CA=0. This check found that bridge workers lacked the flags; they now inherit them.
    • Linux (Ubuntu 24.04 container, Node from mise only on the login-shell PATH, launched with systemd's default PATH): providers are found through mise shims, a Pi update through bb ran mise's npm, a bb terminal resolves every tool, and a machine running its daemon like the systemd unit self-updated from protocol 255 to a bumped 256 server and reconnected.
    • Daemon self-update: a machine enrolled with the manual installer, running a supervised --auto-update daemon under launchd's PATH, updated from protocol 252 to a locally bumped 253 server: it installed the server's package into its private prefix with the Node-owned npm, restarted, and reconnected. The global npm prefix was untouched.

Fixes #6079
Fixes #5807
Fixes #5295
Fixes #5260
Fixes #6284

AGENT GENERATED

🤖 Generated with Claude Code

@ymichael
ymichael force-pushed the bb/swing-5-one-host-toolchain-path-and-proxy-resolv-thr_ak8mbqqesh branch 2 times, most recently from 4bf8699 to 391d072 Compare October 23, 2026 23:34
@ymichael
ymichael marked this pull request as ready for review October 24, 2026 03:03
@ymichael
ymichael force-pushed the bb/swing-5-one-host-toolchain-path-and-proxy-resolv-thr_ak8mbqqesh branch 2 times, most recently from c6f1900 to 68c4009 Compare October 26, 2026 20:41
ymichael and others added 18 commits October 26, 2026 15:34
…ntime

Login-shell and registry discovery now runs asynchronously in the
background; launches use the latest snapshot and never wait for a probe.
Exit 127, ENOENT and lookup misses start a coalesced background refresh.
The launcher no longer refreshes on every bb CLI invocation.

Node shebang scripts run with the node on PATH instead of bb's runtime,
and npm runs with the Node installation that owns it; the Electron
desktop runtime never stands in for npm. An explicit caller PATH is
passed to children exactly while lookups still search well-known
install directories. execHostFile honours the caller's string encoding
and execHostFileBuffer returns raw bytes for git blob reads.

Bumps the plugin SDK for the new process entry point, guards it in the
SDK version check, raises the SDK floor of plugins that import it, and
removes stray blank lines left by the import rewrites.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…unch helpers

Lookups with a caller-supplied PATH search only that PATH, matching what the
child receives. Generic npm/npx launches run what PATH resolves; daemon
self-update asks for the Node-owned npm explicitly. Claude Code keeps its own
well-known install fallback. The CLI startup path imports the host-process
subpath instead of the process-utils barrel, which loaded execa and tripped
Node's NO_COLOR warning. Tests that mocked node:child_process now mock the
helpers the code calls.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…i, probe cwd

Lookups return the executable's on-disk file name instead of PATHEXT's
uppercase extension. Claude Code resolves claude.exe on Windows, as before.
The Pi npm shim falls back to node.exe from the child's PATH, matching npm's
own shim, instead of bb's runtime. Discovery probes run from the home directory
so a background refresh cannot hold a caller's working directory open. Windows
tests now exercise a realistic npm shim and match cmd.exe-wrapped spawn args.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…ments

The launchers exported NODE_USE_ENV_PROXY and NODE_USE_SYSTEM_CA, so every
terminal, provider CLI, and agent shell inherited them; on macOS a plain
`bb --version` inside a Claude Code turn printed an experimental-proxy warning
and repeated system-certificate errors. Server and daemon now start with
--use-system-ca and --use-env-proxy when the runtime accepts them, forked
workers inherit them through execArgv, and child environments keep the user's
own settings. NODE_USE_*=0 still opts out.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@ymichael
ymichael force-pushed the bb/swing-5-one-host-toolchain-path-and-proxy-resolv-thr_ak8mbqqesh branch from fca4481 to 43011fb Compare October 26, 2026 22:34
@ymichael
ymichael merged commit 88048e6 into main Oct 27, 2026
51 checks passed
@ymichael
ymichael deleted the bb/swing-5-one-host-toolchain-path-and-proxy-resolv-thr_ak8mbqqesh branch October 27, 2026 03:09
ymichael added a commit that referenced this pull request Oct 27, 2026
)

## Human comments

## What was wrong

#6194 changed the start of `runDesktopApp` (`apps/desktop/src/main.ts`)
from a synchronous PATH fixup to `await hostToolchain.refresh()`, and
that await ran before
`app.setName(DESKTOP_RELEASE_INFO.applicationName)`. The refresh spawns
a login shell, so Electron reached `ready` while it ran. Electron then
locked the profile directory to the default name from the packaged
`package.json`, `@bb/desktop`. Updated nightlies started with an empty
profile at `~/Library/Application Support/@bb/desktop/` instead of `bb
Nightly/`. That profile has no saved server (`server-target.json`), no
Connect credential (log shows `connect server sync skipped
(no-credential)`) and no window state, so the app fell back to This Mac
with no other servers listed. The real profile is untouched: `bb
Nightly/server-target.json` still holds the user's saved target. Stable
0.47.1 predates #6194 and is not affected.

## What changed

- `apps/desktop/src/main.ts`: `runDesktopApp` now sets the app name,
installs the About panel, takes the single-instance lock and registers
app/process handlers before any await. The packaged host toolchain
refresh moved to just before `await app.whenReady()`, so the profile
name is fixed however long discovery takes. Child processes still
receive the discovered environment before anything is spawned.

When this build is installed, existing users go back to their original
`bb Nightly` / `bb` profile, so nothing needs migrating. Anything chosen
in the interim `@bb/desktop` profile stays behind.

There are no wire, CLI, or doc changes.

## How you verified

- Confirmed on an affected machine: after the update to
`0.47.2-nightly.40533619938.1`, a new `~/Library/Application
Support/@bb/desktop/` profile appeared, holding the `SingletonLock` and
no `server-target.json`. The old `bb Nightly/` profile still has
`target: "custom"`, last written Oct 21.
- `pnpm exec turbo run typecheck lint test --filter=@bb/desktop`: passes
(599 tests passed, 1 skipped).
- There is no automated regression test. The packaged smoke test always
passes `--user-data-dir`, so it cannot catch the default profile path. A
packaged nightly with this change has not been launched yet.

> AGENT GENERATED

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-authored-by: Claude Opus 5.5 <[email protected]>
ymichael added a commit that referenced this pull request Oct 27, 2026
…proxy for loopback (#6394)

## Human comments

## What was wrong

#6194 (88048e6) started bb's own Node processes with
`--use-env-proxy` and copied the login shell's proxy variables into
child environments. That caused two regressions. (A) Node builds its
proxy agent at startup, before user code runs, and throws
`InvalidArgumentError: Invalid URL protocol` (or `TypeError: Invalid
URL`) when any `HTTP_PROXY`/`HTTPS_PROXY` value, in either case, lacks
an `http:`/`https:` scheme. curl and git accept values like
`proxy.corp:3128`. The built-in desktop server and daemon died on every
launch. Under a service, bridge workers and plugin hosts died too: they
inherit the flag from the daemon's `execArgv`, and their environment
picks up the shell's proxy through `hostToolchain.environment()`, which
the daemon's flag decision never saw. (B) Node never bypasses loopback
automatically, and `NO_PROXY=localhost` does not cover `127.0.0.1` or
`[::1]`. The daemon's global `fetch` to `http://127.0.0.1:<port>` went
through the proxy, so the machine showed offline. The flag was decided
in one place (from the launcher's env) while the child's final env was
built in another (the spawner), so the two could disagree.

## What changed

- **One enforcement point at spawn time.** The node-network helpers move
from `@bb/config/node-network` to
`packages/process-utils/src/node-network.ts`. `@bb/config` depends on
process-utils, so the spawner could not import them from there.
`HostToolchain.command()`, used by `spawnHostProcess`, the
`execHostFile*` variants, the PTY launcher and `spawnHostProcessSync`,
checks the leading Node options of each launch. `forkHostProcess` checks
the fork's `execArgv`, which defaults to the parent's. Both checks run
against the child's final environment, after
`hostToolchain.environment()` has merged in the shell's values. That
covers every launch that carries the flag: the launcher's server and
daemon (through `spawnLoggedProcess`), provider bridge workers (through
`spawnManagedProcess`), and plugin-host and watcher forks. None of these
call sites changed.
- **Regression A:** `--use-env-proxy` is kept only if every non-empty
`HTTP_PROXY`/`HTTPS_PROXY` value, in any case, parses as an
`http:`/`https:` URL with a host and has no CR/LF. All four are checked
because Node's readers differ in precedence: undici's
`EnvHttpProxyAgent` reads `http_proxy ?? HTTP_PROXY`, while `node:http`
reads `http_proxy || HTTP_PROXY`. Otherwise the flag is dropped and
`process.emitWarning` reports `BB_INVALID_PROXY_ENV` once per variable
name. Values are never logged because they can contain credentials.
`--use-system-ca` is unaffected. When the flag is dropped from the
daemon, its `execArgv` no longer has it, so its children cannot inherit
it. When the daemon keeps the flag, each child is checked again against
its own environment.
- **Regression B:** when `--use-env-proxy` is kept and a proxy is set,
`localhost,127.0.0.1,::1,[::1]` is appended to every existing
`NO_PROXY`/`no_proxy` value, or `NO_PROXY` is set if neither exists.
Existing entries are kept, duplicates are skipped, and a `*` value is
left alone. `[::1]` is needed because undici compares `URL.hostname`,
which keeps the brackets. `node:http` matches `::1`. I checked both
against Node 22.23. The appending only happens for launches that carry
the flag, so terminals and agent tools launched directly keep their own
environment. Children of bb's Node processes inherit the loopback
entries, which is harmless and keeps their own loopback traffic direct.
- **Opt-outs:** `NODE_USE_ENV_PROXY=0` and `NODE_USE_SYSTEM_CA=0` in the
child's environment now also remove inherited flags. The launcher's
`nodeNetworkArgs` still honors them.
- Removed the `@bb/config` dependency that #6194 added to
`@bb/agent-runtime` only for this module, and the `./node-network`
export from `@bb/config`.
- Docs: `docs/configuration.md` no longer tells users to add loopback to
`NO_PROXY`, and it now explains the scheme rule and the warning. Also
updated the `docs/api_to_audit.md` host-toolchain entry and the Plugin
Guide reference text in `plugins/plugin-api-docs/src/surfaces.ts`.
- No wire changes, so `HOST_DAEMON_PROTOCOL_VERSION` is unchanged.

Not covered: the ACP bridge passes its own `process.execArgv` to the
agent as an MCP stdio server command, which the third-party agent spawns
itself. The bridge only has the flag if its own environment passed the
check, and the agent's environment comes from the bridge's. This path
can only break if the agent adds an invalid proxy itself.

## How you verified

- New `packages/process-utils/test/node-network.test.ts`:
- Unit table for `nodeNetworkLaunch`: scheme-less, bare host:port,
`socks5://` and `http://` values in each case variant drop the flag;
valid proxies keep it and get loopback appended to both `NO_PROXY` and
`no_proxy`; a `NO_PROXY` that is missing, partly loopback already, or
`*`; no proxy leaves the env unchanged;
`NODE_USE_ENV_PROXY=0`/`NODE_USE_SYSTEM_CA=0` remove inherited flags.
- Real processes: `execHostFile(node --use-env-proxy)` with
`HTTP_PROXY=proxy.corp:3128` starts. `forkHostProcess` with `execArgv:
["--use-system-ca","--use-env-proxy"]` and `https_proxy=127.0.0.1:7890`
starts and keeps only `--use-system-ca`. With a dead `HTTP_PROXY` and
`NO_PROXY=corp.example`, `fetch` to `127.0.0.1` and `localhost` succeeds
while `--use-env-proxy` stays active.
- With `host-toolchain.ts` and `host-process.ts` reverted to
`origin/main`, all three real-process tests fail: two crash with
`Invalid URL protocol` / `worker exited with 1`, and the loopback fetch
fails through the dead proxy. All 13 pass with the change.
- `packages/bb-app/test/index.test.ts` "managed process networking" no
longer sets `NO_PROXY: "127.0.0.1"`. It now launches through
`execHostFile` (bb's spawn path) and still gets `proxied` for the remote
URL and `direct` for loopback.
- `pnpm exec turbo run typecheck lint test --filter=@bb/process-utils
--filter=@bb/config --filter=@bb/agent-runtime --filter=bb-app
--filter=bb-plugin-plugin-api-docs --continue`: 21 of 22 tasks pass. The
one failure is `@bb/process-utils`
`test/performance-diagnostics.test.ts` ("logs the sampled blocker
without attributing an adjacent short callback"). It is an event-loop
timing test that also fails when run alone on this machine, and neither
it nor anything it imports touches the changed files. All other tests
pass: process-utils 117 passed, agent-runtime 23 files, bb-app 23 files,
config 10, plugin-api-docs 12.

> AGENT GENERATED

🤖 Generated with [Claude Code](https://claude.com/claude-code)

---------

Co-authored-by: Claude Opus 5.5 <[email protected]>
ymichael pushed a commit that referenced this pull request Oct 28, 2026
## Human comments

## What was wrong

#6194 made script automations set `BB_CLI` to the public launcher,
`~/.bb/bin/bb`. That launcher runs `bb-app/dist/bb.js`.
`runBundledCliCommand` runs `BB_CLI` whenever it is set and had no loop
guard, so each `bb` call started the launcher again, without end, until
the server ran out of memory. See #6435.

## What changed

- `runBundledCliCommand` marks the `BB_CLI` child with
`BB_CLI_REEXEC=1`. When it sees that mark, it runs the bundled CLI
instead. This is the same handshake `apps/cli/src/bb-cli-reexec.ts`
already uses.
- The marker name now lives in `@bb/config/cli-command` for bb-app. The
CLI keeps its own copy because its startup graph must not load
`packages/config` (`startup-graph.test.ts`).

## How you verified

- New bb-app test that runs the entry again with the env from the first
run. It fails on `main` with `expected 1 to be +0` and passes with this
change.
- `turbo run typecheck --filter=bb-app --filter=@bb/config
--filter=@bb/cli` passed. `turbo run test --filter=bb-app` passed,
220/220.
- Ran the loop through a real generated launcher with `BB_CLI` pointing
back at it. It now exits once with the right output and exit code.
Before, it grew to 19-33 processes in 3s.

Fixes #6435

🤖 Generated with [Claude Code](https://claude.com/claude-code)

> AGENT GENERATED

Co-authored-by: Claude Opus 5.5 <[email protected]>
@ymichael ymichael mentioned this pull request Oct 30, 2026
ymichael added a commit that referenced this pull request Oct 30, 2026
## Human comments

## What was wrong

desktop 0.48.0 shipped #6194 but not its fix, #6436, which merged two
hours after the release. On 0.48.0, any script automation that calls
`bb` starts `bb` again without end (#6435, #6557), and users are hitting
it: one Discord report had about 3,750 nested `bb thread show` processes
on a 48 GB Mac. `bb-app` and `@bb/desktop` are still at 0.48.0, so the
publish and desktop workflows can't ship the fix.

## What changed

- `packages/bb-app/package.json`, `apps/desktop/package.json`: 0.48.0 →
0.48.1 (`node scripts/bump-version.mjs --patch`).
- No release notes for this patch: `CHANGELOG.md` and
`changelog-metadata.ts` are unchanged, as with 0.47.1.

The release commit sits directly on `a19a8eeffd`, the current `main`, so
0.48.1 ships all 98 commits since 0.48.0. These include two protocol
bumps (`HOST_DAEMON_PROTOCOL_VERSION` 256 → 258) and no database
migrations.

## How you verified

- `node .github/workflows/check-version-lockstep.mjs`: `bb-app=0.48.1
@bb/desktop=0.48.1`.
- `git diff --check` is clean.
- Reproduced the loop on the published `[email protected]` with `BB_CLI`
pointed at a generated launcher: `--version` printed nothing, and 65
processes were running after 3 seconds. The nightly
`0.48.1-nightly.40912875657.1`, which contains #6436, is the build that
has the fix in the field.

> AGENT GENERATED

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-authored-by: Claude Opus 5.5 <[email protected]>
alexandre-vl added a commit to alexandre-vl/bb that referenced this pull request Oct 30, 2026
- bb/daemon-self-update-node-npm-cli (get-bb#6083): superseded by
  upstream get-bb#6194.
- bb/project-default-source-host (get-bb#6054) and
  bb/explain-failed-automations-thr_agcnkvvvke (get-bb#6005): merged upstream;
  each merges into main with main's own tree.
- carry/automation-environment-composer: it only reconciled the composer
  branch with explain-failed, and the updated
  bb/automation-environment-composer merges without it.
- carry/github-plugin-inbox: it breaks bb-plugin-github#typecheck on
  current main; the updated github-plugin-inbox carries the inbox itself.
samantha-clanker Bot pushed a commit to samanthar0se/bb that referenced this pull request Oct 30, 2026
Conflict resolutions:
- plugin-sdk app-contract: keep local JsonObject alias; take upstream's
  hoisted rpc-contract import and PluginMentionTrigger import.
- desktop main: keep main-instance env handoff; drop
  ensurePackagedUserShellPath, replaced upstream by hostToolchain (get-bb#6194).
- NewThreadComposer: keep plugin metadata on submit and in the composer
  handle; adopt upstream's ComposerSubmitExtras and sendsOnEnter.
- FollowUpPromptBox test: adopt upstream's ComposerBox mock, keep the
  MemoryRouter wrapper and selected-provider probe.
- composer prompt-decoration test: take upstream; draft observers moved
  out of the editor extension (get-bb#6091).

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]>
ymichael added a commit that referenced this pull request Nov 3, 2026
… again (#6926)

## Human comments

## What was wrong

#6194 switched the connect-next gate's `frps` launch
(`apps/connect-next/src/frps.ts`) from `node:child_process` to
`spawnHostProcess` from `@bb/process-utils`. That broke the gate in two
ways:

- The gate's Dockerfile copies only the sources of tunnel-contract,
connect-db and text-utils, so the image no longer builds: `Could not
resolve "@bb/process-utils"`. The next run of Deploy Connect Next would
fail at the build step. The last deploy (Oct 26, `3fcb678bf9`) predates
#6194, so production is unaffected.
- `@bb/process-utils` brings in `cross-spawn`, which calls
`require("path")`. The gate's ESM bundle can't do that, so `pnpm
--filter @bb/connect-next build` produces a gate that crashes at startup
with `Dynamic require of "path" is not supported`. This also breaks
`apps/connect-next/scripts/e2e-local.sh`.

CI missed both because the gate's process test ran the TypeScript source
through tsx, which resolves workspace packages and supports `require`.

## What changed

- `frps.ts` starts `frps` with `node:child_process` `spawn` again, and
`@bb/process-utils` is dropped from the gate's dependencies. The gate
runs in a Linux container with a fixed `FRPS` path, so it needs none of
the host toolchain's PATH, Windows or proxy handling. Lint allows async
`spawn` in apps.
- `test/dockerfile-build.ts` builds the gate the way the Dockerfile's
build stage does. It reads the stage's `COPY` lines, `npm install`
packages and `esbuild` flags from the Dockerfile, copies only those
sources into an empty temp dir, and builds with no `NODE_PATH`. It
throws on any esbuild flag it doesn't recognise, so it can't silently
drift from the Dockerfile.
- `test/main.e2e.test.ts` (the gate process test: real `frps`, a tunnel,
SIGTERM shutdown) now runs that bundle instead of the source. Deploy
Connect Next runs this test before deploying.

## How you verified

- Before the fix, the updated process test fails with the Docker error,
`Could not resolve "@bb/process-utils"`. After it, it passes.
- `docker build -f apps/connect-next/Dockerfile .` fails on main and
succeeds on this branch. `docker run` of the image gets past module load
to the gate's own config check (`ACCOUNT_API_URL is not set`).
- The local `pnpm --filter @bb/connect-next build` gate now starts the
same way.
- `pnpm exec turbo run typecheck lint test --filter=@bb/connect-next`:
94/94 tests pass. One run hit a timing failure in `regions.e2e.test.ts`
under high machine load (load average 65); it passed 6/6 reruns, and it
starts `frps` through the same plain `spawn` it used before #6194.
- `pnpm install --frozen-lockfile` passes; the lockfile change is only
the removed `@bb/process-utils` link.

> AGENT GENERATED

Co-authored-by: Claude Opus 5.5 <[email protected]>
ymichael added a commit that referenced this pull request Nov 9, 2026
…periment) (#6215)

## Human comments

## What was wrong

On 2026-10-23, from 12:16 to 12:53, 15–19 agent threads ran at once. The
server main thread was busy for most of the window: event-loop
utilization was 0.84–0.88, and the saved CPU profiles show the loop
non-idle about 45% of wall time. Yet it consumed only **0.06 CPU-seconds
per wall second**. The stall logs for 12:30–12:50 show the same thing
per task: the longest synchronous work in each stall got 6–7% of its
wall time as CPU. A 30 ms timeline build took about 500 ms, and slow
`TRANSACTION IMMEDIATE` queries ran at 5% CPU/wall with about
1,200–1,500 involuntary context switches per second. The server was
runnable but not scheduled.

- **macOS:** `nice` does not help. The clutch scheduler first picks
among thread groups in the same QoS bucket, so a busy plain process gets
only its fair share against dozens of agent, build and test processes.
With 48 CPU burners at nice 0, 10 and 19, a server-like probe's 20 ms
chunks stretched to 40–80 ms in every case. Clamping agents to utility
QoS protected the server but made the agents' own parallel CPU work
2.3–3× slower, so that is not acceptable.
- **Linux:** the scheduler weights threads by `nice`, but provider
processes and lifecycle scripts ran at the same priority as the server.

This PR now also contains #6216, and both halves sit behind one
experiment.

**Timeline builds, Nov 7 2026.** A separate investigation found the same
cause behind production timeline builds running 4–7x slower than
in-process. A build that needs about 160 ms of CPU took 663 ms in
production, at 0.39 CPU/wall with 1,810 involuntary context switches and
no page faults or disk reads. With 32 normal-priority CPU burners on 16
cores, the same build took 596–703 ms in-process. Under `taskpolicy -a`
it took 220–232 ms, at 0.99 CPU/wall.

## What changed

**Experiment `agentCpuPriority`.** It is off by default, including for
early adopters, so it runs only where someone turns it on. It has a
Settings → Experiments label and description, an app fallback, and
entries in `docs/configuration.md`, `docs/debugging-and-qa.md` and the
bb guide.

**Agent processes at nice 10** (from #6216; below-normal priority class
on Windows):
- `@bb/process-utils` `deprioritizeAgentWorkload(pid)` sets nice 10, but
only while `setAgentWorkloadsLowered(true)` is in effect.
- The daemon calls it right after spawning provider processes (the
bridge worker, and therefore the provider CLI and every tool, build and
test it runs) and environment lifecycle scripts. Their children inherit
it.
- Terminal shells keep normal priority. That includes terminals created
through `bb terminal create` or the SDK, which agents use for dev
servers.
- **Delivery:**
- The server sends `agentCpuPriority` in the session-open response and
in `provider-session-policy.replace`. That message is already pushed on
every `config-changed`, which an experiment change triggers. It follows
the same path as `idleProviderSessionTimeoutMinutes`.
- This bumps `HOST_DAEMON_PROTOCOL_VERSION` to 265. Servers accept only
the matching version, so an older daemon is rejected at session open
until it updates, and older daemons never lower anything.
  - A policy message without the field fails validation and is ignored.
- **Toggling** takes effect after restarting bb, including the restart
an update performs. A running provider bridge worker serves new threads
with the priority it started with, and a process already lowered can't
be raised again, so it stays at nice 10 until it exits. Settings and the
docs say so.

**Server and daemon with app scheduling on macOS** (`taskpolicy -a`):
- **What it does:** the launcher starts the server and host daemon
through `/usr/sbin/taskpolicy -a`, the application resource-management
policy.
- `taskpolicy` execs in place, so the PID, stdio, the IPC channel and
signal handling are unchanged.
  - The policy is not inherited by children.
- The command is resolved through the host toolchain first (#6194) and
then wrapped. That keeps #6194's replacement of a removed or upgraded
Node, its network flags, and the loopback `NO_PROXY` entries #6394 adds
for `--use-env-proxy`. With the experiment off, the launcher spawns
exactly as on main.
- **How the launcher learns the value:** the launcher starts before any
database is open.
- The server writes `{"enabled":…}` to `<data
dir>/agent-cpu-priority.json` at startup and whenever the resolved
experiment value changes.
- The daemon writes the last value it received into its own data dir,
which covers a remote machine whose daemon has its own launcher.
- The launcher reads the file each time it spawns the server or daemon.
A missing or unreadable file means off, and nothing blocks startup.
  - This half therefore takes effect after restarting bb.
- **Before the handshake:** the daemon also seeds its nice-10 setting
from the same file when it starts. Without that, bridge workers spawned
before the handshake would miss the flag.
- **On a single machine,** the server and its local daemon write the
same file with the same value.

Other platforms, or a missing `taskpolicy`, spawn directly as before.

**Plugin SDK** moves to 0.6.135: the new experiment key appears in the
bundled `Experiments` type, and the npm version guard requires the bump.

## How you verified

All numbers were re-measured on Nov 7 2026 at 940e378 (origin/main
55135d1 merged in) on an M4 Max (12P+4E). Each `pnpm start:worktree`
run used this checkout's fresh, empty dev data dir.

This machine was busy with other threads throughout: load average 32–67
before any burners started. Rows marked "0 extra" include that
background load.

**Real worktree server, macOS.** 4 concurrent keep-alive clients on `GET
/api/v1/system/config` for 12 s, with and without 96 extra
self-terminating CPU burners, two rounds each. The experiment was
toggled with `PUT /api/v1/settings/experiments` and bb was restarted
between arms.

The load client is a plain process, so under burners it gets starved
too, and the first `taskpolicy -a` round with a plain client shows that.
Real clients are browser or Electron windows, which macOS already
schedules as apps. So the headline rows run the client under `taskpolicy
-a` as well, to measure only the server.

| server launch | client | burners | req/s | p50 | p90 | p99 |
|---|---|---|---|---|---|---|
| plain | app-scheduled | 0 extra | 664–809 | 2.2–2.3 ms | 6.6–6.9 ms |
74–97 ms |
| plain | app-scheduled | 96 | 181–268 | 2.2–2.5 ms | 27–51 ms | 252–338
ms |
| `taskpolicy -a` | app-scheduled | 0 extra | 2460–2809 | 1.1–1.2 ms |
2.1–2.3 ms | 3.1–3.8 ms |
| `taskpolicy -a` | app-scheduled | 96 | 2020–2025 | 1.5 ms | 2.8–2.9 ms
| 4.3 ms |
| plain | plain | 0 extra | 1420–1766 | 1.9–2.2 ms | 3.7–4.9 ms | 7.8–14
ms |
| plain | plain | 96 | 158–342 | 2.3–2.8 ms | 34–99 ms | 98–303 ms |
| `taskpolicy -a` | plain | 0 extra | 1832–2358 | 1.4–1.7 ms | 2.4–3.1
ms | 4.0–9.5 ms |
| `taskpolicy -a` | plain | 96 | 617–765 | 2.7–3.0 ms | 11–15 ms | 39–41
ms |

The plain-client plain-server baseline ran first, while the background
load was lowest, at 32–58.

**Linux** (OrbStack VM, 16 vCPUs, `node:22-slim`). A server-like probe
does 20 ms CPU chunks every 50 ms, against 64 CPU burners, two rounds
each:

| burners | probe CPU share | chunk wall p50 | chunk wall p99 | loop
delay p99 |
|---|---|---|---|---|
| none | 0.40 | 21 ms | 21 ms | 21–22 ms |
| 64 at nice 0 | 0.17–0.19 | 81–94 ms | 145–163 ms | 132–151 ms |
| 64 at nice 10 | 0.39–0.40 | 23–24 ms | 39–49 ms | 34–47 ms |

**Toggling on the real stack** (`ps -axo pid,ppid,pri,ni,command` and
`ps -M`). Threads ran in a project on a temp git repo:

| state | server | daemon | provider bridge workers + provider CLI |
agent tool command | terminal (`bb terminal create --command`) | plugin
hosts / watcher |
|---|---|---|---|---|---|---|
| default (off), first start | PRI 31, NI 0 | PRI 31, NI 0 | – | – | – |
PRI 31, NI 0 |
| turned on, before restart | unchanged | unchanged | – | – | – |
unchanged |
| on, after restart | **PRI 46** (main thread; workers 31) | **PRI 46**
| **NI 10** (Claude Code and Codex) | **NI 10** (`zsh -lc sleep 45`
under codex) | NI 0 | NI 0 |
| turned off, after restart | PRI 31, NI 0 | PRI 31, NI 0 | NI 0 | NI 0
(`zsh -c sleep 44`) | – | NI 0 |

`<data dir>/agent-cpu-priority.json` changed to `{"enabled":true}` and
back to `{"enabled":false}` as soon as each PUT returned.

**Tests:**
- `logged-process`:
- Off spawns the command as on main, and on spawns `/usr/sbin/taskpolicy
-a <node>` (macOS). Under the wrapper, the PID and IPC still work.
- New: a `--use-env-proxy` child under the wrapper still gets the
loopback `NO_PROXY` entries. This test fails on the pre-merge wrapper,
which dropped the toolchain env.
- `workload-priority`:
- Off leaves processes at their inherited priority, and on lowers them,
with grandchildren inheriting nice 10.
- A missing, garbled, non-boolean or wrongly shaped file reads as off,
and a failed write does not throw.
- Server:
  - The handshake carries the experiment value.
- Toggling pushes `agentCpuPriority` to connected daemons, parsed
through the contract schema, and rewrites the launcher file.
  - Contract and experiment tests are updated for 265 and the new key.
- Daemon:
- The handshake, a live change and a reconnect all reach
`onAgentCpuPriority`, and a policy without the field is ignored.
- The app lowers workloads and saves the value while the server enables
it, and stops lowering new processes and saves off when it is turned
off.
  - The app seeds lowering from a saved file before the handshake.

Typecheck and tests pass via Turbo for `@bb/server`, `@bb/host-daemon`,
`bb-app`, `@bb/process-utils`, `@bb/app`, `@bb/agent-runtime`,
`@bb/host-daemon-contract`, `@bb/domain` and `@bb/templates`, run with
`env -u BB_ACCOUNT_POOL_PARENT_URL -u BB_SERVER_URL -u BB_CLI`. The
plugin SDK npm version guard passes at 0.6.134; after rebasing onto
main, which took 0.6.134 for another change, the bump is 0.6.135.

Not re-measured here: agent throughput under nice 10, and Windows
below-normal priority.

> AGENT GENERATED

🤖 Generated with [Claude Code](https://claude.com/claude-code)

---------

Co-authored-by: Claude Opus 5.5 <[email protected]>
ymichael pushed a commit that referenced this pull request Nov 18, 2026
…th (#7756)

## Human comments

## What was wrong

Settings → Updates names the tool that will run each provider update.
`providerCliUpdaterName` took the first whitespace-separated word of
`installAction.command`, kept its last path segment, and compared it
with the whole `executableName`. When #5170 added the label, the Claude
Code bridge reported the bare name `claude`. Since #6194,
`claudeExecutable()` returns the resolved absolute path, so the
comparison `claude === "/home/<user>/.local/bin/claude"` always failed,
and the row showed `claude` instead of "Built-in updater". Paths that
`formatCommand` single-quotes (every Windows path, and POSIX paths with
spaces) broke further: the whitespace split cut the quoted path, and the
label became a fragment such as `claude.exe'` or a user-name segment.
Details and a live status capture are in #7755.

## What changed

- `apps/app/src/components/settings/UpdatesSettingsSection.tsx`: the
label code now reads the first shell word of the display command and
undoes `formatCommand`'s quoting (`'…'` segments and the `'\''` escape).
It then compares that word's basename, without `.exe/.cmd/.bat`, with
the basename of `executableName`. Unquoted Windows paths keep their
backslashes as path separators. Commands for package managers (`npm`,
`brew`, `mise`, …) are labeled as before.
- No wire, daemon, or CLI change: the `bb updates` CLI does not print an
updater name.

## How you verified

- New component test `recognizes a provider's own updater when the
machine reports its executable by path`. It covers a Claude row with a
POSIX absolute path and a quoted Windows path that contains a space and
an apostrophe. Before the fix it fails with `expected [ '\'\'s',
'claude' ] to deeply equal [ 'Built-in updater', …(1) ]`; after the fix
it passes.
- `pnpm --filter @bb/app exec vitest run
src/components/settings/UpdatesSettingsSection.test.tsx`: 77/77 passed.
The existing `mise` and `Homebrew` label test is unchanged.
- `pnpm exec turbo run typecheck lint --filter=@bb/app --force`: passed.

Fixes #7755

> AGENT GENERATED

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-authored-by: Claude Opus 5.5 <[email protected]>
ymichael added a commit that referenced this pull request Nov 19, 2026
## Human comments

## What was wrong

Every provider bridge built the environment for the CLI it starts by
hand, and each one did it differently. Claude Code passed the thread env
through. Codex passed `codex app-server` only an allow-list of three
names (`CODEX_OPENAI_BASE_URL`, `CODEX_POOL_AUTH_TOKEN`, `CODEX_HOME`)
and stripped every other `BB_*` name. So `BB_THREAD_ID`,
`BB_THREAD_STORAGE` and plugin-contributed variables such as
`BB_CODEX_BRIDGE_APP_SERVER_COMMAND` never reached the app-server or the
MCP servers and hooks it starts. Pi and ACP dropped the contributed env
when listing models. All four providers ran their health and
installation probes with the bridge's own `process.env`, and the server
never sent them the contributed env, so a plugin-supplied
`BB_CLAUDE_CODE_EXECUTABLE` worked for threads while the composer still
said "not installed". A spawn primitive already has one owner (#6194,
#6394); env composition had none. Background notes: C6 in
thr_qchecuan6n's `verify/host.md`.

Live repro on main (installed bb built from `1320c88e8ab`, Nov 16; the
bridge code is unchanged on main): `ps eww` on a running `codex
app-server` lists no `BB_THREAD_ID`, `BB_THREAD_STORAGE` or
`BB_PROJECT_ID`. A Claude Code CLI under the same daemon has all three.

### Issues and patches from this root cause

| | Item | What happened |
|---|---|---|
| open | #4960 | Codex app-server lacks thread identity, so MCP servers
cannot tell which thread they serve. **Fixed.** |
| open | #7179 | Contributed `CODEX_HOME` /
`BB_CODEX_BRIDGE_APP_SERVER_COMMAND` never reach the app-server.
**Fixed** (the `CODEX_HOME` half had already been patched by #6887). |
| open | #7614 | Claude Code installation status and health ignore a
contributed `BB_CLAUDE_CODE_EXECUTABLE`. **Fixed** for the server and
bridge. The app's cached host CLI status still refreshes only on reload;
that is a separate query-policy issue. |
| merged patch | #3056 | Added the pool URL and token to the Codex
allow-list. **Deleted** (the allow-list is gone). |
| merged patch | #6887 | Added `CODEX_HOME` to the Codex allow-list.
**Deleted.** |
| merged patch | #7401 | Gave Claude `model/list` the contributed env,
Claude only. Now one rule for all four providers. |
| merged patch | #5352 | Pi catalog inherited a stale
`PI_BB_TOOLS_FILE`. Kept, in `catalogCliEnv`. |
| related | #6939 | Codex rebuilds its session when a turn's env vars
change. Unchanged; it now rebuilds onto an env that actually carries
them. |
| not this class | #4417 | bb CLI dir prepended to PATH. That is a PATH
policy choice, not composition. Not changed. |

With the builder in place from the start, #4960, #7179 and #7614 could
not have happened, and #3056, #6887 and #7401 would not have been
needed. Each of those patched one provider for one name.

## What changed

- **One builder.** `buildProviderCliEnv(envVars)` in
`@bb/provider-bridge-protocol/bridge-kit`, exported to plugins as
`experimental_buildProviderCliEnv`. It returns the bridge env minus
bridge-only runtime vars, plus the request's `envVars` (valid shell
names). On Windows a request var replaces an inherited one whatever its
case, so a thread `PATH` never sits beside an inherited `Path`.
- **All four bridges use it** for session CLIs, model listing, health
and installation probes, and read their launch overrides from its
result:
- Codex: deleted `appServerLaunchEnv`, `buildAppServerEnv` and
`APP_SERVER_LAUNCH_ENV_NAMES`. `resolveAppServerLaunch` now takes the
CLI env and has no `process.env` default.
- Pi: deleted `buildPiChildEnv`. `resolvePiLaunch` reads the child env.
The model-list catalog is keyed by cwd + contributed env. A thread no
longer uses that catalog: the session starts Pi, asks that same process
for its models (`get_available_models`), picks the exact `provider/id`
match with the existing rules (canonical first, then one exact id;
ambiguity rejected), and switches with `set_model` and
`set_thinking_level`, the way T3 Code does. Model resolution therefore
always uses the Pi the thread's env selects, and no second Pi process
starts. A model missing from the list is retried like the existing
transient login miss; a mid-thread model change is checked against the
running Pi before the session is rebuilt.
- Claude: `buildSessionEnv` is now the builder plus Claude's two
entrypoint tweaks.
- ACP: session, model list (now including the request `envVars`), model
selection, maintenance and the agent probe. The thread-start model-list
command drops the per-thread names, so thread starts share the cached
catalog.
- **ACP's cached model list drops thread identity.**
`withoutThreadIdentityEnv(envVars)` in the bridge kit (internal, not
exported to plugins) removes `BB_THREAD_ID`, `BB_THREAD_STORAGE`,
`BB_PROJECT_ID` and `BB_ENVIRONMENT_ID` from the ACP thread-start list
command, so thread starts share the cached list.
- **Probes take an env.** `experimental_resolveExecutablePath`,
`experimental_commandOutput`, `experimental_readCliVersion`,
`experimental_npmLatestVersion` and `experimental_probeNpmGlobalPackage`
take the env as an argument. Claude, Codex, Pi and ACP maintenance pass
it through.
- **Wire change, `HOST_DAEMON_PROTOCOL_VERSION` 269 → 270.** The
`provider.*` host commands `list_models`, `list_commands`, `health`,
`installation.status` and `installation.run` now require
`contributedEnv`, and the runtime sends `envVars` on the matching
sessionless bridge requests (`model/list`, `commands/list`,
`provider/health`, `provider/installation/*`): the adapter command types
require it, so the type system rejects any request built without it.
`provider.usage` carries no env, as before: probing through the Account
Pooler's routing env reports the machine as signed out (checked live:
the local Claude account returns its Ultra limits, the same probe with
the pool's `ANTHROPIC_BASE_URL`/`ANTHROPIC_AUTH_TOKEN` returns
`unauthenticated`).
- **Bridge compatibility:** the SDK-facing bridge param schemas
(`modelListParamsSchema`, `commandListParamsSchema`,
`providerMaintenanceParamsSchema`) keep `envVars` optional. A bridge
built against the new SDK still accepts requests without it, as the echo
provider's tests and the package smoke send. Those schemas were already
`.passthrough()`, so a bridge built against the previous SDK accepts the
new field. `protocol.test.ts` covers both shapes. The server resolves
the env with `resolveHostProviderEnv` (shared with the model catalog
store, which already did this inline) and puts it in its status and
command-list cache keys. The runtime forwards it as `envVars`. The
thread-start installation gate passes the thread's contributed env and
includes it in its cache key.
- **Reads that bypassed the CLI env:**
- Claude's command list starts the CLI with the request's env and caches
per folder + contributed env.
  - Codex auth reads `CODEX_HOME` from the probe env.
- The Claude skills config dir reads `CLAUDE_CONFIG_DIR` from the
thread's CLI env.
- **`windowsHide` default:**
- `forkHostProcess` and `spawnHostProcessSync` default it to `true`, as
`spawnHostProcess` and `execHostFile` already did. This covers the
plugin-host and watcher forks and the CLI re-exec.
- The CLI re-exec inherits stdio. libuv only adds `CREATE_NO_WINDOW`
when no stdio is inherited, so the re-exec keeps its console.
- The browser-automation supervisor script sets it on its detached
child.
- Nine call sites that passed `windowsHide: true` to a helper that
already defaults it no longer do.
- **Lint:** a new `bb/no-raw-child-process` rule rejects value imports,
`import x = require(...)`, `require`, `process.getBuiltinModule`,
dynamic imports and re-exports of `node:child_process`, `child_process`,
`cross-spawn` and `execa` in apps/packages/plugins TS. Exempt:
`@bb/process-utils/src`, tests, test-support, scripts,
`provider-parity`, `connect-next` (hosted service), Vite configs, and
`apps/desktop/src/bb-process.ts` (the Linux-only AppImage bridge
bootstrap, which runs before the toolchain loads). It is a custom rule
because oxlint overrides replace `no-restricted-imports` per file, so
the `apps/server` block would have dropped a repo-wide ban. The one
production bypass, `workspace-processes.ts` (`ps`/`lsof`), now uses
`execHostFileCallback`.
- **Docs and surfaces:** `docs/provider-bridge-protocol.md` (Child
processes), `docs/provider-plugin-api.md`, the plugin-authoring
`providers.md`, `docs/api_to_audit.md` entries, the Plugin Guide
symbols, Turbo inputs for the protocol tests (Pi + ACP sources), and the
SDK bump to 0.6.163.

## Decisions for review

These change what users or plugin authors can see:

1. **Codex app-server now gets the full thread env**, the same as Claude
Code: thread identity, `BB_CLI`, `BB_SERVER_URL`, the thread `PATH`
(with bb's CLI dir) and all contributed vars. MCP servers, hooks and
anything codex starts see them. Codex shell commands already saw these
through `shell_environment_policy`.
2. **Contributed launch overrides now take effect**:
`BB_CODEX_BRIDGE_APP_SERVER_COMMAND`/`_ARGS` and
`BB_PI_BRIDGE_COMMAND`/`_ARGS` from a plugin pick the CLI. Before, only
the daemon's machine env could.
3. **Installation status and health now use the host's contributed
env.** A plugin-shipped Claude Code counts as installed, and the
composer unblocks after the status refreshes. Usage keeps reporting the
machine's own sign-in.
4. **Pi resolves a thread's model inside the thread's own Pi process and
requires Pi 0.84.3.** Pi 0.84.0–0.84.2 saved every RPC
`set_model`/`set_thinking_level` as the user's global default in
`~/.pi/agent/settings.json` (checked in the 0.84.2 package; fixed in
0.84.3, Aug 24), which is why bb previously pinned the model with launch
flags. `PI_MINIMUM_SUPPORTED_VERSION` is now 0.84.3, so older installs
get bb's existing "Update Pi" prompt. Pi 1.5.2 `set_model` records a
model change in the session transcript and leaves settings untouched
(checked live). The model-picker catalog is now one process per distinct
contributed env instead of one per cwd.
5. **No provider env on `bb.host` calls.** An earlier revision added
`ExperimentalHostCallOptions.providerEnv`. It is removed: a host worker
applies only the first of several overlapping calls' env, and any plugin
could have requested another provider's contributed secrets.
Native-roots lookup and the ACP agent probe use the host env, as on
main.
6. **SDK maintenance probes take an optional env.**
`experimental_resolveExecutablePath`, `experimental_commandOutput`,
`experimental_readCliVersion`, `experimental_npmLatestVersion` and
`experimental_probeNpmGlobalPackage` accept an optional last `env`
argument. Without it they behave exactly as before (the bridge's own
environment), so existing third-party plugins keep building and
typechecking. First-party bridges always pass
`buildProviderCliEnv(params.envVars)`. **Accepted in review:** items 1–4
as described. Item 6 was changed at review from a required argument to
an optional one.

## How you verified

- **Guard test first:**
`packages/provider-bridge-protocol/src/contract-tests/provider-cli-env.test.ts`
drives all four bridges in-process through one table. A wrapper records
the env the spawned CLI actually receives (the mocked Agent SDK `query`
options for Claude). Rows per provider:
- thread CLI receives every thread var (`BB_THREAD_ID`,
`BB_THREAD_STORAGE`, `BB_PROJECT_ID`, `BB_ENVIRONMENT_ID`, a contributed
`BB_*` and non-`BB_*` var, thread PATH first; no
`ELECTRON_RUN_AS_NODE`);
  - model-list CLI receives the contributed env;
  - launch settings come from the thread env;
- installation status and health probe the CLI the contributed env
selects (skipped on Windows; it uses sh fakes);
  - installation run plans against that CLI (Claude, Codex, Pi);
- the command-list CLI receives the contributed env and launch override
(Claude). This row fails on the previous head. The run bridges already
applied `envVars`; their gap was on the wire, and the required schema
fields now close it.

On main, **10 of 16 rows fail**: Codex thread (#4960), Codex launch
(#7179), Codex/Pi/ACP model list, Pi launch, and the Claude/Codex/Pi/ACP
probes (#7614). All pass on this branch.
- **Provider-parity replays (Pi):** the committed Pi recordings were
made while the bridge passed `--provider`/`--model`, so they hold no
`get_available_models`/`set_model`/`set_thinking_level` on the session
child. `replay-provider-child.mjs` now answers those (when the script
does not expect them) from the models the recording itself reports and
the replayed state. Without that change `pi/fork` fails locally with the
same `unansweredRequests` error CI showed; with it all 80 parity and
scenario replays pass.
- `bridge.model-resolution.test.ts` (Pi): with the bridge's own
`BB_PI_BRIDGE_COMMAND` pointing at a missing binary and the thread env
carrying a working one, a thread starts on `fake-provider/fake-model`.
Before the Pi change it failed with `spawn …/missing-pi ENOENT`. The
existing canonical, slash, ambiguity and missing-model cases pass
unchanged; `bridge.settings.test.ts` now expects
`set_model`/`set_thinking_level` on start, resume and fork.
- **Pi thread start, real `pi` 1.5.2 driven through the bridge** (picker
lists models, then three threads start; `thread/start` latency): main
~210 ms in the picker's folder and ~400–700 ms for the first thread in
another folder; this branch ~210 ms in both. An intermediate revision
that resolved through a thread-env catalog measured ~395 ms for the
first thread in the picker's folder, which is what this change removes.
- `provider-maintenance-kit.test.ts`: the probes called with no env
argument resolve, version and run a CLI through the bridge's own
environment (today's behaviour); an explicit env overrides it.
- `host-process-windows-hide.test.ts`: fails on main for
`forkHostProcess` only, passes now. `no-raw-child-process.test.mjs`
covers the rule. The rule flags main's `workspace-processes.ts`, and the
repo now lints clean under it.
- Server: `provider-states.test.ts` checks that health and installation
status carry a plugin's `BB_CLAUDE_CODE_EXECUTABLE` to the host with a
host-scoped context. Daemon: dispatch forwards `contributedEnv`, and the
gate key separates contributed envs.
- **Live before/after with a local plugin** contributing
`BB_REPRO_MARKER`, a wrapper `BB_CODEX_BRIDGE_APP_SERVER_COMMAND`, and a
fake `BB_CLAUDE_CODE_EXECUTABLE` that reports `9.9.9`. On main: the
Codex app-server had no
`BB_THREAD_ID`/`BB_THREAD_STORAGE`/`BB_PROJECT_ID` or marker, the
wrapper never ran, and Settings → Updates showed the system `claude
2.1.325` even after a restart. On this branch: the app-server has all of
them, it launches through the wrapper, Updates shows `9.9.9`, and Codex
and Pi threads reply `ok`.
- **Earlier live after-check:** I started this branch with `pnpm
start:worktree` (isolated data dir) and spawned a Codex thread. The turn
replied `ok`. `ps eww` on its `codex app-server` shows
`BB_THREAD_ID=thr_atcfaipne3`, the thread's `BB_THREAD_STORAGE`, and
`BB_SERVER_URL`/`BB_PROJECT_ID`/`BB_ENVIRONMENT_ID`.
- Locally: `pnpm exec turbo run typecheck --filter='...[origin/main]'`
(green), `turbo run lint --filter='[origin/main]'`, and targeted tests
in provider-bridge-protocol, provider-bridge-acp, provider-codex,
provider-claude-code, provider-pi, agent-runtime, process-utils,
host-daemon (gate, dispatch, app), server (installations, model catalog,
provider states) and scripts. Full suites are left to CI.
- Not verified: the `windowsHide` fork and sync-spawn defaults on a real
Windows console. They are unit-tested only.

Fixes #4960
Fixes #7179
Fixes #7614

> 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