#4960 · Session identity is missing from the provider child environment
Verdict: REPRODUCED · Root-cause confidence: high
1. TL;DR
A provider-launched tool cannot obtain the serving thread's identity from its parent process when that identity never reaches the parent. The Codex bridge accepts a session environment and sends its four thread-context values in shell configuration, but omits them from the environment of the app-server subprocess. A reproduction using the real bridge and a real spawned Node subprocess observed an empty identity object, while all four values were present in the shell-policy request. The same failure occurred in a second clean checkout. This verifies BB's process-boundary defect; upstream Codex MCP environment forwarding was not exercised.
2. Claims vs findings
| Claim | Status | Evidence |
|---|---|---|
| Session thread context is available to shell configuration but not the app-server process. | Verified | Real bridge thread/start request carries all four synthetic shell-policy values; actual subprocess captures none. |
| Inherited BB runtime values are stripped before launching the provider. | Verified | Four synthetic inherited identity values and an unrelated synthetic BB control variable are absent from the spawned child. |
| Thread-free app-servers should remain free of thread identity. | Verified for model listing | The model/list control successfully starts its subprocess without inherited identity. Maintenance source uses the same launch helper; its complete runtime environment was not separately captured. |
| An upstream MCP configuration can forward identity only if the app-server has it. | Downstream behavior not exercised | No upstream Codex binary, live MCP server, or account was used. The confirmed BB-side loss occurs before any downstream inheritance could happen. |
| A linked prototype fixes the issue. | Not evaluated | No external prototype, branch, patch, or linked code was fetched or executed. |
3. Environment
- Public repository:
get-bb/bb, trustedorigin/mainatc5b97d7aa265becdfed89ec837fdc6f20a4f3e06. - Linux 4.19.0-gvisor x86_64; Node v22.19.0; pnpm 9.15.0; Vitest 4.1.1.
- Provider package:
bb-plugin-provider-codexv0.1.0. Endpoint: the trusted repository's existing Node fake app-server fixture, wrapped only to capture five named synthetic variables. No authenticated Codex version applies. - Two separate clean temporary checkouts, with their own frozen installs and successful full Turbo builds. No live BB instance, listening ports, user runtime data, or credentials were used.
- During investigation main advanced to
44578f308fee11b38dfe0fd470158d9e9c03cbc2; its intervening commit changed none of the three root-cause paths checked.
4. Minimal reproduction
- Prepare a trusted checkout and build dependencies:
git clone https://github.com/get-bb/bb.git bb-repro-4960 cd bb-repro-4960 git checkout --detach c5b97d7aa265becdfed89ec837fdc6f20a4f3e06 pnpm install --frozen-lockfile --prefer-offline pnpm exec turbo run build # Save the complete test below to: # plugins/provider-codex/src/bridge/bridge.child-identity.test.ts pnpm exec turbo run test --force --filter=bb-plugin-provider-codex -- src/bridge/bridge.child-identity.test.ts
- Save the complete test below at the specified path and run the final command. It launches the actual provider bridge transport with the existing trusted protocol fixture; neither process spawning nor environment sanitization is mocked.
- Expected: the thread subprocess has the four session-owned context values, not the parent's stale identity; unrelated inherited BB variables remain absent. Actual: the thread subprocess reports
{}. The separate model-list control passes without identity.
Complete repeatable reproduction test
import { mkdtempSync, readFileSync, rmSync, writeFileSync } from "node:fs";
import { tmpdir } from "node:os";
import { join } from "node:path";
import { fileURLToPath } from "node:url";
import { afterEach, beforeEach, expect, it, vi } from "vitest";
import { experimental_createBridgeJsonRpcTestHarness as createHarness } from "@get-bb/plugin-sdk/provider-bridge/testing";
import { z } from "zod";
import { experimental_killAllChildrenForTests, handleLine } from "./bridge.js";
import { FULL_ACCESS_SESSION_OPTIONS } from "./fake-codex-app-server-harness.js";
const threadId = "thr_repro4960";
const identityKeys = [
"BB_THREAD_ID",
"BB_ENVIRONMENT_ID",
"BB_PROJECT_ID",
"BB_THREAD_STORAGE",
];
const identity = {
BB_THREAD_ID: threadId,
BB_ENVIRONMENT_ID: "env_repro4960",
BB_PROJECT_ID: "proj_repro4960",
BB_THREAD_STORAGE: "/tmp/repro4960-thread-storage",
};
let harness: ReturnType<typeof createHarness>;
let directory: string;
let capturePath: string;
let requestPath: string;
beforeEach(() => {
directory = mkdtempSync(join(tmpdir(), "bb-identity-repro-"));
capturePath = join(directory, "identity.json");
requestPath = join(directory, "requests.jsonl");
const scriptPath = join(directory, "script.json");
const wrapperPath = join(directory, "capture-child.mjs");
const fixturePath = fileURLToPath(
new URL("./fake-codex-app-server.mjs", import.meta.url),
);
writeFileSync(scriptPath, JSON.stringify({ requestLogPath: requestPath }));
writeFileSync(
wrapperPath,
[
'import { writeFileSync } from "node:fs";',
'import { pathToFileURL } from "node:url";',
"const [fixturePath, scriptPath, capturePath] = process.argv.slice(2);",
`const keys = ${JSON.stringify([...identityKeys, "BB_REPRO_CONTROL"])};`,
"writeFileSync(capturePath, JSON.stringify(Object.fromEntries(keys.flatMap((key) => process.env[key] === undefined ? [] : [[key, process.env[key]]]))));",
"process.argv = [process.execPath, fixturePath, scriptPath];",
"await import(pathToFileURL(fixturePath).href);",
].join("\n"),
);
for (const key of identityKeys) {
vi.stubEnv(key, "synthetic-parent-identity");
}
vi.stubEnv("BB_REPRO_CONTROL", "synthetic-parent-control");
vi.stubEnv("BB_CODEX_BRIDGE_APP_SERVER_COMMAND", process.execPath);
vi.stubEnv(
"BB_CODEX_BRIDGE_APP_SERVER_ARGS",
JSON.stringify([wrapperPath, fixturePath, scriptPath, capturePath]),
);
harness = createHarness(handleLine);
});
afterEach(async () => {
harness.sendRequest(900, "thread/stop", {
threadId,
providerThreadId: "repro-cleanup",
intent: "release",
activeTurnId: null,
});
await harness.waitForResponse(900).catch(() => undefined);
experimental_killAllChildrenForTests();
harness.restore();
vi.unstubAllEnvs();
rmSync(directory, { recursive: true, force: true });
});
function capturedIdentity(): Record<string, string> {
return z
.record(z.string(), z.string())
.parse(JSON.parse(readFileSync(capturePath, "utf8")));
}
it("passes session identity to the thread child while isolating unrelated parent variables", async () => {
harness.sendRequest(1, "thread/start", {
threadId,
cwd: directory,
instructionMode: "append",
options: { ...FULL_ACCESS_SESSION_OPTIONS, envVars: identity },
});
const response = await harness.waitForResponse(1);
expect(response.error).toBeUndefined();
const requests = readFileSync(requestPath, "utf8")
.trim()
.split("\n")
.map((line) =>
z
.object({
method: z.string(),
params: z.looseObject({
config: z.record(z.string(), z.unknown()).optional(),
}),
})
.parse(JSON.parse(line)),
);
const construction = requests.find(
(request) => request.method === "thread/start",
);
for (const [key, value] of Object.entries(identity)) {
expect(
construction?.params.config?.[`shell_environment_policy.set.${key}`],
).toBe(value);
}
const captured = capturedIdentity();
expect(captured.BB_REPRO_CONTROL).toBeUndefined();
console.log("Synthetic child identity:", JSON.stringify(captured));
console.log("Shell policy carries all four synthetic identity values.");
expect(captured).toEqual(identity);
});
it("keeps model-list children free of inherited thread identity", async () => {
harness.sendRequest(2, "model/list", {});
expect((await harness.waitForResponse(2)).error).toBeUndefined();
expect(capturedIdentity()).toEqual({});
});
Observed first run (exit 1)
bb-plugin-provider-codex:test: stdout | src/bridge/bridge.child-identity.test.ts > passes session identity to the thread child while isolating unrelated parent variables
bb-plugin-provider-codex:test: Synthetic child identity: {}
bb-plugin-provider-codex:test: Shell policy carries all four synthetic identity values.
bb-plugin-provider-codex:test:
bb-plugin-provider-codex:test: ❯ |bb-plugin-provider-codex| src/bridge/bridge.child-identity.test.ts (2 tests | 1 failed) 214ms
bb-plugin-provider-codex:test: × passes session identity to the thread child while isolating unrelated parent variables 124ms
bb-plugin-provider-codex:test: ✓ keeps model-list children free of inherited thread identity 89ms
bb-plugin-provider-codex:test:
bb-plugin-provider-codex:test: ⎯⎯⎯⎯⎯⎯⎯ Failed Tests 1 ⎯⎯⎯⎯⎯⎯⎯
bb-plugin-provider-codex:test:
bb-plugin-provider-codex:test: FAIL |bb-plugin-provider-codex| src/bridge/bridge.child-identity.test.ts > passes session identity to the thread child while isolating unrelated parent variables
bb-plugin-provider-codex:test: AssertionError: expected {} to deeply equal { BB_THREAD_ID: 'thr_repro4960', …(3) }
bb-plugin-provider-codex:test:
bb-plugin-provider-codex:test: - Expected
bb-plugin-provider-codex:test: + Received
bb-plugin-provider-codex:test:
bb-plugin-provider-codex:test: - {
bb-plugin-provider-codex:test: - "BB_ENVIRONMENT_ID": "env_repro4960",
bb-plugin-provider-codex:test: - "BB_PROJECT_ID": "proj_repro4960",
bb-plugin-provider-codex:test: - "BB_THREAD_ID": "thr_repro4960",
bb-plugin-provider-codex:test: - "BB_THREAD_STORAGE": "/tmp/repro4960-thread-storage",
bb-plugin-provider-codex:test: - }
bb-plugin-provider-codex:test: + {}
bb-plugin-provider-codex:test:
bb-plugin-provider-codex:test: ❯ src/bridge/bridge.child-identity.test.ts:117:20
bb-plugin-provider-codex:test: 115| console.log("Synthetic child identity:", JSON.stringify(captured));
bb-plugin-provider-codex:test: 116| console.log("Shell policy carries all four synthetic identity values…
bb-plugin-provider-codex:test: 117| expect(captured).toEqual(identity);
bb-plugin-provider-codex:test: | ^
bb-plugin-provider-codex:test: 118| });
bb-plugin-provider-codex:test: 119|
bb-plugin-provider-codex:test:
bb-plugin-provider-codex:test: ⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯[1/1]⎯
bb-plugin-provider-codex:test:
bb-plugin-provider-codex:test:
bb-plugin-provider-codex:test: Test Files 1 failed (1)
bb-plugin-provider-codex:test: Tests 1 failed | 1 passed (2)
The failure is specifically the final child identity comparison. Thread construction, all four shell-policy assertions, and the unrelated-variable isolation assertion pass first. The model-list negative control also passes. This rules out a failure caused merely by a broken fixture, malformed options, or a thread/start protocol error.
5. Root cause
- The runtime constructs session-owned identity in
buildThreadShellEnvironment: thread, environment, and optional project/storage values. appServerLaunchEnvandbuildAppServerEnvuse the parent process environment, overlaying only the account-pool variables from session options. They never overlay session identity. The inherited environment sanitizer then drops every BB-prefixed value.sanitizeInheritedChildProcessEnvintentionally scrubs all inheritedBB_*values andNODE_ENV. Merely merging identity before that sanitizer would still lose it.spawnChildConnectionsupplies the resulting environment to the actual portable subprocess spawn. The separaterecordThreadIdfield is used for recording; it does not export thread identity to the process.buildCodexConfigsupplies identity throughshell_environment_policy.set.*, explaining the passing shell-policy assertions despite the empty parent environment.
function buildAppServerEnv(
envVars: Readonly<Record<string, string>> | undefined,
): NodeJS.ProcessEnv {
return withoutBridgeRuntimeEnv(
sanitizeInheritedChildProcessEnv({
env: appServerLaunchEnv(envVars),
}),
);
}
The deeper distinction is session-owned environment versus inherited daemon/runtime environment. Shell configuration handles the former; the app-server launch path handles only the latter, plus its narrow pool-routing exception.
6. Proposed fix and automation safety
After sanitizing inherited runtime state, a reviewed provider-local change could explicitly restore an agreed allowlist of session-owned identity keys for thread-bound app-servers only. Never copy arbitrary BB-prefixed session or parent variables, never fall back to stale parent identity, and preserve thread-free model/maintenance isolation. Tests should cover absent optional context, unrelated session and inherited variables, and repeated thread launches.
No automatic fix PR: this would expand what the sanitized provider-child environment exposes to downstream tool processes. It changes a process-isolation/security boundary, which the autopilot's simple-fix conditions expressly exclude. No production code was modified, committed, or pushed. Low effort describes the likely implementation size; it is not authorization to bypass this safety gate.
7. Related issues and pull requests
The target issue's cross-reference timeline and open-PR search for its numeric ID contained no linked open pull request at investigation time. A narrow related-issue metadata search did not establish a directly matching duplicate. No external code review was performed.
8. Verification
The same agent repeated the reproduction in a second clean checkout, not an independent reviewer. The second checkout was detached at exactly the recorded trusted base, initially clean, and had a separate frozen install and a successful full Turbo build. Only the locally authored reproduction test was then copied in. New temporary fixture directories and child processes were created by its setup. No ports or BB data directory were needed.
pnpm exec turbo run test --force --filter=bb-plugin-provider-codex -- src/bridge/bridge.child-identity.test.ts Exit: 1 (expected regression failure) Result: 1 failed thread-identity assertion; 1 passed thread-free model-list control.
bb-plugin-provider-codex:test: stdout | src/bridge/bridge.child-identity.test.ts > passes session identity to the thread child while isolating unrelated parent variables
bb-plugin-provider-codex:test: Synthetic child identity: {}
bb-plugin-provider-codex:test: Shell policy carries all four synthetic identity values.
bb-plugin-provider-codex:test:
bb-plugin-provider-codex:test: ❯ |bb-plugin-provider-codex| src/bridge/bridge.child-identity.test.ts (2 tests | 1 failed) 217ms
bb-plugin-provider-codex:test: × passes session identity to the thread child while isolating unrelated parent variables 130ms
bb-plugin-provider-codex:test: ✓ keeps model-list children free of inherited thread identity 86ms
bb-plugin-provider-codex:test:
bb-plugin-provider-codex:test: ⎯⎯⎯⎯⎯⎯⎯ Failed Tests 1 ⎯⎯⎯⎯⎯⎯⎯
bb-plugin-provider-codex:test:
bb-plugin-provider-codex:test: FAIL |bb-plugin-provider-codex| src/bridge/bridge.child-identity.test.ts > passes session identity to the thread child while isolating unrelated parent variables
bb-plugin-provider-codex:test: AssertionError: expected {} to deeply equal { BB_THREAD_ID: 'thr_repro4960', …(3) }
bb-plugin-provider-codex:test:
bb-plugin-provider-codex:test: - Expected
bb-plugin-provider-codex:test: + Received
bb-plugin-provider-codex:test:
bb-plugin-provider-codex:test: - {
bb-plugin-provider-codex:test: - "BB_ENVIRONMENT_ID": "env_repro4960",
bb-plugin-provider-codex:test: - "BB_PROJECT_ID": "proj_repro4960",
bb-plugin-provider-codex:test: - "BB_THREAD_ID": "thr_repro4960",
bb-plugin-provider-codex:test: - "BB_THREAD_STORAGE": "/tmp/repro4960-thread-storage",
bb-plugin-provider-codex:test: - }
bb-plugin-provider-codex:test: + {}
bb-plugin-provider-codex:test:
bb-plugin-provider-codex:test: ❯ src/bridge/bridge.child-identity.test.ts:117:20
bb-plugin-provider-codex:test: 115| console.log("Synthetic child identity:", JSON.stringify(captured));
bb-plugin-provider-codex:test: 116| console.log("Shell policy carries all four synthetic identity values…
bb-plugin-provider-codex:test: 117| expect(captured).toEqual(identity);
bb-plugin-provider-codex:test: | ^
bb-plugin-provider-codex:test: 118| });
bb-plugin-provider-codex:test: 119|
bb-plugin-provider-codex:test:
bb-plugin-provider-codex:test: ⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯[1/1]⎯
bb-plugin-provider-codex:test:
bb-plugin-provider-codex:test:
bb-plugin-provider-codex:test: Test Files 1 failed (1)
bb-plugin-provider-codex:test: Tests 1 failed | 1 passed (2)
The forced run prevents a cached test result from standing in for the second subprocess launch. Both runs show an empty child identity after proving shell policy carried all four synthetic values. No correction to the root-cause claim was needed.
9. Appendix
Relevant existing suites were also run on the unchanged trusted base:
pnpm exec turbo run test --filter=bb-plugin-provider-codex -- src/bridge/app-server-launch.test.ts src/bridge/bridge.model-list.test.ts src/bridge/provider-maintenance.test.ts bb-plugin-provider-codex:test: Test Files 3 passed (3) bb-plugin-provider-codex:test: Tests 27 passed (27) Tasks: 6 successful, 6 total
Both full builds completed successfully. git diff --check passed for the local test addition. Raw install/build/test logs and the authored test are retained outside this public reports repository; public evidence is embedded here in accordance with its publishing rules. All identity values are synthetic; no environment dump or real runtime identity is included.
Trust note: the issue and its links were treated as untrusted claims. No instructions, scripts, branches, or patches from issue content were followed. The reproduction derives only from trusted main source and existing test support.
> AGENT GENERATED