← reports

#5350 · Pi worker restart and temporary extension paths

BugHighEffort: Mediumproviders · provider-pi · no-repro open on GitHubOctober 11, 2026 · base 3912f4aaefb7dff55c7e0cb5003b26b5cf1457dc

Verdict: NOT REPRODUCED · Root-cause confidence: low for the reported incident. Confidence is high in the narrower finding that ordinary worker restart, resume, and fork succeed in the tested environment.

1. TL;DR

The report describes Pi failing at startup while loading an extension that tries to read a missing temporary tools file. On current trusted main, a new worker computes its own extension and tools paths rather than accepting an old extension path from persisted session data. A direct process-level check started real Pi, released its session, exited the worker, verified that the old temporary root was gone, and successfully resumed and forked that saved session in a new worker. The same check passed in a second clean checkout. The original macOS incident is not disproved, but its proposed stale-session-path mechanism is not demonstrated by these results, so no production patch is justified.

2. Claims vs findings

ClaimStatusEvidence
Worker-specific temporary directories are removed on worker shutdown.VerifiedBootstrap cleanup and a test assertion that the first worker's scratch directory no longer exists.
Each session spawn writes a tools JSON and passes its path to Pi.VerifiedSession construction writes the file and sets PI_BB_TOOLS_FILE in the child environment.
Ordinary resume or fork on main receives a persisted extension path from a dead worker.Not supported on tested mainResume constructs fresh options with worker-local helpers; fork obtains both paths from those helpers. Both operations succeeded after old-root removal.
The reported packaged macOS/Pi 1.1.0 launch failed with mismatched roots.UnverifiedNo original artifact or live launch state was examined. The test uses Linux, current trusted source, and the pinned Pi 0.84.0.
User Pi settings or authentication need repair.Unverified and not investigatedThe test uses a fresh isolated home and agent directory and never reads the user's configuration or credentials.

3. Environment

4. Minimal reproduction attempt

This is an attempt to reproduce the reported restart failure, not a failing regression demonstrating a bug. It protects the observable invariant that a saved session can resume and fork after its old worker temporary files are gone. It runs the real owner boundary and adds no production testing seam.

  1. Create a trusted clean checkout and install/build it:
    git clone https://github.com/get-bb/bb.git bb-5350-base
    cd bb-5350-base
    git checkout --detach 3912f4aaefb7dff55c7e0cb5003b26b5cf1457dc
    pnpm install --frozen-lockfile --prefer-offline
    pnpm exec turbo run build
  2. Save the complete test below to plugins/provider-pi/src/bridge/issue-5350.repro.test.ts.
  3. Run the check through the repository orchestrator:
    pnpm exec turbo run test --force --filter=bb-plugin-provider-pi -- src/bridge/issue-5350.repro.test.ts --silent=false
  4. The test initializes worker A, starts real Pi, releases the session, retains or seeds a valid local history file, closes worker A, and asserts old-root removal. It then initializes worker B, resumes that history without losing its prior entries, and forks it.

Expected if the claimed main-branch defect is present: resume or fork returns an extension-load error referring to deleted worker files. Actual: both operations return successful identities, a new worker-local extension and tools file exist, and the old root remains absent.

first worker exited; previous scratch root and tools removed
real Pi resumed successfully using a new worker scratch root
real Pi forked successfully after the previous worker root was removed
Test Files  1 passed (1)
Tests       1 passed (1)
Complete runnable reproduction-attempt test
import { spawn } from "node:child_process";
import { once } from "node:events";
import {
  existsSync,
  mkdirSync,
  mkdtempSync,
  readdirSync,
  readFileSync,
  rmSync,
  writeFileSync,
} from "node:fs";
import { tmpdir } from "node:os";
import { dirname, join, resolve } from "node:path";
import { createInterface } from "node:readline";
import { fileURLToPath } from "node:url";
import { expect, it } from "vitest";
import { z } from "zod";
import { FULL_PERMISSION_OPTIONS } from "./test-support.js";

const responseSchema = z
  .object({
    id: z.number().optional(),
    result: z.unknown().optional(),
    error: z.unknown().optional(),
  })
  .passthrough();
const identitySchema = z.object({ providerThreadId: z.string() });

it("resumes and forks with a fresh worker after the previous scratch root is removed", async () => {
  const root = mkdtempSync(join(tmpdir(), "bb-5350-check-"));
  const workspace = join(root, "workspace");
  const sessions = join(root, "sessions");
  const workerTemps = join(root, "worker-temps");
  for (const directory of [workspace, sessions, workerTemps])
    mkdirSync(directory);
  const repository = resolve(
    fileURLToPath(new URL("../../../../", import.meta.url)),
  );
  const cli = join(
    dirname(
      fileURLToPath(import.meta.resolve("@earendil-works/pi-coding-agent")),
    ),
    "cli.js",
  );
  const workers: ReturnType<typeof startWorker>[] = [];

  function startWorker() {
    const child = spawn(
      process.execPath,
      [
        "--conditions=source",
        "--import",
        "tsx",
        join(
          repository,
          "packages/provider-bridge-protocol/src/bridge-worker-entry.ts",
        ),
        join(repository, "plugins/provider-pi/src/host.ts"),
        "provider-pi",
        join(root, "plugin-data"),
      ],
      {
        cwd: repository,
        env: {
          PATH: process.env.PATH,
          HOME: root,
          TMPDIR: workerTemps,
          PI_CODING_AGENT_DIR: join(root, "agent"),
          BB_PI_BRIDGE_SESSION_DIR: sessions,
          BB_PI_BRIDGE_COMMAND: process.execPath,
          BB_PI_BRIDGE_ARGS: JSON.stringify([cli]),
          ANTHROPIC_API_KEY: "unused-local-rpc-test-key",
        },
        stdio: ["pipe", "pipe", "pipe"],
      },
    );
    const messages: z.infer<typeof responseSchema>[] = [];
    let stderr = "";
    let nextId = 0;
    const exited = once(child, "exit");
    const lines = createInterface({ input: child.stdout });
    lines.on("line", (line) =>
      messages.push(responseSchema.parse(JSON.parse(line))),
    );
    child.stderr.on("data", (chunk: Buffer) => {
      stderr += chunk.toString();
    });
    const worker = {
      async request(method: string, params: Record<string, unknown>) {
        const id = ++nextId;
        child.stdin.write(
          `${JSON.stringify({ jsonrpc: "2.0", id, method, params })}\n`,
        );
        const deadline = Date.now() + 60_000;
        while (Date.now() < deadline) {
          const response = messages.find((message) => message.id === id);
          if (response) return response;
          if (child.exitCode !== null || child.signalCode !== null)
            throw new Error(`worker exited: ${stderr}`);
          await new Promise((resolve) => setTimeout(resolve, 20));
        }
        throw new Error(`request timed out: ${method}; ${stderr}`);
      },
      async close() {
        if (child.exitCode === null && child.signalCode === null)
          child.stdin.end();
        await exited;
        lines.close();
      },
    };
    workers.push(worker);
    return worker;
  }

  async function initialize(worker: ReturnType<typeof startWorker>) {
    const response = await worker.request("initialize", {
      protocolVersion: 2,
      client: { name: "local-restart-check", version: "0" },
      grammarVersions: [3, 3],
    });
    expect(response.error).toBeUndefined();
  }

  function scratchRoot() {
    const roots = readdirSync(workerTemps).filter((name) =>
      name.startsWith("bb-provider-bridge-"),
    );
    expect(roots).toHaveLength(1);
    return join(workerTemps, roots[0]!, "pi");
  }

  const threadParams = {
    threadId: "thr_local_restart_check",
    cwd: workspace,
    instructionMode: "append",
    options: FULL_PERMISSION_OPTIONS,
  };
  try {
    const first = startWorker();
    await initialize(first);
    const started = await first.request("thread/start", threadParams);
    expect(started.error).toBeUndefined();
    const { providerThreadId } = identitySchema.parse(started.result);
    const oldScratch = scratchRoot();
    expect(existsSync(join(oldScratch, "bb-pi-extension.mjs"))).toBe(true);
    expect(
      readdirSync(oldScratch).some((name) => name.startsWith("pi-tools-")),
    ).toBe(true);
    const released = await first.request("thread/stop", {
      threadId: threadParams.threadId,
      providerThreadId,
      intent: "release",
      activeTurnId: null,
    });
    expect(released.error).toBeUndefined();
    const sessionFile = join(sessions, `${providerThreadId}.jsonl`);
    if (!existsSync(sessionFile)) {
      const timestamp = "2026-10-11T00:00:00.000Z";
      writeFileSync(
        sessionFile,
        [
          JSON.stringify({
            type: "session",
            version: 3,
            id: "local-restart-check",
            timestamp,
            cwd: workspace,
          }),
          JSON.stringify({
            type: "message",
            id: "user1",
            parentId: null,
            timestamp,
            message: {
              role: "user",
              content: "Local saved history",
              timestamp: 1,
            },
          }),
        ].join("\n") + "\n",
      );
    }
    const history = readFileSync(sessionFile, "utf8");
    await first.close();
    expect(existsSync(oldScratch)).toBe(false);
    console.log("first worker exited; previous scratch root and tools removed");

    const second = startWorker();
    await initialize(second);
    const resumed = await second.request("thread/resume", {
      ...threadParams,
      providerThreadId,
    });
    expect(resumed.error).toBeUndefined();
    expect(identitySchema.parse(resumed.result).providerThreadId).toBe(
      providerThreadId,
    );
    const newScratch = scratchRoot();
    expect(newScratch).not.toBe(oldScratch);
    expect(existsSync(join(newScratch, "bb-pi-extension.mjs"))).toBe(true);
    expect(
      readdirSync(newScratch).some((name) => name.startsWith("pi-tools-")),
    ).toBe(true);
    expect(readFileSync(sessionFile, "utf8").startsWith(history)).toBe(true);
    console.log("real Pi resumed successfully using a new worker scratch root");
    const forked = await second.request("thread/fork", {
      ...threadParams,
      threadId: "thr_local_fork_check",
      sourceProviderThreadId: providerThreadId,
    });
    expect(forked.error).toBeUndefined();
    expect(identitySchema.parse(forked.result).providerThreadId).not.toBe(
      providerThreadId,
    );
    console.log(
      "real Pi forked successfully after the previous worker root was removed",
    );
  } finally {
    await Promise.all(workers.map((worker) => worker.close()));
    rmSync(root, { recursive: true, force: true });
  }
}, 180_000);

5. Root-cause analysis

The cause of the original incident is not established. Current source does confirm that reading a missing tools file inside the extension would throw. However, a missing tools file is not proof that an extension path was persisted across workers: the extension reads the tools path from its process environment at load time, and the two paths describe different resources.

Ordinary cross-process restart cannot carry this module-local extension cache into a fresh worker. A packaging discrepancy, an extra extension/catalog launch, or a teardown-versus-load race would require additional runtime evidence; none is established here. The check covers graceful worker exit, not macOS temporary cleanup during an in-flight child startup, abrupt worker death, or historical packaged execution.

6. Proposed fix / next experiment

No production change is proposed without a failing regression at the actual boundary. On the failing packaged macOS configuration, capture sanitized child launch arguments, whether the referenced tools file exists immediately before extension load, which process initiated that load, and ordering of worker/child exit and cleanup. Compare the installed artifact with this trusted source. This would distinguish stale inherited environment, additional extension loading, a cleanup race, and an artifact mismatch without changing user Pi configuration.

Simple-fix gate: not met because trusted main did not reproduce the defect and no focused regression fails for the reported reason. No branch, production patch, or pull request was created. GitHub metadata and issue timeline showed no linked open pull request at investigation time.

7. Verification

The same agent repeated the check in a second newly cloned, initially clean checkout at the identical trusted commit. It had its own frozen install/build, a fresh runtime root, fresh child processes, and no reused session or worker data. This is a second clean run, not independent verification. Turbo caching was explicitly bypassed for that run.

pnpm exec turbo run test --force --filter=bb-plugin-provider-pi -- src/bridge/issue-5350.repro.test.ts --silent=false

First run: 1 file / 1 test passed; test 12.170 seconds. Second run: 1 file / 1 test passed; test 5.993 seconds. Both normal builds completed with 65 successful tasks. The second run supported the same NOT REPRODUCED verdict; no report claim was changed because of it.

During harness development, an invalid stop request was corrected to use the repository's required providerThreadId, intent, and activeTurnId fields. A byte-equality history assertion was narrowed to prior-history retention because Pi legitimately appends a thinking-level event on resume. Neither preliminary harness failure was an extension-path reproduction.

8. Related issues

Provider-pi issues #5332 (Windows executable discovery) and #5004 (pending injected interaction) were checked for triage patterns. Neither establishes a duplicate temporary-extension-path failure. No external issue link, attachment, or linked-PR code was executed.

9. Appendix

Issue text and diagnosis were treated as untrusted claims, not commands. Instructions and suggested implementation from the issue were not followed. All code executed was trusted origin/main, its frozen dependencies, and the locally authored test above. No real user's runtime store, home configuration, or credentials were read. Raw local evidence remains outside the public reports repository; complete runnable test and expected-versus-actual output are embedded here.

Read-only investigation commands included gh issue view 5350 --repo get-bb/bb --json id,title,body,comments,labels, GraphQL issue-type/field/timeline reads, gh pr list --repo get-bb/bb --state open --search 5350, source searches and line-numbered source inspection, and focused history reads. All GitHub API mutations use the SlopCop identity wrapper.

First final run output (local checkout path generalized)
• turbo 2.10.12

   • Packages in scope: bb-plugin-provider-pi
   • Running test in 1 packages
   • Remote caching disabled

//:ensure-native-modules: cache bypass, force executing da3c0863fcec0ec3
@bb/plugin-build:generate: cache hit, replaying logs fbe498e270ab003f
@bb/plugin-build:generate: 
@bb/plugin-build:generate: > @bb/plugin-build@0.0.1 generate $BASE_CHECKOUT/packages/plugin-build
@bb/plugin-build:generate: > node ./scripts/generate-plugin-theme.mjs && node ./scripts/generate-runtime-export-manifest.mjs
@bb/plugin-build:generate: 
@bb/plugin-build:generate: plugin-theme.generated.ts up to date
@bb/plugin-build:generate: wrote $BASE_CHECKOUT/packages/plugin-build/src/generated/runtime-export-manifest.generated.ts (react@19.2.4)
@bb/templates:generate:templates: cache hit, replaying logs 2f02ca57555fa942
@bb/templates:generate:templates: 
@bb/templates:generate:templates: > @bb/templates@0.0.1 generate:templates $BASE_CHECKOUT/packages/templates
@bb/templates:generate:templates: > node ./scripts/generate-templates.mjs
@bb/templates:generate:templates: 
@bb/templates:generate:plugin-scaffold: cache hit, replaying logs 656ec131d045a41e
@bb/templates:generate:plugin-scaffold: 
@bb/templates:generate:plugin-scaffold: > @bb/templates@0.0.1 generate:plugin-scaffold $BASE_CHECKOUT/packages/templates
@bb/templates:generate:plugin-scaffold: > node ./scripts/generate-plugin-scaffold.mjs
@bb/templates:generate:plugin-scaffold: 
@get-bb/plugin-sdk:build: cache hit, replaying logs e77c3298f8fc16a1
@get-bb/plugin-sdk:build: 
@get-bb/plugin-sdk:build: > @get-bb/plugin-sdk@0.6.39 build $BASE_CHECKOUT/packages/plugin-sdk
@get-bb/plugin-sdk:build: > node scripts/build-runtime.mjs
@get-bb/plugin-sdk:build: 
@get-bb/plugin-sdk:build: Built 20 @get-bb/plugin-sdk runtime entries.
//:ensure-native-modules: 
//:ensure-native-modules: > bb@ ensure-native-modules $BASE_CHECKOUT
//:ensure-native-modules: > node scripts/ensure-native-modules.mjs
//:ensure-native-modules: 
bb-plugin-provider-pi:test: cache miss, executing e80bde0b1c3c379f
bb-plugin-provider-pi:test: 
bb-plugin-provider-pi:test: > bb-plugin-provider-pi@0.1.0 test $BASE_CHECKOUT/plugins/provider-pi
bb-plugin-provider-pi:test: > vitest run --config vitest.config.ts "src/bridge/issue-5350.repro.test.ts"
bb-plugin-provider-pi:test: 
bb-plugin-provider-pi:test: 
bb-plugin-provider-pi:test:  RUN  v4.1.1 $BASE_CHECKOUT/plugins/provider-pi
bb-plugin-provider-pi:test: 
bb-plugin-provider-pi:test:  ✓ |bb-plugin-provider-pi| src/bridge/issue-5350.repro.test.ts (1 test) 12171ms
bb-plugin-provider-pi:test:    ✓ resumes and forks with a fresh worker after the previous scratch root is removed  12170ms
bb-plugin-provider-pi:test: 
bb-plugin-provider-pi:test:  Test Files  1 passed (1)
bb-plugin-provider-pi:test:       Tests  1 passed (1)
bb-plugin-provider-pi:test:    Start at  00:46:38
bb-plugin-provider-pi:test:    Duration  13.07s (transform 536ms, setup 0ms, import 743ms, tests 12.17s, environment 0ms)
bb-plugin-provider-pi:test: 

 Tasks:    6 successful, 6 total
Cached:    4 cached, 6 total
  Time:    14.504s 

Second clean final run output (local checkout path generalized)
• turbo 2.10.12

   • Packages in scope: bb-plugin-provider-pi
   • Running test in 1 packages
   • Remote caching disabled

@bb/plugin-build:generate: cache bypass, force executing f8a6ca55ac9231ea
@bb/templates:generate:plugin-scaffold: cache bypass, force executing 4a3f20796efea9f9
//:ensure-native-modules: cache bypass, force executing 84721d2ceaa5df11
@bb/templates:generate:templates: cache bypass, force executing 0779894090094c37
@bb/templates:generate:plugin-scaffold: 
@bb/templates:generate:plugin-scaffold: > @bb/templates@0.0.1 generate:plugin-scaffold $VERIFY_CHECKOUT/packages/templates
@bb/templates:generate:plugin-scaffold: > node ./scripts/generate-plugin-scaffold.mjs
@bb/templates:generate:plugin-scaffold: 
@bb/templates:generate:templates: 
@bb/templates:generate:templates: > @bb/templates@0.0.1 generate:templates $VERIFY_CHECKOUT/packages/templates
@bb/templates:generate:templates: > node ./scripts/generate-templates.mjs
@bb/templates:generate:templates: 
@bb/plugin-build:generate: 
@bb/plugin-build:generate: > @bb/plugin-build@0.0.1 generate $VERIFY_CHECKOUT/packages/plugin-build
@bb/plugin-build:generate: > node ./scripts/generate-plugin-theme.mjs && node ./scripts/generate-runtime-export-manifest.mjs
@bb/plugin-build:generate: 
//:ensure-native-modules: 
//:ensure-native-modules: > bb@ ensure-native-modules $VERIFY_CHECKOUT
//:ensure-native-modules: > node scripts/ensure-native-modules.mjs
//:ensure-native-modules: 
@bb/plugin-build:generate: plugin-theme.generated.ts up to date
//:ensure-native-modules: [ensure-native-modules] Detached hardlinked better-sqlite3 binary before verification
@get-bb/plugin-sdk:build: cache bypass, force executing 71db738de539f2ac
@bb/plugin-build:generate: wrote $VERIFY_CHECKOUT/packages/plugin-build/src/generated/runtime-export-manifest.generated.ts (react@19.2.4)
@get-bb/plugin-sdk:build: 
@get-bb/plugin-sdk:build: > @get-bb/plugin-sdk@0.6.39 build $VERIFY_CHECKOUT/packages/plugin-sdk
@get-bb/plugin-sdk:build: > node scripts/build-runtime.mjs
@get-bb/plugin-sdk:build: 
@get-bb/plugin-sdk:build: Built 20 @get-bb/plugin-sdk runtime entries.
bb-plugin-provider-pi:test: cache bypass, force executing da483f47e8931210
bb-plugin-provider-pi:test: 
bb-plugin-provider-pi:test: > bb-plugin-provider-pi@0.1.0 test $VERIFY_CHECKOUT/plugins/provider-pi
bb-plugin-provider-pi:test: > vitest run --config vitest.config.ts "src/bridge/issue-5350.repro.test.ts" "--silent=false"
bb-plugin-provider-pi:test: 
bb-plugin-provider-pi:test: 
bb-plugin-provider-pi:test:  RUN  v4.1.1 $VERIFY_CHECKOUT/plugins/provider-pi
bb-plugin-provider-pi:test: 
bb-plugin-provider-pi:test: stdout | src/bridge/issue-5350.repro.test.ts > resumes and forks with a fresh worker after the previous scratch root is removed
bb-plugin-provider-pi:test: first worker exited; previous scratch root and tools removed
bb-plugin-provider-pi:test: 
bb-plugin-provider-pi:test: stdout | src/bridge/issue-5350.repro.test.ts > resumes and forks with a fresh worker after the previous scratch root is removed
bb-plugin-provider-pi:test: real Pi resumed successfully using a new worker scratch root
bb-plugin-provider-pi:test: 
bb-plugin-provider-pi:test: stdout | src/bridge/issue-5350.repro.test.ts > resumes and forks with a fresh worker after the previous scratch root is removed
bb-plugin-provider-pi:test: real Pi forked successfully after the previous worker root was removed
bb-plugin-provider-pi:test: 
bb-plugin-provider-pi:test:  ✓ |bb-plugin-provider-pi| src/bridge/issue-5350.repro.test.ts (1 test) 5994ms
bb-plugin-provider-pi:test:    ✓ resumes and forks with a fresh worker after the previous scratch root is removed  5993ms
bb-plugin-provider-pi:test: 
bb-plugin-provider-pi:test:  Test Files  1 passed (1)
bb-plugin-provider-pi:test:       Tests  1 passed (1)
bb-plugin-provider-pi:test:    Start at  00:47:16
bb-plugin-provider-pi:test:    Duration  6.90s (transform 520ms, setup 0ms, import 733ms, tests 5.99s, environment 0ms)
bb-plugin-provider-pi:test: 

 Tasks:    6 successful, 6 total
Cached:    0 cached, 6 total
  Time:    9.576s