Repository navigation
Stop overriding Codex's shell_environment_policy with the thread env - #8075
Merged
Merged
Conversation
The Codex bridge copied every thread env var, including plugin contributions such as the Account Pooler token, into shell_environment_policy.set.*. Codex applies set after inherit and exclude, so an admin's policy could not keep those variables out of sandboxed commands. Each bb thread has its own app-server process whose environment is already the thread env, so Codex's own policy now decides what commands get. bb still sets BB_THREAD_ID.
…e test CI sets BB_TEST_DURATIONS_DIR, so the fake app-server logged it with the test's BB_TEST_ variables and the launch env assertion failed.
Removing the thread-env copy from shell_environment_policy.set left only BB_THREAD_ID forced, so inherit = "core" or an exclude matching BB_* dropped BB_SERVER_URL and BB_CLI and broke the bb CLI inside Codex commands. Force bb's non-secret context variables (BB_PROJECT_ID, BB_ENVIRONMENT_ID, BB_THREAD_STORAGE, BB_CLI, BB_SERVER_URL, BB_HOST_DAEMON_PORT, BB_THREAD_ID) and leave every other variable, including tokens and project variables, to Codex's policy. Co-Authored-By: Claude Opus 5.5 <[email protected]>
ymichael
added a commit
that referenced
this pull request
Nov 25, 2026
…ess start speed (#8147) ## Human comments ## What was wrong Two tests in `packages/agent-runtime/src/runtime.process-lifecycle.test.ts` fail at random in `Tests (packages-host)` on loaded runners. Both depend on how fast processes start under CPU load. **`drains provider stderr before reporting process exit`** fails with `expected null to be 'stderr-after-exit'`, for example on #8075's merge run ([job](https://github.com/get-bb/bb/actions/runs/45507748534/job/138847431154), 2286 ms). The fake provider spawned a grandchild that inherits stderr, then exited at once. The grandchild had to boot Node and wait 50 ms before writing. After a provider exits, the runtime waits at most `PROVIDER_PROCESS_CLOSE_GRACE_MS` (1 s) for stderr to close. On a loaded runner, Node startup alone can take longer than that. **`does not wait for stalled replacement initialization during full shutdown`** times out at 15 s, followed by an unhandled `Provider "fake" failed to start: spawn .../node ENOENT` ([job](https://github.com/get-bb/bb/actions/runs/45506198560/job/138847994142); it failed on all three attempts of that branch, and took 12.1 s on #8076's passing run). Before reaching its stalled replacement, the test started and retired a full scripted-echo bridge. #8141 measured a full start at 3.7–4.6 s under load, and stopping one can take up to 5 s plus kill and stderr grace periods. On other PRs' loaded runs the test took 3–12 s. When it overran, Vitest timed the test out but its body kept running. `afterEach` removed `tmpDir`, and the replacement then spawned into the missing cwd, which Node reports as `spawn <node> ENOENT`. The ENOENT is a consequence of the timeout, not its cause. #8136 and #8141 fixed the sibling retirement tests the same way; this one was left. ## What changed `runtime.process-lifecycle.test.ts` only. No runtime code changes. - **stderr drain:** the grandchild reports ready over IPC, the provider exits only after that, and the grandchild writes to stderr 50 ms after the IPC channel disconnects, which happens when the provider exits. The write still lands after the exit, but Node startup no longer counts toward the 1 s grace period. - **stalled shutdown:** the first process is the idle child (`process.stdin.resume()`, no post-initialize requests) that the sibling tests use. The adapter it uses is pulled out into a `createIdleAdapter` helper that `createIdleProviderManager` now shares. The replacement still uses the real fake adapter on the raw stalled script, so it receives `initialize` and holds its reply for 3 s, which is the behavior under test. ## How you verified CPU starvation locally: the test runs at background QoS (`taskpolicy -b`) next to 32 busy-loop processes on a 16-core Mac. This reproduces both CI failures. | Test | Before | After | |---|---|---| | stderr drain | 2 CI-assertion failures before I stopped it | 6 of 6 pass | | stalled shutdown | 2 of 4 time out (18.9 s, 21.4 s); passes took 13.1 s and 2.3 s | 4 of 4 pass in 198–358 ms | Both tests still catch the bugs they guard: - stderr drain: with `PROVIDER_PROCESS_CLOSE_GRACE_MS` temporarily set to 0, the new test fails 3 of 3. - stalled shutdown: with `shutdown()` temporarily changed to await in-flight provider starts, the new test fails. `pnpm exec turbo run typecheck lint test --filter=@bb/agent-runtime`: pass (316 tests, 1 skipped). > AGENT GENERATED 🤖 Generated with [Claude Code](https://claude.com/claude-code) --------- Co-authored-by: Claude Opus 5.5 <[email protected]>
alexburlis
added a commit
to alexburlis/omnyo
that referenced
this pull request
Nov 26, 2026
Record the upstream PRs, revisions, contributors, and Omnyo integration commits for merge d2a24ac in docs/upstream-credits.md. Original-PR: get-bb/bb#7663 Original-Commit: get-bb/bb@1737a03 Original-Author: rufi Original-PR: get-bb/bb#8055 Original-Commit: get-bb/bb@651ae20 Original-Author: Jake Lancaster Original-PR: get-bb/bb#8075 Original-Commit: get-bb/bb@511e1ed Original-Author: Jake Lancaster Original-Co-Author: Michael Yong Original-Co-Author: Claude Opus 5.5 Original-PR: get-bb/bb#8096 Original-Commit: get-bb/bb@775090b Original-Author: Michael Yong Original-Co-Author: Claude Opus 5.5 Original-PR: get-bb/bb#8145 Original-Commit: get-bb/bb@8de6711 Original-Commit: get-bb/bb@0d3db49 Original-Commit: get-bb/bb@92d3a76 Original-Commit: get-bb/bb@6705422 Original-Author: Michael Yong Original-Co-Author: Claude Opus 5.5 Original-PR: get-bb/bb#8171 Original-Commit: get-bb/bb@b56ed04 Original-Author: Jake Lancaster Original-PR: get-bb/bb#8238 Original-Commit: get-bb/bb@2a9a142 Original-Author: SawyerHood Original-PR: get-bb/bb#8247 Original-Commit: get-bb/bb@ba4ae22 Original-Author: Salem Original-Co-Author: Claude Opus 5.5 Original-PR: get-bb/bb#8259 Original-Commit: get-bb/bb@96f40a9 Original-Author: SawyerHood Original-PR: get-bb/bb#8263 Original-Commit: get-bb/bb@141e40a Original-Author: mk Original-PR: get-bb/bb#8266 Original-Commit: get-bb/bb@84e20e9 Original-Author: ILIA GOLUBEV
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Human comments
What was wrong
The Codex bridge copied every thread environment variable into
shell_environment_policy.set.*in thethread/startandthread/resumeconfig (buildShellEnvironmentPolicyConfiginplugins/provider-codex/src/session-params.ts). This included plugin contributions such as the Account Pooler'sCODEX_POOL_AUTH_TOKENandBB_ACCOUNT_POOL_PARENT_TOKEN, andGH_TOKEN. Codex appliessetafterinheritandexclude, so an admin'sshell_environment_policy.exclude = ["*TOKEN*"]could not keep these values out of sandboxed commands (#8008, part 2). Thesetcopy dates from when one app-server served several bb threads (901aebd). Now each bb thread starts its own app-server, and its process environment is the thread environment (spawnChildConnection, also on every rebuild from #6939). The copy therefore only overrode the user's or admin's Codex policy.What changed
plugins/provider-codex/src/session-params.ts:buildCodexConfigno longer copies the thread environment intoshell_environment_policy.set. Codex's ownshell_environment_policydecides which variables from the app-server environment reach commands. bb still forces its non-secret context variables throughset(BB_THREAD_ID,BB_PROJECT_ID,BB_ENVIRONMENT_ID,BB_THREAD_STORAGE,BB_CLI,BB_SERVER_URL,BB_HOST_DAEMON_PORT), so thebbCLI works under any policy. With Codex's default policy (inherit all), commands get the same variables as before.plugins/provider-codex/skills/codex-provider/SKILL.md: documents how the thread environment reaches Codex commands and how anexcludefilters it.session-params.test.tsasserts that only bb's context variables appear inshell_environment_policy, and no tokens or project variables.bridge.session-signature.test.tsnow asserts that a rotated or removed variable reaches the relaunched app-server's process environment and not the session config.fake-codex-app-server.mjslogsCODEX_SIGNATURE_TEST_*variables at launch for that assertion.inherit = "core"or"none", or a matchingexclude, commands no longer getGH_TOKEN, plugin contributions or project variables, because bb no longer forces them throughset. bb's context variables above are still forced, sobbCLI calls keep working. Codex's default policy is not affected.HOST_DAEMON_PROTOCOL_VERSIONbump, no plugin API change.networkAccess: trueintoWorkspaceWriteCodexSandboxPolicy: this has been there since the first Codex adapter (c7a5bd2), next toreadOnlywithnetworkAccess: false. Codex's Linux sandbox with network off also blocks loopback, sobbCLI calls from sandboxed commands would fail (checked withcodex sandboxandcurlto 127.0.0.1:000with network off,200with network on). TheworkspaceWriteschema requiresnetworkAccess, so the only way to defer to Codex is to stop sending a per-turnsandboxPolicy. Options: (a) keep it and document that the workspace modes allow network; (b) add a Codex provider setting, like Claude Code'ssandboxEnabled, that leaves the sandbox to Codex's config andrequirements.toml; (c) turn network off and route it through approval, like Claude's sandbox, which allows loopback only.BB_ACCOUNT_POOL_PARENT_TOKENreaches agent commands on purpose so that a nested bb server can use the parent's pool (Let nested bb servers use the parent's Account Pooler deliberately #3654). Claude Code threads get it the same way, andCODEX_POOL_AUTH_TOKENhas the same value. Whether routed threads should pass that token by default is a product decision.How you verified
session-params.test.tsandbridge.session-signature.test.tsassertions fail on origin/main (2 failed, 80 passed) and pass with the change.codex app-server, started with bb'sresolveAppServerLaunch,buildCodexConfigandtoCodexPermissionSettings, a scratchCODEX_HOME, a fake Responses server as the hub, and a fake pool token. An accept-edits workspace turn ranenvin the workspace-write sandbox, and a write outside the workspace was denied.exclude = ["*TOKEN*"]in config.toml: origin/main showedBB_ACCOUNT_POOL_PARENT_TOKENandCODEX_POOL_AUTH_TOKENin the command environment. With this change the command environment has no TOKEN variables.x-bb-account-pool-tokenon 2/2 model requests, andBB_THREAD_IDandPLUGIN_API_URLreached the command.pnpm start:worktreeinstance with Codex 0.171, reading raw command output from the event log:.codex/config.tomlwithexclude = ["*TOKEN*"]and a project variableQA_FAKE_TOKEN: main passesQA_FAKE_TOKENto the command; this branch does not, and$BB_CLI statusworks.inherit = "core": commands get only the bb context variables (no project variables or tokens), and$BB_CLI statusworks.pnpm exec turbo run typecheck test lint --filter=bb-plugin-provider-codex --force: pass (625 tests).pnpm exec turbo run test --filter=@bb/provider-parity --force: pass (80 tests).apps/server/test/skills/shipped-skills-quality.test.ts: pass.Part of #8008. The network-access half and Codex permission profiles are in #8145.