← reports

#5351 · Inherited tool manifest breaks Pi catalog startup

BugHighEffort: Lowproviders · provider-pi · confirmed-reproGitHub issue2026-10-11 · base 3912f4aaefb7dff55c7e0cb5003b26b5cf1457dc

Verdict: REPRODUCED · Root-cause confidence: high

1. TL;DR

The Pi model catalog can fail to start even though normal thread sessions use their own fresh tool manifests. The catalog process inherits a tool-manifest path from its parent rather than supplying one for its own execution. When that file has been deleted, the actual BB Pi extension throws ENOENT during initialization and the model request rejects with a child-exit error. Two clean trusted-main checkouts reproduce this through the real catalog, subprocess launcher, and extension, with the repository's fake Pi RPC process standing in for the external Pi binary. This verifies the local startup failure, not the reporter's macOS app-relaunch history or their exact installed versions.

2. Claims vs findings

ClaimStatusEvidence
A stale inherited manifest breaks model catalog startup.VerifiedBoth clean runs exit 1; the real extension read fails with ENOENT and listModels rejects.
Normal thread sessions supply a fresh manifest.Verified in sourceSession startup writes a manifest and explicitly overrides the inherited path. This report does not run a real authenticated Pi turn.
The value propagated through the macOS desktop, server, daemon, and worker processes.UnverifiedNo macOS instance or reporter process tree was inspected. The reproduction deliberately seeds only the catalog parent's environment.
The proposed relaunch workaround clears the problem.UnverifiedLaunchServices is unavailable in this Linux environment.

3. Environment

4. Minimal reproduction

  1. Create a trusted clean checkout and install/build the repository:
    git clone https://github.com/get-bb/bb.git bb-5351
    cd bb-5351
    git checkout --detach 3912f4aaefb7dff55c7e0cb5003b26b5cf1457dc
    pnpm install --frozen-lockfile --prefer-offline
    pnpm exec turbo run build
  2. Replace plugins/provider-pi/src/bridge/catalog.test.ts with the complete test file below. It adds one scenario to the existing catalog test owner: create/delete a manifest, seed its path into the parent environment, and list models.
  3. Run the regression:
    pnpm exec turbo run test --filter=bb-plugin-provider-pi -- src/bridge/catalog.test.ts -t "earlier session"

Expected: the catalog returns ["fake-provider/fake-model"] without depending on an earlier session's manifest. Actual: the subprocess exits 1 during real extension initialization, and the catalog request fails.

Observed output (only checkout and temporary directory identities are redacted):

bb-plugin-provider-pi:test: Error: ENOENT: no such file or directory, open '<TEMP>/previous-session-tools.json'
bb-plugin-provider-pi:test: ⎯⎯⎯⎯⎯⎯⎯ Failed Tests 1 ⎯⎯⎯⎯⎯⎯⎯
bb-plugin-provider-pi:test: PiRpcChildExitedError: pi exited (code 1, signal null): node:fs:441
bb-plugin-provider-pi:test: Error: ENOENT: no such file or directory, open '<TEMP>/previous-session-tools.json'
bb-plugin-provider-pi:test:  Test Files  1 failed (1)
bb-plugin-provider-pi:test:       Tests  1 failed | 6 skipped (7)
bb-plugin-provider-pi:test:    Duration  1.83s (transform 518ms, setup 0ms, import 725ms, tests 954ms, environment 0ms)
 Tasks:    5 successful, 6 total
  Time:    3.275s 
Complete executable regression test file
import {
  existsSync,
  mkdtempSync,
  readFileSync,
  rmSync,
  writeFileSync,
} from "node:fs";
import { tmpdir } from "node:os";
import { join } from "node:path";
import { afterEach, describe, expect, it, vi } from "vitest";
import { BB_PI_EXTENSION_SOURCE } from "./bb-pi-extension.js";
import { closeAllPiCatalogs, getPiCatalog } from "./catalog.js";
import { PI_BRIDGE_ARGS_ENV, PI_BRIDGE_COMMAND_ENV } from "./rpc-child.js";
import { fakePiPath } from "./test-support.js";

const originalEnv = { ...process.env };
const tempDirs: string[] = [];

