Repository navigation
Let nested bb servers use the parent's Account Pooler deliberately - #3654
Merged
ymichael merged 1 commit intoSep 14, 2026
Merged
Conversation
ymichael
force-pushed
the
bb/trace-environment-variables-to-agents-thr_uazquq3zvk
branch
from
September 14, 2026 20:29
b736145 to
f6f004e
Compare
A bb server started inside another bb server's thread already inherited the parent's pooler routing, but only by accident of process inheritance. Contributed env reaches the agent's shell, toDevProcessEnv strips only three BB_ thread keys, turbo passes everything through, and the daemon's bridge spawn strips only BB_* and NODE_ENV, so the provider credentials survive into the nested instance. That accident is provider-locked: contributeEnv is registered per provider and the server resolves only the thread's own provider, so a Codex thread propagates only CODEX_*, a Claude thread only ANTHROPIC_*. Which half of the nested server works is decided by whichever provider happened to launch it. It also hands the parent's unscoped hub token to every agent in the nested instance, and leaves nested threads invisible to recordRouted and unreachable by bypass. The parent now contributes a provider-neutral marker (BB_ACCOUNT_POOL_PARENT_URL as a serverPath, plus the machine token) to both providers. A nested instance reads it, enables the pooler on first run, and defaults to proxying: it runs its own hub with its own machine tokens and forwards upstream with the parent's token, so that token never reaches nested agents. It reads a new hub-token-authenticated /availability route to learn which providers the parent can serve, and contributes routing only for those, failing closed when the parent is unreachable. bb pool parent isolate switches to contributing empty routing values, which overrides the inherited ones. The marker is BB_-prefixed deliberately: contributed env is an explicit session override so it reaches the nested server, but sanitizeInheritedChildProcessEnv strips it at the bridge spawn, so it cannot propagate further without a deliberate re-contribution. In settings the parent appears as a banner above everything else, since it decides whether the rest of the page applies at all. While proxying, the remainder of the page is dimmed and inert, which is accurate: Hub.handle forwards every request to the parent in that mode, so local accounts go unused regardless of provider. The banner names the providers the parent can actually serve and says what falls back. Also fixes a latent bug in httpUrlSchema that the new marker schema would have copied: .refine runs even when .url() fails, so malformed CLI or RPC input threw a raw TypeError instead of a validation error. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
ymichael
force-pushed
the
bb/trace-environment-variables-to-agents-thr_uazquq3zvk
branch
from
September 14, 2026 21:44
f6f004e to
eb62b37
Compare
ymichael
deleted the
bb/trace-environment-variables-to-agents-thr_uazquq3zvk
branch
September 14, 2026 21:52
OXI-717
added a commit
to OXI-717/bb
that referenced
this pull request
Sep 17, 2026
Twenty commits from the 0.43.1 line: three opencode subscriptions and Cursor pooled behind the hub, real quota for all of them, and an exhausted pool that refuses instead of handing back a multi-day retry-after a coding agent obeys in silence. Every conflict was inside plugins/account-pool, so the merge takes that plugin whole from the branch that is actually running rather than reconciling two designs. Upstream's own post-0.43.1 work on this plugin — the parent-pool layer from get-bb#3654 and the usage-source split from get-bb#3449 — is therefore not carried over; adopting it belongs with the re-port onto whatever app version supersedes 0.43.1, where the result can be exercised. Verified: turbo typecheck and the plugin suite (14 files) on the merge result, whose plugin tree is identical to the one serving six pooled subscriptions today. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
ymichael
added a commit
that referenced
this pull request
Nov 24, 2026
…8075) ## Human comments ## What was wrong The Codex bridge copied every thread environment variable into `shell_environment_policy.set.*` in the `thread/start` and `thread/resume` config (`buildShellEnvironmentPolicyConfig` in `plugins/provider-codex/src/session-params.ts`). This included plugin contributions such as the Account Pooler's `CODEX_POOL_AUTH_TOKEN` and `BB_ACCOUNT_POOL_PARENT_TOKEN`, and `GH_TOKEN`. Codex applies `set` after `inherit` and `exclude`, so an admin's `shell_environment_policy.exclude = ["*TOKEN*"]` could not keep these values out of sandboxed commands (#8008, part 2). The `set` copy 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`: `buildCodexConfig` no longer copies the thread environment into `shell_environment_policy.set`. Codex's own `shell_environment_policy` decides which variables from the app-server environment reach commands. bb still forces its non-secret context variables through `set` (`BB_THREAD_ID`, `BB_PROJECT_ID`, `BB_ENVIRONMENT_ID`, `BB_THREAD_STORAGE`, `BB_CLI`, `BB_SERVER_URL`, `BB_HOST_DAEMON_PORT`), so the `bb` CLI 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 an `exclude` filters it. - Tests: `session-params.test.ts` asserts that only bb's context variables appear in `shell_environment_policy`, and no tokens or project variables. `bridge.session-signature.test.ts` now asserts that a rotated or removed variable reaches the relaunched app-server's process environment and not the session config. `fake-codex-app-server.mjs` logs `CODEX_SIGNATURE_TEST_*` variables at launch for that assertion. - Behavior change for strict Codex policies: with `inherit = "core"` or `"none"`, or a matching `exclude`, commands no longer get `GH_TOKEN`, plugin contributions or project variables, because bb no longer forces them through `set`. bb's context variables above are still forced, so `bb` CLI calls keep working. Codex's default policy is not affected. - No wire change, no `HOST_DAEMON_PROTOCOL_VERSION` bump, no plugin API change. - Not changed, left for a maintainer decision: - Part 1, `networkAccess: true` in `toWorkspaceWriteCodexSandboxPolicy`: this has been there since the first Codex adapter (c7a5bd2), next to `readOnly` with `networkAccess: false`. Codex's Linux sandbox with network off also blocks loopback, so `bb` CLI calls from sandboxed commands would fail (checked with `codex sandbox` and `curl` to 127.0.0.1: `000` with network off, `200` with network on). The `workspaceWrite` schema requires `networkAccess`, so the only way to defer to Codex is to stop sending a per-turn `sandboxPolicy`. Options: (a) keep it and document that the workspace modes allow network; (b) add a Codex provider setting, like Claude Code's `sandboxEnabled`, that leaves the sandbox to Codex's config and `requirements.toml`; (c) turn network off and route it through approval, like Claude's sandbox, which allows loopback only. - With Codex's default policy, sandboxed commands still see the hub token. `BB_ACCOUNT_POOL_PARENT_TOKEN` reaches agent commands on purpose so that a nested bb server can use the parent's pool (#3654). Claude Code threads get it the same way, and `CODEX_POOL_AUTH_TOKEN` has the same value. Whether routed threads should pass that token by default is a product decision. - The login-shell PATH order note. ## How you verified - The new `session-params.test.ts` and `bridge.session-signature.test.ts` assertions fail on origin/main (2 failed, 80 passed) and pass with the change. - End to end with Codex CLI 0.171.0: a real `codex app-server`, started with bb's `resolveAppServerLaunch`, `buildCodexConfig` and `toCodexPermissionSettings`, a scratch `CODEX_HOME`, a fake Responses server as the hub, and a fake pool token. An accept-edits workspace turn ran `env` in the workspace-write sandbox, and a write outside the workspace was denied. - With `exclude = ["*TOKEN*"]` in config.toml: origin/main showed `BB_ACCOUNT_POOL_PARENT_TOKEN` and `CODEX_POOL_AUTH_TOKEN` in the command environment. With this change the command environment has no TOKEN variables. - With Codex's default policy, both builds pass both variables (Codex inherits all). - In every run the hub received `x-bb-account-pool-token` on 2/2 model requests, and `BB_THREAD_ID` and `PLUGIN_API_URL` reached the command. - Live check on a `pnpm start:worktree` instance with Codex 0.171, reading raw command output from the event log: - Project `.codex/config.toml` with `exclude = ["*TOKEN*"]` and a project variable `QA_FAKE_TOKEN`: main passes `QA_FAKE_TOKEN` to the command; this branch does not, and `$BB_CLI status` works. - `inherit = "core"`: commands get only the bb context variables (no project variables or tokens), and `$BB_CLI status` works. - `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. > AGENT GENERATED --------- Co-authored-by: Michael Yong <[email protected]> Co-authored-by: Claude Opus 5.5 <[email protected]>
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
A bb server started inside another bb server's thread — the normal way we dev on bb itself — already inherited the parent's Account Pooler routing, but only by accident of process inheritance. Contributed env lands in the agent's shell,
toDevProcessEnvstrips only threeBB_thread keys, turbo passes everything through (@bb/server#devand@bb/host-daemon#devboth declarepassThroughEnv: ["*"]), and the daemon's bridge spawn strips onlyBB_*andNODE_ENV— so the provider credentials survive into the nested instance.That accident is provider-locked.
experimental_contributeEnvis registered per provider and the server resolves only the thread's own provider, so a Codex thread propagates onlyCODEX_*and a Claude thread onlyANTHROPIC_*; which half of the nested server works is decided by whichever provider happened to runpnpm dev. Verified live on a running nested instance: its host-daemon and itsprovider-claude-codebridge worker both carried the parent'sCODEX_OPENAI_BASE_URLandCODEX_POOL_AUTH_TOKENand noANTHROPIC_*, because a Codex thread had launched it. The accident also hands the parent's unscoped hub token to every agent in the nested instance, and leaves nested threads invisible torecordRoutedand unreachable bybypass.What changed
Marker (
plugins/account-pool/src/server.ts). The parent contributes a provider-neutral pair to both providers:BB_ACCOUNT_POOL_PARENT_URL(as a{ serverPath }, so it stays correct on remote machines where agents reach the server through the daemon's local auth proxy) andBB_ACCOUNT_POOL_PARENT_TOKEN. TheBB_prefix is deliberate — contributed env is an explicit session override so it reaches the nested server, butsanitizeInheritedChildProcessEnvstrips it at the bridge spawn, so it cannot propagate past one level without a deliberate re-contribution.Proxy mode (
src/hub.ts,src/parent-pool.ts). A nested instance reads the marker and defaults to proxying: it keeps its own hub and mints its own machine tokens, andHub.forwardToParentforwards upstream with the parent's token, skipping account selection, quota, pacing and failover entirely. The parent's token never reaches nested agents, and the nested instance's ownRoutingStorerecords and bypasses its own threads. The abort/release plumbing is shared withfetchUpstreamviatrackRequestrather than duplicated.Availability route. New
GET …/http/availability, authenticated by the hub token, returning{ claude, codex }booleans from the samecanServegate the env contribution uses — that gate is now one function instead of the three inline copies it was before. A proxying child queries it and contributes routing only for providers the parent can serve, failing closed when the parent is unreachable. Booleans only: a hub token is unscoped, so every holder can read this.Isolate mode.
bb pool parent isolatecontributes empty routing values, which override the inherited ones. Verified empty string is sufficient at both consumers, so this needs no unset capability: noHOST_DAEMON_PROTOCOL_VERSIONbump and no new public plugin API.ENABLE_TOOL_SEARCHis deliberately left alone — it only matters behind a custom base URL, so blanking the base URL is enough and empty-boolean semantics stay out of it.Default-enable (
apps/server/src/services/plugins/builtin-registry.ts).account-poolisdefaultEnabled: false, so without this a nested instance never loads the plugin and falls through to the silent inheritance.defaultEnabledis now marker-aware. It is a first-run seed (enabled: existing?.enabled ?? bundled.defaultEnabled), so fresh nested data dirs pick it up and already-booted instances need one manual flip.Settings UI (
app.tsx). The parent is a banner above everything else, since it decides whether the rest of the page applies at all. While proxying, the remainder is dimmed andinert— accurate, becauseHub.handleforwards every request to the parent in that mode, so local accounts go unused regardless of provider. The error alert and dialogs stay outside the inert region. Five states, all screenshotted against the running app:main<host>. Turn this on to send Claude and Codex requests to its pool instead of using the accounts below.<host>. Accounts on this server are not used while this is on.<host>. Codex has no accounts there, so those requests fall back to their own credentials.<host>has no accounts available right now, so nothing is being sent there. Requests fall back to each provider's own credentials.Parent-unreachable renders as the last row, since it fails closed to the same value. The banner shows the host, not the full
/api/v1/plugins/account-pool/httppath.Surfaces.
bb pool parent [proxy|isolate]plusparentModeinbb pool config;PLUGIN_OVERVIEW.md, theaccount-poolskill reference, and the two new env vars indocs/configuration.md.Drive-by.
httpUrlSchemaincontracts.tshad a latent bug the new marker schema would have copied —.refineruns even when.url()fails, sonew URL()threw a rawTypeErroron malformed CLI or RPC input instead of returning a validation error. My own new test caught it. Both schemas now catch and return false. Happy to split this out if you'd rather.How you verified
src/parent-pool.test.ts: marker parsing rejects a malformed URL or token rather than half-configuring proxying; header rewriting drops inbound credentials; availability caches, and fails closed on unreachable / 401 / unexpected body.src/server.test.ts: isolate, can't-serve and unreachable all neutralise; proxy contributes self-pointing routing plus the marker with a token that is not the parent's; forwarding presents the parent token and drops the inbound one; the child rejects traffic bearing the parent's token; the availability route is 401 without a hub token.app.test.tsxcovering all four copy branches plus the no-parent case, and asserting the API path is not leaked into the UI.sanitizeInheritedChildProcessEnvkeeps the provider vars and strips the marker (@bb/process-utils);toDevProcessEnvpasses the marker through (@bb/scripts);resolveAppServerLaunchdrops pool args when an inherited value is neutralised with""(bb-plugin-provider-codex). These exist because a plausible-sounding*_TOKENhardening would otherwise silently break every nested instance.turbo run typecheck lint --filter='...[origin/main]'— 78/78 green.turbo run test—bb-plugin-account-pool310,bb-plugin-provider-codex287,@bb/scripts133,@bb/process-utils21,@bb/server2677.pnpm start:worktreeserver running this branch contributed the marker into a nested instance's environment, and its/availabilityanswered that token with{"claude":true,"codex":true}. The five UI states above were captured from the running settings page.Fixes #
🤖 Generated with Claude Code