#6444 · Inherited agent-directory environment survives bridge startup
Verdict: NOT REPRODUCED · Root-cause confidence: high for the environment-inheritance mechanism.
1. TL;DR
The issue infers that an agent-directory setting disappears because it is absent from the provider registry's environment object. That object contains only explicit overrides, not the complete environment of the spawned process. The process manager first copies the sanitized daemon environment, and the sanitizer retains PI_CODING_AGENT_DIR. A real bridge worker received a synthetic directory value without adding it to the Pi declaration. Both the configured case and the unset control passed in two separate clean checkouts; no authenticated Pi session was started.
2. Claims vs findings
| Claim | Finding | Evidence |
|---|---|---|
| The Pi declaration does not list the directory variable. | Verified | The trusted declaration lists only two BB-prefixed bridge overrides; the test reads the real declaration. |
| The registry adapter's process env lacks the directory value. | Verified | Both test cases assert that the adapter overlay omits this key. |
| Therefore the bridge process cannot receive the daemon value. | Refuted at the real spawn boundary | The spawned worker writes its actual environment value to a temporary file, and the configured case matches exactly. |
| The sanitizer does not remove this non-BB variable. | Verified, but supports inheritance rather than loss | The process manager merges this sanitized inherited environment before the adapter overlay. |
| Pi's final agent-directory behavior fails in a running deployment. | Unverified | No live Pi session or enrolled daemon was used. This report isolates the proposed declaration-to-child failure. |
3. Environment
- Public repository:
get-bb/bb; freshly fetched main matched the reported base commit above. - Linux
4.19.0-gvisor, Nodev22.19.0, pnpm9.15.0, Vitest4.1.1. - Two separate detached temporary worktrees at the same trusted commit, each with its own frozen dependency install.
- Actual runtime process manager, actual bridge worker, actual Pi declaration, trusted scripted-echo provider fixture. The fixture avoids authentication and model traffic; it is not the real Pi agent.
- No HTTP server or ports. Every test creates fresh workspace and bridge-data directories under the OS temporary directory, then shuts down its worker and deletes its data.
4. Minimal reproduction
- In a clean clone of the public repository, check out the recorded trusted base and install dependencies:
git checkout --detach f8c0701e94ba74a09bf48b1dcc4f49aa22ce81b7 pnpm install --frozen-lockfile --prefer-offline pnpm exec turbo run build build:types --filter=@get-bb/plugin-sdk
- Save the inline test as
packages/agent-runtime/src/issue-6444.repro.test.ts. - Run the real worker observation through the repository's test orchestration:
pnpm exec turbo run test --force --filter=@bb/agent-runtime -- src/issue-6444.repro.test.ts
Expected for correct inheritance: the registry overlay is missing the key, but the child has the configured directory. With the variable unset, the child reports null. Actual: both assertions pass. Thus the registry-only observation is real, but does not establish the reported failure.
First checkout:
✓ |@bb/agent-runtime:isolated| src/issue-6444.repro.test.ts (2 tests) 893ms
Test Files 1 passed (1)
Tests 2 passed (2)
Second checkout (cache bypassed):
✓ |@bb/agent-runtime:isolated| src/issue-6444.repro.test.ts (2 tests) 887ms
Test Files 1 passed (1)
Tests 2 passed (2)
The output excerpts above are verbatim apart from removing the test runner's repeated package prefix and leading whitespace. Raw logs and a standalone copy of the test are retained locally, not published, in accordance with this reports repository's policy. No production source is modified.
Complete test source
import { mkdtempSync, readFileSync, rmSync } from "node:fs";
import { tmpdir } from "node:os";
import { join } from "node:path";
import { afterEach, expect, it, vi } from "vitest";
import {
parseJsonRpcLine,
settleJsonRpcResponse,
} from "@bb/provider-bridge-protocol/bridge-kit";
import { piProviderDeclaration } from "../../../plugins/provider-pi/src/declaration.js";
import { createProviderForId } from "./provider-registry.js";
import { RuntimeProviderProcessManager } from "./runtime-provider-process.js";
import { RuntimeThreadIdentityRegistry } from "./runtime-thread-identity.js";
import { createScriptedEchoLaunch } from "./test/runtime-test-harness.js";
afterEach(() => vi.unstubAllEnvs());
it.each(["configured", "unset"])(
"observes the daemon environment inside a real bridge worker (%s)",
async (mode) => {
const workspacePath = mkdtempSync(join(tmpdir(), "bb-6444-worker-"));
const configuredDir = join(workspacePath, "agent-home");
const outputPath = join(workspacePath, "observed.json");
const expectedValue = mode === "configured" ? configuredDir : undefined;
vi.stubEnv("PI_CODING_AGENT_DIR", expectedValue);
const declaration = piProviderDeclaration();
const bridgeLaunch = {
...createScriptedEchoLaunch(),
envPassthrough: declaration.env?.passthrough ?? [],
};
const adapter = createProviderForId("pi", {
additionalWorkspaceWriteRoots: [],
bridgeNodeExecutablePath: process.execPath,
bridgeLaunch,
});
expect(bridgeLaunch.envPassthrough).not.toContain("PI_CODING_AGENT_DIR");
expect(adapter.process.env?.PI_CODING_AGENT_DIR).toBeUndefined();
const probe = [
'import { writeFileSync } from "node:fs";',
`writeFileSync(${JSON.stringify(outputPath)}, JSON.stringify({`,
"agentDir: process.env.PI_CODING_AGENT_DIR ?? null",
"}));",
].join("\n");
const processAdapter = {
...adapter,
process: {
...adapter.process,
args: [
"--import",
`data:text/javascript,${encodeURIComponent(probe)}`,
...adapter.process.args,
],
},
};
const identities = new RuntimeThreadIdentityRegistry();
let nextRequestId = 1;
const manager = new RuntimeProviderProcessManager({
additionalWorkspaceWriteRoots: [],
bridgeBundleDir: undefined,
createAdapter: () => processAdapter,
captureThreadExitState: (threadId) => ({
activeTurnId: null,
pendingTurnStart: false,
providerThreadId: null,
threadId,
}),
createProviderIdentityState: (providerId) =>
identities.createProviderState({ providerId }),
env: undefined,
getNextRequestId: () => nextRequestId++,
handleDeferredEvents: () => {},
handleStdoutLine: ({ line, providerProcess }) => {
const parsed = parseJsonRpcLine(line);
if (parsed.kind === "response") {
settleJsonRpcResponse({
id: parsed.parsedId,
pending: providerProcess.pending,
response: parsed.parsed,
});
}
},
onProcessExit: undefined,
onProviderThreadDetached: (threadId) => identities.clearThread(threadId),
onStderr: undefined,
skillRoots: [],
workspacePath,
});
try {
await manager.ensureProvider({
bridgeLaunch,
processKey: "issue-6444",
providerId: "pi",
});
expect(JSON.parse(readFileSync(outputPath, "utf8"))).toEqual({
agentDir: expectedValue ?? null,
});
console.log(
`${mode}: adapter overlay absent; child agent directory ${expectedValue === undefined ? "absent" : "matches daemon value"}`,
);
} finally {
await manager.shutdown();
rmSync(bridgeLaunch.dataDir, { recursive: true, force: true });
rmSync(workspacePath, { recursive: true, force: true });
}
},
);
5. Root cause of the misleading reproduction
The real Pi declaration omits the directory variable, and the server registration forwards that declared list. The registry picks those keys into the adapter's environment overlay. This much agrees with the issue's intermediate observation.
The missing step is the actual process spawn:
const env: NodeJS.ProcessEnv = {
...sanitizeInheritedChildProcessEnv({ env: process.env }),
...this.args.env,
...processConfig.env,
};
const managed = spawnManagedProcess({
command: processConfig.command,
args: processConfig.args,
cwd: this.args.workspacePath,
env,
});
The sanitizer removes NODE_ENV and BB_* values, not this PI_* setting. An absent property in a later object spread does not erase a property already inherited from the daemon. BB-prefixed bridge command overrides need explicit passthrough because they are sanitized; the non-BB agent-directory variable does not. There is no confirmed production root cause for a missing child value on this trusted base.
6. Proposed fix / next experiment
No production change is justified for the stated inheritance failure. If a real Pi deployment still uses the wrong directory, first verify that the actual daemon process was launched with the intended value, then inspect Pi's own directory handling in an isolated session. Merely exporting a value in a different shell does not alter an already-running daemon. That is a next diagnostic step, not an observed cause in this issue.
7. Linked PR review
PR #6445 — static diff only
The open PR adds the non-BB variable to the Pi declaration and updates the existing exact-list assertion in plugins/provider-pi/server.test.ts:17. Its branch was not checked out or executed. Medium finding: that assertion checks declaration data rather than the child process, so its pre-fix failure does not prove a delivery failure. The added declaration is redundant for the specific inherited-daemon scenario verified here. No other PR behavior is claimed to have been tested.
Verdict: unnecessary for the reported inheritance mechanism; a real daemon/Pi failure would need additional evidence. No duplicate PR was created.
8. Related issues
Repository search also found #5092 (environment path expansion) and #3925 (project-scoped provider configuration for skill discovery). These describe different mechanisms, not verified duplicates.
9. Verification
The same agent repeated the experiment in a second separate temporary worktree initially clean at the full trusted commit. It received its own frozen install, SDK build, temporary workspaces, and bridge-data directories. The exact test artifact was copied there and executed with Turbo --force; the second run reports Cached: 0 cached, 7 total, so it did not reuse the first run's result. Both configured and unset observations passed again. This is a second clean run, not independent verification.
Two existing runtime environment tests also passed on trusted main:
pnpm exec turbo run test --filter=@bb/agent-runtime -- src/runtime.process-lifecycle.test.ts -t 'scrubs inherited bb runtime env vars|overlays adapter process env'
✓ |@bb/agent-runtime:isolated| src/runtime.process-lifecycle.test.ts (32 tests | 30 skipped) 88ms
Test Files 1 passed (1)
Tests 2 passed | 30 skipped (32)
Correction to the initial hypothesis: the registry omission is genuine, but treating its env overlay as the final process environment is incorrect. The report verdict reflects the executed spawn path rather than the issue's proposed diagnosis.
10. Appendix / limits
The initial normal pnpm exec turbo run build was attempted in both worktrees. It stopped at plugin builds because SDK dist/process.js and dist/host.js had not yet been built. Explicit pnpm exec turbo run build build:types --filter=@get-bb/plugin-sdk succeeded in each checkout, followed by the focused Turbo test runs above. This report does not claim a successful full-monorepo build.
The worker probe adds a Node preload that writes only the synthetic directory value to a temporary file; it does not replace environment assembly or bypass the initialize handshake. The provider implementation is the repository's scripted-echo fixture. Authenticated Pi behavior, daemon service-manager configuration, and existing user data were not inspected.
Issue content and the PR diff were treated as untrusted hypotheses; no supplied command, patch, branch, or reproduction test was executed. Only trusted main and the locally authored test were run.