afterEach(async () => {
  await closeAllPiCatalogs();
  process.env = { ...originalEnv };
  for (const dir of tempDirs.splice(0)) {
    rmSync(dir, { recursive: true, force: true });
  }
});

describe("pi catalog child generations", () => {
  it("re-reads model scope after the catalog child restarts", async () => {
    const workspace = mkdtempSync(join(tmpdir(), "bb-pi-catalog-"));
    tempDirs.push(workspace);
    const extensionPath = join(workspace, "bb-extension.mjs");
    const spawnCounterPath = join(workspace, "spawns.txt");
    const processLogPath = join(workspace, "processes.txt");
    writeFileSync(extensionPath, BB_PI_EXTENSION_SOURCE);

    process.env[PI_BRIDGE_COMMAND_ENV] = process.execPath;
    process.env[PI_BRIDGE_ARGS_ENV] = JSON.stringify([fakePiPath]);
    process.env.FAKE_PI_SPAWN_COUNTER_FILE = spawnCounterPath;
    process.env.FAKE_PI_PROCESS_LOG = processLogPath;
    process.env.FAKE_PI_SCOPE_BY_SPAWN = "1";
    process.env.FAKE_PI_EXIT_AFTER_FIRST_AVAILABLE = "1";

    const catalog = await getPiCatalog(workspace, extensionPath);
    const first = await catalog.listModels();
    expect(first.models.map((model) => model.id)).toEqual([
      "fake-provider/fake-model",
    ]);

    await vi.waitFor(() => {
      expect(readFileSync(processLogPath, "utf8")).toContain("exit:");
    });

    const second = await catalog.listModels();
    expect(second.models.map((model) => model.id)).toEqual([
      "fake-provider/fake-mini",
    ]);
    expect(second.models[0]?.isDefault).toBe(true);
    expect(readFileSync(spawnCounterPath, "utf8")).toBe("2");
  }, 60_000);
});

const FAKE_MODEL = {
  id: "fake-model",
  name: "Fake Model",
  provider: "fake-provider",
  input: ["text"],
  reasoning: true,
  contextWindow: 200_000,
};
const ADDED_MODEL = {
  id: "added-model",
  name: "Added Model",
  provider: "added-provider",
  input: ["text"],
  reasoning: false,
  contextWindow: 64_000,
};

interface FakeCatalogPaths {
  workspace: string;
  extensionPath: string;
  modelsPath: string;
  refreshLogPath: string;
  spawnCounterPath: string;
  processLogPath: string;
}

function setUpFakeCatalog(env: Record<string, string>): FakeCatalogPaths {
  const workspace = mkdtempSync(join(tmpdir(), "bb-pi-catalog-"));
  tempDirs.push(workspace);
  const paths: FakeCatalogPaths = {
    workspace,
    extensionPath: join(workspace, "bb-extension.mjs"),
    modelsPath: join(workspace, "models.json"),
    refreshLogPath: join(workspace, "refreshes.txt"),
    spawnCounterPath: join(workspace, "spawns.txt"),
    processLogPath: join(workspace, "processes.txt"),
  };
  writeFileSync(paths.extensionPath, BB_PI_EXTENSION_SOURCE);
  writeFileSync(paths.modelsPath, JSON.stringify([FAKE_MODEL]));
  process.env[PI_BRIDGE_COMMAND_ENV] = process.execPath;
  process.env[PI_BRIDGE_ARGS_ENV] = JSON.stringify([fakePiPath]);
  process.env.FAKE_PI_MODELS_FILE = paths.modelsPath;
  process.env.FAKE_PI_REFRESH_LOG = paths.refreshLogPath;
  process.env.FAKE_PI_SPAWN_COUNTER_FILE = paths.spawnCounterPath;
  process.env.FAKE_PI_PROCESS_LOG = paths.processLogPath;
  Object.assign(process.env, env);
  return paths;
}

function readLogLines(path: string): string[] {
  return existsSync(path)
    ? readFileSync(path, "utf8").split("\n").filter(Boolean)
    : [];
}

