You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Codex app-server process does not carry the thread identity (BB_THREAD_ID), so MCP servers it launches cannot tell which thread they serve #4960
confirmed-reproBug reproduced again from a clean trusted checkout; see linked reportprovider-codexBuilt-in plugin: provider-codexprovidersCross-provider bridges, models, login
A stdio MCP server or other tool that a Codex thread launches needs to know which bb thread it serves, for example to call bb thread ... --self or to keep per-thread state. In bb each Codex thread runs its own app-server process, so the thread is known when that process starts.
What happens today
The Codex bridge sets BB_THREAD_ID only through shell_environment_policy (
), so shell commands see it but the app-server process does not. The app-server's environment is the daemon's environment with every BB_ variable stripped (
). As I read codex's MCP client, it starts stdio MCP servers from the app-server's environment (a default allow-list plus each server's env and env_vars), so even an MCP server configured with env_vars = ["BB_THREAD_ID"] gets nothing.
What you would expect
The app-server for a thread carries that thread's identity: BB_THREAD_ID, BB_ENVIRONMENT_ID, BB_PROJECT_ID and BB_THREAD_STORAGE, copied from the session's environment. Other inherited BB_ variables stay stripped, and the maintenance and model-list app-servers carry no thread identity.
Prototype: RIMTHAN-LAB@0dea73246 (branch codex-app-server-thread-env, on main @ 17b19716c5a00bf29a6b51798ddb07b72acaf259). buildAppServerEnv copies those four keys from the session's env vars. app-server-launch.test.ts covers both the thread and no-thread cases, and the thread case fails on main. The bb-plugin-provider-codex suite (350 tests), its tsc and oxlint pass. The codex-provider skill notes the variables.
Context and alternatives
Alternative: export only BB_THREAD_ID. The other three are cheap and match what shells already see.
Workaround today: give every thread its own workspace directory and have the tool derive the thread from its working directory. That is indirect and breaks when two threads share a checkout.
Evidence: The locally authored regression test fails at the actual spawned-child environment in two clean trusted-main checkouts. All four identity values reach shell configuration but none reach the child. The model-list isolation control and 27 related existing tests pass. Upstream Codex MCP forwarding was not exercised.
Root cause: The Codex launch path overlays only pool-routing session variables and strips inherited BB_*; it never restores session-owned identity for the app-server.
No PR: Restoring identity expands the sanitized provider-child environment's isolation boundary, which this rule excludes from automatic simple fixes.
Same root cause also breaks Codex lifecycle hooks (SessionStart, PreCompact/compact, etc.), not only MCP servers.
Hook processes are spawned by codex app-server, so they inherit its environment, where BB_THREAD_ID / BB_THREAD_STORAGE are absent (checked /proc/<pid>/environ of every running codex app-server and its wrapper on 0.45.0). shell_environment_policy.set.BB_THREAD_ID reaches only model shell commands. A SessionStart hook therefore cannot tell which bb thread it is in. Child Codex threads also share the parent's cwd, so the thread cannot be derived from the working directory either, and bb thread show --json does not expose the Codex session id that the hook receives (session_id), so there is no mapping fallback.
Would help either of:
Set BB_THREAD_ID and BB_THREAD_STORAGE in the env of the per-thread codex app-server process (fixes MCP servers and hooks together), or
Expose the provider session id in bb thread show --json (or a bb thread find --provider-session <id>), so a hook can resolve its thread from session_id.
confirmed-reproBug reproduced again from a clean trusted checkout; see linked reportprovider-codexBuilt-in plugin: provider-codexprovidersCross-provider bridges, models, login
Activity
bb-slop-cop commentedon Oct 5, 2026
🚨 SLOP COP 🚨 ·
new-issue-autopilotproviders,provider-codex, andconfirmed-repro; no existing classifications were replaced.BB_*; it never restores session-owned identity for the app-server.rk1000000 commentedon Oct 22, 2026
Same root cause also breaks Codex lifecycle hooks (
SessionStart,PreCompact/compact, etc.), not only MCP servers.Hook processes are spawned by
codex app-server, so they inherit its environment, whereBB_THREAD_ID/BB_THREAD_STORAGEare absent (checked/proc/<pid>/environof every runningcodex app-serverand its wrapper on 0.45.0).shell_environment_policy.set.BB_THREAD_IDreaches only model shell commands. ASessionStarthook therefore cannot tell which bb thread it is in. Child Codex threads also share the parent's cwd, so the thread cannot be derived from the working directory either, andbb thread show --jsondoes not expose the Codex session id that the hook receives (session_id), so there is no mapping fallback.Would help either of:
BB_THREAD_IDandBB_THREAD_STORAGEin the env of the per-threadcodex app-serverprocess (fixes MCP servers and hooks together), orbb thread show --json(or abb thread find --provider-session <id>), so a hook can resolve its thread fromsession_id.Build every provider CLI's environment with one builder
Build every provider CLI's environment with one builder (get-bb#7722)