← reports

#6309 · Interrupted working-directory lookup aborts provider initialization

Bug High Effort: Medium providers provider-claude-code GitHub issue

2026-10-26 · trusted main 3540a699e29034b53da32bb7efa6f5b4055209eb

Verdict: PARTIALLY REPRODUCED · Root-cause confidence: high for the startup-failure mechanism; the native signal trigger remains unverified. Reproduction label: partial-repro.

1. TL;DR

A single failed working-directory lookup can prevent the Claude provider from starting. A deterministic injected EINTR at the real bundled SDK call makes the real bridge worker exit with status 1 before it reads a request. Healthy startup exits normally with the same empty input. The result repeats in a second clean checkout of the same trusted commit. This is not a reproduction of an operating-system signal interrupting getcwd: the native call is replaced only at the targeted SDK invocation.

2. Claims vs findings

ClaimStatusEvidence
A cwd failure can abort provider import before request processing.Verified under fault injectionThe built provider host and unchanged worker produce the load-failure diagnostic and exit 1 with empty stdin.
SDK initialization evaluates cwd outside the realpath catch.VerifiedLocked SDK 0.3.245 and the built bundle show the call before the try block. The injected stack identifies jae in host.js.
A real signal caused the reporter's repeated failures.UnverifiedNo original runtime, native trace, or reporter logs were available. No real EINTR was induced here.
The failure is independent of provider authentication.Verified for this mechanismIt occurs during module evaluation with a fresh temporary HOME and without submitting a provider request.
Retrying import once is sufficient.Refuted for the same module URLA second import returns the identical cached evaluation error after the sole injected failure has already been consumed.
Reported Electron/Node/libuv versions and the exact number of startup cwd calls.UnverifiedThe test uses Linux/Node 22 and confirms the failing call, not an exhaustive startup-call inventory.

3. Environment

4. Minimal reproduction

Clone trusted main at the recorded commit, install frozen dependencies, and build the plugin with the normal repository tooling:

git clone https://github.com/get-bb/bb.git source
cd source
git checkout --detach 3540a699e29034b53da32bb7efa6f5b4055209eb
pnpm install --frozen-lockfile --prefer-offline
pnpm exec turbo run build --filter=bb-plugin-provider-claude-code...
pnpm exec turbo run prepare:bundled --filter=bb-plugin-provider-claude-code
cd ..

Save the following two complete files together in a separate local directory. The preloader throws once only when the stack includes this provider's built host artifact. It does not edit the repository, dependency, or packaged bundle.

cwd-fault.mjs

const originalCwd = process.cwd.bind(process);
const faultCode = process.env.BB_REPRO_CWD_FAULT;
let injected = false;

if (faultCode) {
  process.cwd = () => {
    const stack = new Error().stack ?? "";
    if (!injected && stack.includes("/provider-claude-code/.bundled-runtime/dist/host.js")) {
      injected = true;
      process.stderr.write(`injected one cwd failure: ${faultCode}\n`);
      process.stderr.write(`${stack.split("\n").find((line) => line.includes("/provider-claude-code/.bundled-runtime/dist/host.js"))?.trim()}\n`);
      throw Object.assign(new Error(`injected ${faultCode} at process.cwd`), {
        code: faultCode,
        syscall: "uv_cwd",
      });
    }
    return originalCwd();
  };
}

run.mjs

import assert from "node:assert/strict";
import { spawnSync } from "node:child_process";
import { mkdtempSync, rmSync } from "node:fs";
import { tmpdir } from "node:os";
import { join, resolve } from "node:path";
import { fileURLToPath } from "node:url";

const checkout = resolve(process.argv[2]);
const dataDir = mkdtempSync(join(tmpdir(), "bb-6309-data-"));
const preload = fileURLToPath(new URL("./cwd-fault.mjs", import.meta.url));
const worker = join(checkout, "packages/provider-bridge-protocol/src/bridge-worker-entry.ts");
const host = join(checkout, "plugins/provider-claude-code/.bundled-runtime/dist/host.js");
const tsx = join(checkout, "node_modules/tsx/dist/loader.mjs");

try {
  for (const fault of ["", "EINTR", "ENOENT"]) {
    const result = spawnSync(process.execPath, [
      "--conditions=source", "--import", tsx, "--import", preload,
      worker, host, "provider-claude-code", dataDir,
    ], {
      cwd: dataDir,
      encoding: "utf8",
      input: "",
      timeout: 30000,
      env: { PATH: process.env.PATH, HOME: dataDir, TMPDIR: dataDir,
        XDG_CONFIG_HOME: dataDir, BB_REPRO_CWD_FAULT: fault },
    });
    assert.ifError(result.error);
    const stderr = result.stderr.replaceAll(checkout, "<checkout>").replaceAll(dataDir, "<temporary-data>");
    console.log(`case=${fault || "control"} exit=${result.status}`);
    console.log(stderr.trim() || "stderr=(empty)");
    if (fault) {
      assert.equal(result.status, 1);
      assert.match(stderr, new RegExp(`injected one cwd failure: ${fault}`));
      assert.match(stderr, /failed to load its provider bridge/);
      assert.match(stderr, new RegExp(`injected ${fault} at process.cwd`));
    } else {
      assert.equal(result.status, 0);
    }
  }
  const cachedImport = spawnSync(process.execPath, [
    "--import", preload, "--input-type=module", "--eval",
    `const moduleUrl = ${JSON.stringify(new URL(`file://${host}`).href)};
     let firstError;
     try { await import(moduleUrl); } catch (error) { firstError = error; }
     if (!firstError) throw new Error("Expected initial import to fail");
     try { await import(moduleUrl); throw new Error("Expected cached import failure"); }
     catch (error) { if (error !== firstError) throw error; }
     console.log("PASS: retrying the same module URL returns the cached evaluation failure");`,
  ], {
    cwd: dataDir, encoding: "utf8", timeout: 30000,
    env: { PATH: process.env.PATH, HOME: dataDir, TMPDIR: dataDir,
      XDG_CONFIG_HOME: dataDir, BB_REPRO_CWD_FAULT: "EINTR" },
  });
  assert.ifError(cachedImport.error);
  assert.equal(cachedImport.status, 0, cachedImport.stderr);
  console.log(cachedImport.stdout.trim());
  console.log("PASS: healthy startup succeeds; one interrupted cwd read aborts the real provider import.");
} finally {
  rmSync(dataDir, { recursive: true, force: true });
}

Run with an absolute checkout path:

node /path/to/repro/run.mjs "$PWD/source"

Expected recovery behavior: one transient EINTR should not prevent startup; permanent cwd failures must remain visible. Observed baseline behavior: healthy startup exits 0; one injected EINTR exits 1; one ENOENT also exits 1. The script is a passing diagnostic reproducer, not a before/after fix regression test.

Actual output — first checkout

case=control exit=0
stderr=(empty)
case=EINTR exit=1
injected one cwd failure: EINTR
at jae (<checkout>/plugins/provider-claude-code/.bundled-runtime/dist/host.js:224:102369)
plugin "provider-claude-code" failed to load its provider bridge: injected EINTR at process.cwd
case=ENOENT exit=1
injected one cwd failure: ENOENT
at jae (<checkout>/plugins/provider-claude-code/.bundled-runtime/dist/host.js:224:102369)
plugin "provider-claude-code" failed to load its provider bridge: injected ENOENT at process.cwd
PASS: retrying the same module URL returns the cached evaluation failure
PASS: healthy startup succeeds; one interrupted cwd read aborts the real provider import.

5. Root cause

The Claude SDK reads process.cwd() during module evaluation outside its realpath catch; an interrupted read rejects the provider import and the bridge worker exits. The provider host statically re-exports the bridge, which statically imports the SDK. The dependency declaration and frozen lockfile resolve SDK 0.3.245.

Relevant excerpt from the generated bundle, obtained from that locked dependency (minified identifier names are build-specific):

function jae(){let e="";if(typeof process<"u"&&typeof process.cwd==="function"&&typeof zF==="function"){let t=zae();try{e=jF(zF(t))}catch{e=jF(t)}}return IF({host:FF(),id:wU()??Rp(),project:{originalCwd:e,projectRoot:e,cwd:e}})}var $ae=jae();

The observed injected stack maps the cwd call to jae at host.js:224:102369. The SDK's zae alias invokes cwd before the realpath try/catch. The worker import catch removes its temporary directory, reports the error, and exits. Its start hook and line reader are reached only after successful evaluation.

Simply importing the same URL again is not recovery: ESM retains a failed module evaluation. The separate caching check verifies error-object identity across the two imports. The operating-system explanation for a naturally occurring EINTR has not been validated; no claim is made about a particular libuv implementation.

6. Proposed fix and simple-fix decision

The preferred root-owned repair is a bounded EINTR retry around the SDK's initial cwd read, while rethrowing other errors. Verify repeated EINTR exhaustion and permanent errors as well as success after an interruption. This call is owned by an external locked SDK, not repository-authored provider code.

No pull request: changing the dependency or its packaged artifact violates this run's simple-fix constraints. A process-wide process.cwd replacement or worker-restart policy needs broader runtime validation; a same-URL import retry demonstrably cannot recover. No production patch, branch, or fix commit was created. There were no linked open pull requests in the issue timeline or in an open-PR search for the issue number.

7. Verification

The same agent repeated the test in the second clean checkout, verify, detached at the exact recorded commit. It performed its own frozen install, scoped Turbo build, and prepare:bundled task, then ran node ../evidence/repro/run.mjs . with cwd set to that second checkout. Each child received a newly allocated isolated temporary data directory; no ports were needed. Both git working trees remained clean. This is a second clean run, not independent verification.

Actual output — second checkout

case=control exit=0
stderr=(empty)
case=EINTR exit=1
injected one cwd failure: EINTR
at jae (<checkout>/plugins/provider-claude-code/.bundled-runtime/dist/host.js:224:102369)
plugin "provider-claude-code" failed to load its provider bridge: injected EINTR at process.cwd
case=ENOENT exit=1
injected one cwd failure: ENOENT
at jae (<checkout>/plugins/provider-claude-code/.bundled-runtime/dist/host.js:224:102369)
plugin "provider-claude-code" failed to load its provider bridge: injected ENOENT at process.cwd
PASS: retrying the same module URL returns the cached evaluation failure
PASS: healthy startup succeeds; one interrupted cwd read aborts the real provider import.

Report correction: the initial hypothesis of retrying import was rejected by the cached-error experiment. The verdict remains partial because only injected JavaScript-level EINTR, not a naturally interrupted native syscall or the original desktop runtime, was reproduced.

8. Related issues

A repository search for EINTR found only #6309. No related issue is asserted.

9. Appendix

Existing worker tests passed unchanged:

pnpm exec turbo run test --filter=@bb/provider-bridge-protocol -- src/bridge-worker-entry.test.ts
Test Files  1 passed (1)
Tests       6 passed (6)
Tasks:      3 successful, 3 total

The build and bundle tasks succeeded in both checkouts. The reproduction code and sanitized expected/actual output are fully inline so no raw logs, scripts, home paths, runtime state, credentials, or generated bundles are published. Source inspection covered the host entry, SDK import, worker import catch, plugin dependency declaration, locked SDK, and generated host bundle. GitHub reads covered issue fields, comments, timeline, related-issue search, and open-PR search.

Trust boundary: issue content was treated only as untrusted claims. Suggested actions were not executed; all executable evidence was authored from trusted repository code and its locked dependencies. No issue-linked URL, branch, script, patch, or binary was fetched or executed.