function processIds(path: string, step: "spawn" | "exit"): string[] {
  return readLogLines(path)
    .map((line) => line.split(":"))
    .filter(([entry]) => entry === step)
    .map(([, pid]) => pid ?? "");
}

function modelIds(result: { models: { id: string }[] }): string[] {
  return result.models.map((model) => model.id);
}

describe("pi catalog freshness", () => {
  it("lists models after an earlier session's tool manifest is deleted", async () => {
    const paths = setUpFakeCatalog({});
    const toolsPath = join(paths.workspace, "previous-session-tools.json");
    writeFileSync(toolsPath, "[]");
    rmSync(toolsPath);
    process.env.PI_BB_TOOLS_FILE = toolsPath;

    const catalog = await getPiCatalog(paths.workspace, paths.extensionPath);

    expect(modelIds(await catalog.listModels())).toEqual([
      "fake-provider/fake-model",
    ]);
  }, 60_000);

  it("serves models added after the child started without respawning it", async () => {
    const paths = setUpFakeCatalog({});

    const catalog = await getPiCatalog(paths.workspace, paths.extensionPath);
    expect(modelIds(await catalog.listModels())).toEqual([
      "fake-provider/fake-model",
    ]);

    writeFileSync(paths.modelsPath, JSON.stringify([FAKE_MODEL, ADDED_MODEL]));

    expect(modelIds(await catalog.listModels())).toEqual([
      "fake-provider/fake-model",
      "added-provider/added-model",
    ]);
    expect(readFileSync(paths.spawnCounterPath, "utf8")).toBe("1");
    expect(readLogLines(paths.refreshLogPath)).toEqual([
      JSON.stringify({ allowNetwork: false }),
    ]);
  }, 60_000);

  it("shares one model refresh between concurrent reads", async () => {
    const paths = setUpFakeCatalog({});

    const catalog = await getPiCatalog(paths.workspace, paths.extensionPath);
    await catalog.listModels();
    writeFileSync(paths.modelsPath, JSON.stringify([FAKE_MODEL, ADDED_MODEL]));

    const [listed, raw] = await Promise.all([
      catalog.listModels(),
      catalog.rawModels(),
    ]);

    expect(modelIds(listed)).toContain("added-provider/added-model");
    expect(raw.map((model) => model.id)).toContain("added-model");
    expect(readLogLines(paths.refreshLogPath)).toHaveLength(1);
    expect(readFileSync(paths.spawnCounterPath, "utf8")).toBe("1");
  }, 60_000);

  it("falls back to a new child when Pi exposes no model registry", async () => {
    const paths = setUpFakeCatalog({ FAKE_PI_NO_MODEL_REGISTRY: "1" });

    const catalog = await getPiCatalog(paths.workspace, paths.extensionPath);
    expect(modelIds(await catalog.listModels())).toEqual([
      "fake-provider/fake-model",
    ]);

    writeFileSync(paths.modelsPath, JSON.stringify([FAKE_MODEL, ADDED_MODEL]));

    expect(modelIds(await catalog.listModels())).toEqual([
      "fake-provider/fake-model",
      "added-provider/added-model",
    ]);
    expect(readFileSync(paths.spawnCounterPath, "utf8")).toBe("2");
    expect(readLogLines(paths.refreshLogPath)).toEqual([]);
  }, 60_000);

  it.each([
    ["hangs", "hang"],
    ["rejects", "reject"],
  ])(
    "replaces the child when the model refresh %s",
    async (_label, failure) => {
      const paths = setUpFakeCatalog({ FAKE_PI_REFRESH_FAILURE: failure });

      const catalog = await getPiCatalog(paths.workspace, paths.extensionPath);
      await catalog.listModels();
      writeFileSync(
        paths.modelsPath,
        JSON.stringify([FAKE_MODEL, ADDED_MODEL]),
      );

      expect(modelIds(await catalog.listModels())).toEqual([
        "fake-provider/fake-model",
        "added-provider/added-model",
      ]);
      const spawned = processIds(paths.processLogPath, "spawn");
      expect(spawned).toHaveLength(2);
      expect(processIds(paths.processLogPath, "exit")).toEqual([spawned[0]]);
    },
    60_000,
  );
});

