Skip to content

Commit 63f26f4

Browse files
committed
fix(cli): forward CBM_CACHE_DIR to the Codex-spawned server (DeusData#1562)
Codex sanitizes the environment of stdio MCP subprocesses and passes through only the names listed in `env_vars`. Our generated block had `command` and `args` and nothing else, so a user with a custom CBM_CACHE_DIR got a Codex-spawned server reading the DEFAULT cache while their account daemon used the configured one. The two disagree during initialization, the connection closes, and Codex exposes no cbm tools at all — a total failure that looks like a broken MCP server rather than a missing environment variable. The name is listed unconditionally rather than only when the variable 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 CBM_CACHE_DIR after installing — a case install-time detection would silently miss, producing exactly this bug again with no way to tell. Reported by @anton-matosov, who verified the corrected block end-to-end before filing. Signed-off-by: Martin Vogel <martin.vogel.tech@gmail.com>
1 parent 2bb9437 commit 63f26f4

2 files changed

Lines changed: 20 additions & 1 deletion

File tree

‎src/cli/cli.c‎

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3278,8 +3278,22 @@ int cbm_upsert_codex_mcp(const char *binary_path, const char *config_path) {
32783278
return CLI_ERR;
32793279
}
32803280
char block[CLI_BUF_8K];
3281+
/* #1562: Codex sanitizes the environment of stdio MCP subprocesses, passing
3282+
* through only the names listed in env_vars. Without CBM_CACHE_DIR the
3283+
* Codex-spawned server silently falls back to the DEFAULT cache while the
3284+
* account daemon uses the configured one; the two disagree and the
3285+
* handshake closes during initialization, so Codex exposes no cbm tools at
3286+
* all.
3287+
*
3288+
* The name is listed unconditionally rather than only when the variable is
3289+
* set at install time: env_vars names variables to FORWARD IF PRESENT, so
3290+
* listing it costs nothing when unset and keeps working for someone who
3291+
* sets it after installing — which install-time detection would silently
3292+
* fail to cover. */
32813293
int written = snprintf(block, sizeof(block),
3282-
CODEX_CMM_SECTION "\ncommand = \"%s\"\nargs = []\n", escaped);
3294+
CODEX_CMM_SECTION "\ncommand = \"%s\"\nargs = []\n"
3295+
"env_vars = [\"CBM_CACHE_DIR\"]\n",
3296+
escaped);
32833297
if (written < 0 || (size_t)written >= sizeof(block) ||
32843298
cbm_remove_codex_legacy_mcp(config_path) != 0) {
32853299
return CLI_ERR;

‎tests/test_cli.c‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10122,6 +10122,11 @@ TEST(cli_upsert_codex_mcp_fresh) {
1012210122
ASSERT_NOT_NULL(data);
1012310123
ASSERT(strstr(data, "[mcp_servers.codebase-memory-mcp]") != NULL);
1012410124
ASSERT(strstr(data, "/usr/local/bin/codebase-memory-mcp") != NULL);
10125+
/* #1562: Codex passes only the names listed in env_vars into a stdio MCP
10126+
* subprocess. Without CBM_CACHE_DIR the spawned server uses the DEFAULT
10127+
* cache while the daemon uses the configured one, the two disagree, and the
10128+
* handshake closes — Codex then shows no cbm tools at all. */
10129+
ASSERT(strstr(data, "env_vars = [\"CBM_CACHE_DIR\"]") != NULL);
1012510130

1012610131
test_rmdir_r(tmpdir);
1012710132
PASS();

0 commit comments

Comments
 (0)