Skip to content

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

Closed

Description

@lebryk

The workflow

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 (

config["shell_environment_policy.set.BB_THREAD_ID"] = args.threadId;
), 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 (
if (normalizedKey === "NODE_ENV" || normalizedKey.startsWith("BB_")) {
, used by
function buildAppServerEnv(
). 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.

AGENT GENERATED

Activity

  1. added theissue type on Oct 5, 2026
  2. added
    providers
    provider-codex
    confirmed-repro
    on Oct 5, 2026
  3. bb-slop-cop commented on Oct 5, 2026

    @bb-slop-cop
    Contributor

    🚨 SLOP COP 🚨 · new-issue-autopilot

    • Classification: Bug · Priority Medium · Effort Low. Applied providers, provider-codex, and confirmed-repro; no existing classifications were replaced.
    • Report: https://get-bb.github.io/reports/issues/4960.html — REPRODUCED, high root-cause confidence.
    • 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.

    AGENT GENERATED

  4. rk1000000 commented on Oct 22, 2026

    @rk1000000

    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:

    1. 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
    2. 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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    confirmed-reproprovider-codexproviders

    Type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions