#5292 · Removed machine PATH masks shell refresh
Verdict: PARTIALLY REPRODUCED · Root-cause confidence: high for the deterministic refresh-masking defect.
TL;DR
A failed shell probe can leave child processes unable to find an installed executable. The probe is not strictly one-shot: main already retries on later requests after a ten-second cache TTL. However, after a machine PATH override has been applied and removed, the environment overlay repeatedly reinstates the original startup PATH, even when a later shell probe succeeds. That persistent failure is reproduced twice with real child processes and unmodified production code. Native macOS launchd timing and real provider behavior were not reproduced in this Linux environment.
Claims versus findings
| Claim tested | Finding | Evidence |
|---|---|---|
| Both failed probes can yield only the inherited PATH. | Verified at the production helper boundary. | Controlled-shell timeout case returns null; a real executable lookup fails with ENOENT. |
| A successful plain-login fallback can omit interactive tool directories. | Verified with a controlled shell; native zsh configuration remains unverified. | The fallback returns the inherited PATH and cannot locate the synthetic tool. |
| Recovery necessarily requires daemon restart because the probe runs only once. | Refuted on trusted main as a general claim. | A second call to the same resolver finds the tool without restarting. App request paths use a refresh cache with a ten-second TTL. |
| Removing a managed PATH exposes a bad startup capture. | Verified, including a stronger persistent failure. | After a successful refresh, the MachineEnvironment overlay still supplies the old capture; the child fails with ENOENT. |
| Default 3-second probes frequently fail under macOS login load. | Unverified. | No macOS host, launchd service, native zsh, or real provider processes were used. |
Environment and trusted base
Repository visibility: public. Both runs use 1ae755fce6bba411f471f0c3dc0b93a6603f1ba0 from trusted origin/main. Environment: Linux, Node v22.19.0, pnpm 9.15.0, Vitest 4.1.1. Provider: a newly authored harmless executable named qa-provider in a new temporary tool directory. No dependency was added.
The controlled shell is an executable test fixture, not a native macOS login shell. It sleeps for three seconds on selected startup modes; the existing resolver timeout override is set to 100 ms to make the race deterministic and fast. No spawn implementation is mocked. Each case allocates a separate temporary directory and removes it afterward. No service or server is started: there are no ports or persistent data directories in use. The inert loopback URL passed to environment preparation is not contacted.
Minimal reproduction
- Clone the public target repository and detach at the recorded commit.
- Perform a frozen install and the normal Turbo build.
- Save the complete inline test to the indicated source path.
- Run the focused Turbo test command. Exit code 1 is expected evidence of the defect, not a passing regression suite.
git clone https://github.com/get-bb/bb.git bb-path-qa cd bb-path-qa git checkout --detach 1ae755fce6bba411f471f0c3dc0b93a6603f1ba0 pnpm install --frozen-lockfile --prefer-offline pnpm exec turbo run build # Save the inline test as apps/host-daemon/src/runtime-shell-path-repro.test.ts pnpm exec turbo run test --filter=@bb/host-daemon -- src/runtime-shell-path-repro.test.ts
The complete reproduction test appears inline. It was written from repository evidence, not copied from issue code or a linked pull request. Raw evidence is retained locally rather than published as repository scripts or logs.
Expected: after a successful refresh and removal of a managed PATH, the child receives the refreshed shell PATH and prints ready with status 0.
Actual: the fresh shell alone successfully launches the child; applying the machine environment overlay changes its PATH back to the startup capture, yielding spawnSync qa-provider ENOENT. The final assertion fails in each checkout. Three control tests pass: total probe failure, incomplete plain-login fallback, and recovery by a later resolver call.
Full reproduction test
import { spawnSync } from "node:child_process";
import fs from "node:fs/promises";
import os from "node:os";
import path from "node:path";
import { afterEach, expect, it } from "vitest";
import { MachineEnvironment } from "./machine-environment.js";
import {
createUserShellPathResolver,
prepareRuntimeShellEnv,
} from "./runtime-shell-env.js";
const directories: string[] = [];
const inheritedPath = "/usr/bin:/bin";
afterEach(async () => {
await Promise.all(
directories
.splice(0)
.map((directory) => fs.rm(directory, { recursive: true, force: true })),
);
});
async function fixture(failAll: boolean) {
const directory = await fs.mkdtemp(path.join(os.tmpdir(), "bb-path-repro-"));
directories.push(directory);
const tools = path.join(directory, "tools");
const shell = path.join(directory, "controlled-shell");
const slow = path.join(directory, "slow");
await fs.mkdir(tools);
await fs.writeFile(slow, "slow");
await fs.writeFile(
path.join(tools, "qa-provider"),
"#!/bin/sh\nprintf 'ready\\n'\n",
{ mode: 0o755 },
);
await fs.writeFile(
shell,
[
"#!/bin/sh",
'if [ -f "$QA_SLOW" ] && { [ "$1" = "-ilc" ] || [ "$QA_FAIL_ALL" = "yes" ]; }; then',
" exec /bin/sleep 3",
"fi",
'if [ "$1" = "-ilc" ]; then',
' PATH="$QA_TOOLS:/usr/bin:/bin"',
" export PATH",
"fi",
'exec /bin/sh -c "$2"',
"",
].join("\n"),
{ mode: 0o755 },
);
const env = {
PATH: inheritedPath,
SHELL: shell,
QA_TOOLS: tools,
QA_SLOW: slow,
QA_FAIL_ALL: failAll ? "yes" : "no",
};
const resolvePath = createUserShellPathResolver({
env,
platform: "linux",
timeoutMs: 100,
});
const runtimeEnv = (resolvedPath: string | null) =>
prepareRuntimeShellEnv({
bbExecutableDirectory: path.join(directory, "bb-bin"),
inheritedPath: resolvedPath ?? inheritedPath,
serverUrl: "http://127.0.0.1:49999",
});
const provider = (shellEnv: Record<string, string>) =>
spawnSync("qa-provider", [], {
env: shellEnv,
encoding: "utf8",
});
return { env, slow, tools, resolvePath, runtimeEnv, provider };
}
it("cannot discover a child executable when both startup probes time out", async () => {
const setup = await fixture(true);
const resolved = await setup.resolvePath();
expect(resolved).toBeNull();
const result = setup.provider(setup.runtimeEnv(resolved));
expect(result.error).toMatchObject({ code: "ENOENT" });
});
it("accepts a successful plain-login probe that omits interactive tools", async () => {
const setup = await fixture(false);
const resolved = await setup.resolvePath();
expect(resolved).toBe(inheritedPath);
expect(setup.provider(setup.runtimeEnv(resolved)).error).toMatchObject({
code: "ENOENT",
});
});
it("recovers on a later probe without restarting the resolver", async () => {
const setup = await fixture(true);
expect(await setup.resolvePath()).toBeNull();
await fs.rm(setup.slow);
const resolved = await setup.resolvePath();
expect(resolved).toBe(`${setup.tools}:${inheritedPath}`);
const result = setup.provider(setup.runtimeEnv(resolved));
expect(result.status).toBe(0);
expect(result.stdout).toBe("ready\n");
});
it("discovers tools from a refreshed shell after a managed PATH is removed", async () => {
const setup = await fixture(true);
const originalShell = setup.runtimeEnv(await setup.resolvePath());
const machine = new MachineEnvironment({ ...setup.env }, originalShell);
const workingPath = `${setup.tools}:${inheritedPath}`;
machine.replace([
{
name: "PATH",
value: workingPath,
source: { core: "machine-environment" },
reason: "qa",
},
]);
expect(setup.provider(machine.shellEnvironment(originalShell)).status).toBe(
0,
);
machine.replace([]);
expect(
setup.provider(machine.shellEnvironment(originalShell)).error,
).toMatchObject({ code: "ENOENT" });
await fs.rm(setup.slow);
const refreshedShell = setup.runtimeEnv(await setup.resolvePath());
expect(setup.provider(refreshedShell).status).toBe(0);
const result = setup.provider(machine.shellEnvironment(refreshedShell));
expect(
result.error,
"the refreshed PATH must reach the provider child",
).toBeUndefined();
expect(result.status).toBe(0);
expect(result.stdout).toBe("ready\n");
});
Root cause
The default timeout is 3,000 ms. The argument selection tries interactive login mode before plain login mode. The resolver returns the first parsed successful PATH, returns null when no probe succeeds, and retains a prior success when the next interactive probe fails. Startup environment assembly substitutes the process PATH when probing returns null.
The persistent defect is the MachineEnvironment snapshot combined with its overlay algorithm:
this.originalShell = { ...shell };
...
this.managed.add(entry.name);
...
const result = { ...shell };
for (const name of this.managed) {
const value = this.values[name] ?? this.originalShell[name];
if (value === undefined) delete result[name];
else result[name] = value;
}
The managed-name set remembers PATH after settings remove it. With no active value, every subsequent overlay overwrites the current supplied PATH with originalShell.PATH. A later successful probe cannot escape that fallback. In app construction, originalShell comes from startup runtimeShellEnv. RuntimeManager applies the overlay when resolving shell environment values, while refresh replaces its base shell environment separately. This explains why a good refreshed base can coexist with a bad effective provider PATH.
Important correction: the app TTL is ten seconds, and the refresh cache integration permits a later request to re-probe. The cache refresh algorithm does not permanently retain a failed startup resolution. It is request-triggered rather than an unconditional periodic background timer.
Verification
The same agent repeated the reproduction in a second freshly cloned checkout, detached at the same trusted base. Its git status was clean before adding only the reproduction test. A fresh frozen install and pnpm exec turbo run build --filter=@bb/host-daemon succeeded. No first-run mutable data, shell processes, or temporary test directories were reused.
Command in each checkout: pnpm exec turbo run test --filter=@bb/host-daemon -- src/runtime-shell-path-repro.test.ts. Result in both: exit 1, exactly three controls passed and the refreshed-PATH regression failed with ENOENT. This is a same-agent repeat, not independent verification. The report corrects the one-shot-only claim and limits its verdict to controlled process behavior rather than native macOS reproduction.
Existing focused suites also pass: runtime-shell-env.test.ts, runtime-shell-env-cache.test.ts, and machine-environment.test.ts, 33 tests total. Two existing app tests covering model-list refresh and immediate reuse of startup environment also pass (15 unrelated tests skipped by the filter). The original shell-overlay test explicitly expects startup-snapshot restoration, so changing that restoration contract deserves a deliberate decision rather than an incidental timeout adjustment.
Fix proposal and safety gate
Distinguish a degraded startup fallback from a healthy shell capture; specify the retry budget and which shell environment removing a managed override should restore. A healthy refreshed base must not be masked by an obsolete capture if the chosen contract is to track current login-shell state. Then add a native macOS check covering real interactive startup configuration and launchd boot load.
No pull request is opened: repairing the complete startup/fallback behavior and changing removed-variable restoration semantics needs a maintainer policy decision, failing the no-product-decision simple-fix gate. Native macOS behavior is not yet verified. GitHub metadata and open-PR search found no open pull request linked to #5292 at investigation time. No production fix, branch, or push was attempted in the target repository.
Related issues and trust boundary
Repository search found #2343 and #4417 as neighboring PATH reports; neither establishes this reproduction's root cause. Issue text was treated solely as untrusted claims. No linked external page, command, patch, provider binary, or pull-request branch from issue data was fetched or executed. All executable repository code came from trusted origin/main, plus the newly authored controlled reproduction.
Appendix: exact results
Initial full build: 64 successful Turbo tasks. Second checkout host build: succeeded. Exact test results appear inline. Checkout paths in saved output are normalized for publication; assertions, ENOENT, counts, and exit status are unchanged.
First reproduction output
@bb/host-daemon:test: RUN v4.1.1 [first-checkout]/apps/host-daemon
@bb/host-daemon:test:
@bb/host-daemon:test: ❯ |@bb/host-daemon| src/runtime-shell-path-repro.test.ts (4 tests | 1 failed) 799ms
@bb/host-daemon:test: ✓ cannot discover a child executable when both startup probes time out 220ms
@bb/host-daemon:test: ✓ accepts a successful plain-login probe that omits interactive tools 116ms
@bb/host-daemon:test: ✓ recovers on a later probe without restarting the resolver 224ms
@bb/host-daemon:test: × discovers tools from a refreshed shell after a managed PATH is removed 238ms
@bb/host-daemon:test:
@bb/host-daemon:test: ⎯⎯⎯⎯⎯⎯⎯ Failed Tests 1 ⎯⎯⎯⎯⎯⎯⎯
@bb/host-daemon:test:
@bb/host-daemon:test: FAIL |@bb/host-daemon| src/runtime-shell-path-repro.test.ts > discovers tools from a refreshed shell after a managed PATH is removed
@bb/host-daemon:test: AssertionError: the refreshed PATH must reach the provider child: expected Error: spawnSync qa-provider ENOENT { …(5) } to be undefined
@bb/host-daemon:test:
@bb/host-daemon:test: - Expected:
@bb/host-daemon:test: undefined
@bb/host-daemon:test:
@bb/host-daemon:test: + Received:
@bb/host-daemon:test: Error {
@bb/host-daemon:test: "message": "spawnSync qa-provider ENOENT",
@bb/host-daemon:test: "errno": -2,
@bb/host-daemon:test: "code": "ENOENT",
@bb/host-daemon:test: "syscall": "spawnSync qa-provider",
@bb/host-daemon:test: "path": "qa-provider",
@bb/host-daemon:test: "spawnargs": [],
@bb/host-daemon:test: }
@bb/host-daemon:test:
@bb/host-daemon:test: ❯ src/runtime-shell-path-repro.test.ts:133:5
@bb/host-daemon:test: 131| result.error,
@bb/host-daemon:test: 132| "the refreshed PATH must reach the provider child",
@bb/host-daemon:test: 133| ).toBeUndefined();
@bb/host-daemon:test: | ^
@bb/host-daemon:test: 134| expect(result.status).toBe(0);
@bb/host-daemon:test: 135| expect(result.stdout).toBe("ready\n");
@bb/host-daemon:test:
@bb/host-daemon:test: ⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯[1/1]⎯
@bb/host-daemon:test:
@bb/host-daemon:test:
@bb/host-daemon:test: Test Files 1 failed (1)
@bb/host-daemon:test: Tests 1 failed | 3 passed (4)
@bb/host-daemon:test: Start at 22:12:41
@bb/host-daemon:test: Duration 1.22s (transform 129ms, setup 0ms, import 227ms, tests 799ms, environment 0ms)
@bb/host-daemon:test:
@bb/host-daemon:test: ELIFECYCLE Test failed. See above for more details.
@bb/host-daemon#test: ERROR command ([first-checkout]/apps/host-daemon) /usr/local/bin/pnpm run test src/runtime-shell-path-repro.test.ts exited (1)
Tasks: 5 successful, 6 total
Cached: 0 cached, 6 total
Time: 3.637s
Failed: @bb/host-daemon#test
ERROR run failed: command exited (1)
Second clean reproduction output
@bb/host-daemon:test: RUN v4.1.1 [second-checkout]/apps/host-daemon
@bb/host-daemon:test:
@bb/host-daemon:test: ❯ |@bb/host-daemon| src/runtime-shell-path-repro.test.ts (4 tests | 1 failed) 801ms
@bb/host-daemon:test: ✓ cannot discover a child executable when both startup probes time out 221ms
@bb/host-daemon:test: ✓ accepts a successful plain-login probe that omits interactive tools 118ms
@bb/host-daemon:test: ✓ recovers on a later probe without restarting the resolver 223ms
@bb/host-daemon:test: × discovers tools from a refreshed shell after a managed PATH is removed 238ms
@bb/host-daemon:test:
@bb/host-daemon:test: ⎯⎯⎯⎯⎯⎯⎯ Failed Tests 1 ⎯⎯⎯⎯⎯⎯⎯
@bb/host-daemon:test:
@bb/host-daemon:test: FAIL |@bb/host-daemon| src/runtime-shell-path-repro.test.ts > discovers tools from a refreshed shell after a managed PATH is removed
@bb/host-daemon:test: AssertionError: the refreshed PATH must reach the provider child: expected Error: spawnSync qa-provider ENOENT { …(5) } to be undefined
@bb/host-daemon:test:
@bb/host-daemon:test: - Expected:
@bb/host-daemon:test: undefined
@bb/host-daemon:test:
@bb/host-daemon:test: + Received:
@bb/host-daemon:test: Error {
@bb/host-daemon:test: "message": "spawnSync qa-provider ENOENT",
@bb/host-daemon:test: "errno": -2,
@bb/host-daemon:test: "code": "ENOENT",
@bb/host-daemon:test: "syscall": "spawnSync qa-provider",
@bb/host-daemon:test: "path": "qa-provider",
@bb/host-daemon:test: "spawnargs": [],
@bb/host-daemon:test: }
@bb/host-daemon:test:
@bb/host-daemon:test: ❯ src/runtime-shell-path-repro.test.ts:133:5
@bb/host-daemon:test: 131| result.error,
@bb/host-daemon:test: 132| "the refreshed PATH must reach the provider child",
@bb/host-daemon:test: 133| ).toBeUndefined();
@bb/host-daemon:test: | ^
@bb/host-daemon:test: 134| expect(result.status).toBe(0);
@bb/host-daemon:test: 135| expect(result.stdout).toBe("ready\n");
@bb/host-daemon:test:
@bb/host-daemon:test: ⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯[1/1]⎯
@bb/host-daemon:test:
@bb/host-daemon:test:
@bb/host-daemon:test: Test Files 1 failed (1)
@bb/host-daemon:test: Tests 1 failed | 3 passed (4)
@bb/host-daemon:test: Start at 22:13:41
@bb/host-daemon:test: Duration 1.22s (transform 129ms, setup 0ms, import 227ms, tests 801ms, environment 0ms)
@bb/host-daemon:test:
@bb/host-daemon:test: ELIFECYCLE Test failed. See above for more details.
@bb/host-daemon#test: ERROR command ([second-checkout]/apps/host-daemon) /usr/local/bin/pnpm run test src/runtime-shell-path-repro.test.ts exited (1)
Tasks: 5 successful, 6 total
Cached: 0 cached, 6 total
Time: 3.649s
Failed: @bb/host-daemon#test
ERROR run failed: command exited (1)
Existing tests output
@bb/host-daemon:test: RUN v4.1.1 [first-checkout]/apps/host-daemon @bb/host-daemon:test: @bb/host-daemon:test: ✓ |@bb/host-daemon:isolated| src/runtime-shell-env.test.ts (24 tests) 49ms @bb/host-daemon:test: ✓ |@bb/host-daemon| src/machine-environment.test.ts (2 tests) 132ms @bb/host-daemon:test: ✓ |@bb/host-daemon| src/runtime-shell-env-cache.test.ts (7 tests) 10ms @bb/host-daemon:test: @bb/host-daemon:test: Test Files 3 passed (3) @bb/host-daemon:test: Tests 33 passed (33) @bb/host-daemon:test: Start at 22:13:33 @bb/host-daemon:test: Duration 1.24s (transform 954ms, setup 0ms, import 1.52s, tests 192ms, environment 0ms) @bb/host-daemon:test: Tasks: 6 successful, 6 total Cached: 0 cached, 6 total Time: 3.752s
App refresh tests output
@bb/host-daemon:test: RUN v4.1.1 [first-checkout]/apps/host-daemon @bb/host-daemon:test: @bb/host-daemon:test: ✓ |@bb/host-daemon:isolated| src/app.test.ts (17 tests | 15 skipped) 44ms @bb/host-daemon:test: @bb/host-daemon:test: Test Files 1 passed (1) @bb/host-daemon:test: Tests 2 passed | 15 skipped (17) @bb/host-daemon:test: Start at 22:15:39 @bb/host-daemon:test: Duration 2.58s (transform 1.71s, setup 0ms, import 2.34s, tests 44ms, environment 0ms) @bb/host-daemon:test: Tasks: 6 successful, 6 total Cached: 0 cached, 6 total Time: 5.082s
pnpm exec turbo run test --filter=@bb/host-daemon -- src/runtime-shell-env.test.ts src/runtime-shell-env-cache.test.ts src/machine-environment.test.ts
pnpm exec turbo run test --filter=@bb/host-daemon -- src/app.test.ts -t 'refreshes.*model|reuses freshly resolved startup shell env'
Reproduction label: partial-repro.
> AGENT GENERATED