The complete test is inline because the reports repository forbids committed test/script artifacts. Raw logs and the test file remain in local evidence storage, outside this public repository.

5. Root cause

The catalog uses an empty override map: plugins/provider-pi/src/bridge/catalog.ts:132.

    const child = new PiRpcChild({
      cwd,
      env: buildPiChildEnv({}),
      args: ["--mode", "rpc", "--no-session", "--extension", extensionPath],

The Pi child environment helper sanitizes BB/runtime variables but forwards the inherited manifest path unchanged: plugins/provider-pi/src/bridge/rpc-child.ts:89.

export function buildPiChildEnv(
  overrides: Record<string, string>,
): NodeJS.ProcessEnv {
  return {
    ...withoutBridgeRuntimeEnv(
      sanitizeInheritedChildProcessEnv({ env: process.env }),
    ),
    ...overrides,
  };
}

The shared sanitizer excludes NODE_ENV and BB_-prefixed variables, not the Pi manifest variable: packages/process-utils/src/environment.ts:6. The extension then synchronously opens that inherited file: plugins/provider-pi/src/bridge/bb-pi-extension.ts:168.

export default function bbExtension(pi) {
  const toolsFile = process.env.PI_BB_TOOLS_FILE;
  const tools = toolsFile ? JSON.parse(readFileSync(toolsFile, "utf8")) : [];

An absent manifest variable is already supported: the extension uses an empty tools array. By contrast, sessions write fresh manifests and pass an explicit current-session override: plugins/provider-pi/src/bridge/rpc-session.ts:193, plugins/provider-pi/src/bridge/rpc-session.ts:240. Thus stale ambient state affects catalog startup even while session startup can work.

6. Proposed fix

Remove only the inherited PI_BB_TOOLS_FILE from the Pi child environment before applying explicit per-spawn overrides. Catalog children then start without session-local tools, while session children retain their newly written manifests. Do not broadly strip every PI_ variable or modify app/daemon startup policy: those changes are not necessary for this reproduced failure and could affect unrelated configuration.

7. Verification

The same agent repeated the reproduction in a second clean detached checkout of the exact base commit, with a separate frozen install and freshly created test workspace. Only the added regression test changed; production code remained byte-for-byte at the trusted base. The command included --force to rule out a cached result:

pnpm exec turbo run test --filter=bb-plugin-provider-pi --force -- src/bridge/catalog.test.ts -t "earlier session"
bb-plugin-provider-pi:test: Error: ENOENT: no such file or directory, open '<TEMP>/previous-session-tools.json'
bb-plugin-provider-pi:test: ⎯⎯⎯⎯⎯⎯⎯ Failed Tests 1 ⎯⎯⎯⎯⎯⎯⎯
bb-plugin-provider-pi:test: PiRpcChildExitedError: pi exited (code 1, signal null): node:fs:441
bb-plugin-provider-pi:test: Error: ENOENT: no such file or directory, open '<TEMP>/previous-session-tools.json'
bb-plugin-provider-pi:test:  Test Files  1 failed (1)
bb-plugin-provider-pi:test:       Tests  1 failed | 6 skipped (7)
bb-plugin-provider-pi:test:    Duration  1.79s (transform 522ms, setup 0ms, import 727ms, tests 915ms, environment 0ms)
 Tasks:    5 successful, 6 total
  Time:    4.154s 

Both runs fail for the same missing manifest read in the actual extension. No report correction was needed. This is a second clean reproduction by the same agent, not independent verification.

8. Related issues

#5350 concerns another temporary-path/session-resume claim. This report proves the distinct catalog environment-inheritance failure; it does not establish the other issue's cause. No linked open pull request was found before fix work.

9. Appendix

Issue content was treated as untrusted claims. No issue-supplied command, script, patch, binary, linked branch, or external URL was executed or fetched. Source paths, test setup, and the narrow fix proposal were derived from trusted repository code.

Relevant commands: fetch origin/main; create branch and detached worktrees at the recorded base; frozen pnpm installs; Turbo build; focused catalog regression on both unchanged production trees; forced clean-checkout repetition. Raw output is retained locally and is not committed to the public reports site.