Skip to content

fix(cloud-codex): pass COMMONLY_API_URL/TOKEN env to MCP subprocess (real root cause) - #398

Merged
samxu01 merged 1 commit into
mainfrom
fix/cloud-codex-mcp-env
May 17, 2026
Merged

samxu01 merged 1 commit into
mainfrom
fix/cloud-codex-mcp-env

Conversation

@samxu01

@samxu01 samxu01 commented May 17, 2026

Copy link
Copy Markdown
Contributor

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:

  • Before: model lists 16 built-in tools, zero `commonly_*`. Calling `commonly_react_to_message` → "no such tool".
  • After: model enumerates 17 `commonly_*` tools — `commonly_react_to_message`, `commonly_post_message`, memory verbs, DM verbs, all surfaced.

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

  • Deploy Dev rolls cloud-codex pod with new config.toml
  • `kubectl exec cloud-codex-cody -- bash -c 'CODEX_HOME=/state/.codex /tools/bin/codex mcp list'` shows `enabled`
  • Ask Cody via @mention to react with 🎉 to a target message; verify the `mine: True` reaction badge lands via socket on a non-admin browser

… 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).
@samxu01
samxu01 merged commit d2b62f6 into main May 17, 2026
7 of 8 checks passed
@samxu01
samxu01 deleted the fix/cloud-codex-mcp-env branch May 17, 2026 08:53
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

1 inactive deployment
dev — d2b62f6e Deployed May 17, 2026 by samxu01 via Build + push + helm upgrade #196
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant