Skip to content

Codex install omits CBM_CACHE_DIR from env_vars, causing MCP handshake failure #1562

Closed

Description

@anton-matosov

Version

codebase-memory-mcp 0.10.2

Platform

Linux (arm64)

Install channel

GitHub release archive / install.sh

Binary variant

standard

What happened, and what did you expect?

When CBM_CACHE_DIR points to a non-default cache directory, codebase-memory-mcp install -y --force configures the Codex MCP server without forwarding that variable:

[mcp_servers.codebase-memory-mcp]
command = "/root/.local/bin/codebase-memory-mcp"
args = []

Codex sanitizes the environment of stdio MCP subprocesses unless variables are explicitly listed in env_vars. Consequently, the CBM subprocess spawned by Codex falls back to the default cache directory while the active account daemon uses the custom CBM_CACHE_DIR.

The cache mismatch closes the MCP connection during initialization. Codex then exposes none of the CBM tools.

I expected the CBM installer to configure Codex to forward CBM_CACHE_DIR whenever that variable is set:

[mcp_servers.codebase-memory-mcp]
command = "/root/.local/bin/codebase-memory-mcp"
args = []
env_vars = ["CBM_CACHE_DIR"]

Reproduction

  1. Set a custom cache directory:

    export CBM_CACHE_DIR=/workspaces/example/.cache/codebase-memory-mcp
  2. Install/configure CBM:

    codebase-memory-mcp install -y --force
  3. Start the daemon and index a repository:

    codebase-memory-mcp daemon start
    codebase-memory-mcp cli index_repository --repo-path /workspaces/example
  4. Inspect ~/.codex/config.toml. The generated MCP entry has command and args, but no env_vars.

  5. Start Codex from an environment containing CBM_CACHE_DIR and request a CBM tool such as list_projects.

  6. Observe that CBM tools are unavailable and the MCP handshake fails.

For comparison, add this manually:

env_vars = ["CBM_CACHE_DIR"]

Start a new Codex session and call list_projects again. The MCP connection succeeds and the indexed project is returned.

No repository source code is required to reproduce the problem.

Logs

error: CBM could not start because the active account daemon uses a different cache

Codex also reports:

MCP startup failed: handshaking with MCP server failed: connection closed: initialize response

The two cache locations in the reproduced case were:

Active daemon: /workspaces/example/.cache/codebase-memory-mcp
Codex-spawned CBM fallback: /root/.cache/codebase-memory-mcp

Proposed solution

When CBM_CACHE_DIR is set during installation, add it to the Codex server’s forwarded environment:

[mcp_servers.codebase-memory-mcp]
env_vars = ["CBM_CACHE_DIR"]

The installer should preserve existing env_vars entries and add CBM_CACHE_DIR only if it is absent.

The same setting may also be needed in installer-generated Codex agent profiles that declare their own [mcp_servers.codebase-memory-mcp] transport.

A regression test could:

  1. Run configuration generation with CBM_CACHE_DIR set.
  2. Verify that the resulting Codex server table contains env_vars = ["CBM_CACHE_DIR"].
  3. Verify that existing forwarded variables are preserved.
  4. Verify that the generated TOML remains idempotent across repeated installs.

Project scale

Not relevant; the failure occurs during MCP initialization before graph access.

Confirmations

  • I searched existing issues and did not find a duplicate mentioning Codex env_vars or CBM_CACHE_DIR.
  • The reproduction does not require proprietary code.

Related but distinct: #1383 discusses account-daemon cache conflicts, but not the Codex installer’s missing environment forwarding.

Activity

  1. anton-matosov commented on Aug 12, 2026

    @anton-matosov
    Author

    I have worked around this issue by adding the env_vars after install and reverting before reinstall with this little script:
    https://github.com/plume-works/agent-devcontainer/pull/46/changes#diff-570bc27223451d80b291a06294080e6fbee20dc73f427e9a292f6fff1d373294

  2. DeusData commented on Aug 12, 2026

    @DeusData
    Owner

    @anton-matosov — fixed and shipping in v0.10.3 (releasing now), commit 63f26f4c. The generated Codex block now carries env_vars = ["CBM_CACHE_DIR"], exactly the shape you verified by hand.

    One deliberate difference from the obvious implementation: the name is listed unconditionally, not only when CBM_CACHE_DIR happens to be set during install. env_vars names variables to forward if present, so listing it costs nothing when unset — and it keeps working for someone who sets the variable after installing, which install-time detection would silently miss and reproduce your exact bug with no way to tell.

    Thank you for tracing it to the sanitized subprocess environment and confirming the corrected block end-to-end before filing. That turned it into a one-line change.

  3. added
    bugSomething isn't working
    priority/highNeeds near-term maintainer attention; high-impact bug, regression, safety issue, or release blocker.
    on Aug 12, 2026
  4. DeusData commented on Aug 13, 2026

    @DeusData
    Owner

    v0.10.3 is published — https://github.com/DeusData/codebase-memory-mcp/releases/tag/v0.10.3 (GitHub archives, npm, and PyPI are all serving it).

    This fix is in it. Please give it a try when you get a chance: if it behaves in your setup, feel free to close this out, and if anything still looks off, say so and we'll pick it straight back up. Thank you again for the report.

  5. DeusData commented on Aug 13, 2026

    @DeusData
    Owner

    Closing as fixed in v0.10.3 by commit 63f26f4c. Generated Codex configuration now lists CBM_CACHE_DIR in env_vars unconditionally, so it is forwarded whenever present without depending on install-time state.

    Thank you again @anton-matosov for tracing the handshake failure to Codex's sanitized subprocess environment and verifying the corrected TOML shape. If the custom-cache path still diverges on v0.10.3 or newer, comment here and we will reopen it.

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

    bugSomething isn't workingeditor/integrationEditor compatibility and CLI integrationpriority/highNeeds near-term maintainer attention; high-impact bug, regression, safety issue, or release blocker.windowsWindows-specific issues

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions