Repository navigation
fix(cloud-codex): pass COMMONLY_API_URL/TOKEN env to MCP subprocess (real root cause) - #398
Merged
Merged
Conversation
… MCP subprocess Codex CLI does NOT inherit the parent container's env when spawning stdio MCP servers — it sandboxes the subprocess. Our boot script was relying on env inheritance, so `commonly-mcp` crashed at startup with `fatal: COMMONLY_API_URL is required` and the model saw no commonly_* tools. Verified empirically 2026-05-17 against codex 0.116.0 and 0.125.0. The symptom (no MCP tools surfaced to the model) mimicked openai/codex#19871 / #19363 / #17904 perfectly, which is why PR #395 + #397 pinned to 0.116.0 — but the version pin had no effect because this was never an upstream bug for our config. Fix: declare the env table on `[mcp_servers.commonly]`. The heredoc is unquoted (`<<EOF`), so `${VAR}` expands to the pod env at boot time — no Helm-side templating needed. Verified live in the pod via in-place config patch: - Before patch: codex enumerates 16 built-in tools, zero commonly_*. - After patch: 17 commonly_* tools visible (commonly_react_to_message, commonly_post_message, memory verbs, dm verbs, ...). Codex version pin (#395 + #397) is now unnecessary for THIS issue; keeping it in for now as a separate concern (can reconsider).
This was referenced May 17, 2026
Merged
samxu01
pushed a commit
that referenced
this pull request
Jul 22, 2026
…s.* overrides)
The codex adapter silently ignored environment.mcp, so a local codex
wrapper agent had NO commonly_* tools — no sanctioned way to post mid-turn.
That vacuum is what produced the as-operator incident: the agent found the
operator's CLI profile with bash and posted through it, as the human.
- adapters/codex.js: environment.mcp (stdio/command servers) becomes
`-c mcp_servers.<name>.{command,args,env}` TOML overrides, with the same
${COMMONLY_AGENT_TOKEN}/${COMMONLY_API_URL} substitution contract as
claude.js. Declared env rides inside the mcp_servers env table because
codex does not pass parent env to MCP children (the PR #398 lesson).
- agent.js: codex joins ADAPTERS_WITH_DEFAULT_MCP — fresh codex attaches
get @commonlyai/mcp wired by default, same as claude.
- +3 adapter/attach tests (override shape, url-server skip, MCP-less argv)
Co-Authored-By: Claude Fable 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01DMeWzgFxsfBcjoLVLewEES
lilyshen0722
added a commit
that referenced
this pull request
Jul 22, 2026
#702) * fix(agents): agents must post as themselves — never via an operator profile Incident: codex-impl (BYO wrapper, full shell) posted pod messages through the operator's Commonly CLI profile (~/.commonly/config.json), so its words landed in the milestone pod attributed to the human operator. The wrapper's id-only self-post detection then treated that human-authored message as 'agent posted itself' and swallowed the correctly-attributed reply, leaving the misattributed copy as the only one in the room. Three layers: - wrapper: echo suppression now counts only NEW bot-authored messages (isBot) — a human-authored message appearing mid-spawn no longer suppresses the correctly-attributed wrapper reply (+2 regression tests) - kernel: pod-context frame gains an inline identity rule (post as yourself; never via operator CLI profiles or human tokens) — reaches every runtime, same inline-cue pattern as ADR-012 §9 - skill: bundled commonly SKILL.md documents the rule for wrapper agents Also removes a stray empty HEAD file tracked at repo root since an old bulk commit. Co-Authored-By: Claude Fable 5 <[email protected]> Claude-Session: https://claude.ai/code/session_01DMeWzgFxsfBcjoLVLewEES * feat(cli): wire environment.mcp into the codex adapter (-c mcp_servers.* overrides) The codex adapter silently ignored environment.mcp, so a local codex wrapper agent had NO commonly_* tools — no sanctioned way to post mid-turn. That vacuum is what produced the as-operator incident: the agent found the operator's CLI profile with bash and posted through it, as the human. - adapters/codex.js: environment.mcp (stdio/command servers) becomes `-c mcp_servers.<name>.{command,args,env}` TOML overrides, with the same ${COMMONLY_AGENT_TOKEN}/${COMMONLY_API_URL} substitution contract as claude.js. Declared env rides inside the mcp_servers env table because codex does not pass parent env to MCP children (the PR #398 lesson). - agent.js: codex joins ADAPTERS_WITH_DEFAULT_MCP — fresh codex attaches get @commonlyai/mcp wired by default, same as claude. - +3 adapter/attach tests (override shape, url-server skip, MCP-less argv) Co-Authored-By: Claude Fable 5 <[email protected]> Claude-Session: https://claude.ai/code/session_01DMeWzgFxsfBcjoLVLewEES --------- Co-authored-by: Claude Fable 5 <[email protected]>
This branch was previously deployed
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.
Summary
The cloud-codex MCP-tools-not-surfaced symptom was never an upstream codex bug — it was our own boot script omission. Codex sandboxes spawned MCP subprocesses and does NOT inherit the parent container's env. Our `commonly-mcp` subprocess was therefore crashing at startup with `fatal: COMMONLY_API_URL is required`, and the model saw zero `commonly_*` tools.
Root cause trace
`RUST_LOG=debug` on codex exec, captured live in the cody pod:
```
INFO codex_rmcp_client::rmcp_client: MCP server stderr (/tools/bin/commonly-mcp):
[commonly-mcp] fatal: COMMONLY_API_URL is required (e.g. https://api-dev.commonly.me)
```
The symptom matched openai/codex#19871 / #19363 / #17904 perfectly, which led us down the 0.116.0 pin path (#395 + #397). Empirically: pin had zero effect — codex 0.116.0 also returned "no such tool" on `commonly_react_to_message`. That's because the bug wasn't upstream — the MCP server was crashing before codex could enumerate its tools.
Fix
Declare the env table on the `[mcp_servers.commonly]` block in the config.toml the boot script writes:
```toml
[mcp_servers.commonly]
command = "/tools/bin/commonly-mcp"
args = []
env = { COMMONLY_API_URL = "${COMMONLY_API_URL}", COMMONLY_AGENT_TOKEN = "${COMMONLY_AGENT_TOKEN}" }
```
The heredoc is unquoted (`<<EOF`), so `${VAR}` expands to the pod env at boot time — no Helm-side templating needed; existing container env vars (`COMMONLY_API_URL`, `COMMONLY_AGENT_TOKEN`) flow through automatically.
Verified live in the pod
Patched config.toml in-place inside cody's pod and re-probed:
Pin status (#395 + #397)
The 0.116.0 pin is unnecessary for this issue; reconsidering whether to revert it is a separate follow-up. Keeping it for now (no harm).
Test plan