Skip to content

fix(codex): define mocked MCP servers on the codex exec command - #398

Merged
zpzjzj merged 8 commits into
alibaba:mainfrom
karanb192:fix/codex-mocked-mcp-flags
Nov 16, 2026
Merged

zpzjzj merged 8 commits into
alibaba:mainfrom
karanb192:fix/codex-mocked-mcp-flags

Conversation

@karanb192

@karanb192 karanb192 commented Nov 12, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Mocked MCP servers for the codex engine are defined with -c mcp_servers.<name>... overrides on each codex exec and codex exec resume command. They no longer go through codex mcp add or codex mcp remove, so they do not replace or leave entries in the user's Codex config.

Refs #360. Real MCP servers retain the existing installation path.

Details

  • Mock definitions are stored per runtime, shared across Codex adapters so a separate agent judge gets the case's mocks. Concurrent runtimes with the same workspace path keep separate definitions. An optional RuntimeReleaser hook lets the evaluator drop the record before closing the runtime, including after setup failures.
  • codex mcp list --json checks for existing server names. A conflicting name, an unreadable list, or a mock definition the adapter cannot represent causes an error before execution instead of modifying the user's config.
  • Each generated script is uploaded to the run's artifact directory as mcp-server-<n>.cjs. Numbered files avoid case-insensitive filename collisions, and .cjs preserves CommonJS behavior inside a module package. Upload failures stop execution and clean up the artifact directory.
  • Existing approval flags remain in place. The English and Chinese guides and changelog describe the new behavior.

Test plan

Checked after merging current main, using Go 1.26.10 and the pinned lint tools:

  • make verify
  • make test
  • make e2e
  • npm run docs:build

Unit tests cover first and resumed turns, sandbox and bypass modes, real-server installation, existing-name and listing failures, rejected definitions, upload cleanup, concurrent runtimes, judge adapters, and runtime release.

Earlier live checks with Codex CLI 0.167.1 verified invocation-only servers answered tool calls under workspace-write, the Codex config stayed byte-identical, and generated overrides parsed correctly. Generated .cjs scripts also answered MCP requests. These live checks were not rerun for this main merge.

Codex 0.80.0, the default pin, has not been run. Its binary contains the mcp list --json help text but could not be launched in the test environment.

codex mcp add wrote each mocked server into the user's global
~/.codex/config.toml, replaced a same-named server of theirs, and left
the mock there after the run. Define mocked servers with -c overrides on
every codex exec and resume command instead, and fail early when the
user's config already has a server with that name.

Refs alibaba#360
Reject a mocked server that cannot be defined with -c flags instead of
falling back to codex mcp add. Read existing names from codex mcp list
--json and fail when the listing fails. Write each mock script to the
run's artifact directory so several mocks do not lengthen the command.
Names that differ only in case shared one file on case-insensitive
disks, and a .js file under a package.json with "type": "module" would
break the built-in filesystem mock's require calls.
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 12, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-12T18:52:57.409273Z 2298e30 PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 2298e30c7a

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread internal/agent/codex.go Resolved
Comment thread internal/agent/codex.go Resolved
Docker and OpenSandbox runtimes of concurrent cases report the same
workspace path, so keying by path let one case receive another's mocks.
Key by runtime identity instead. Keep the record outside the adapter so
the separate adapter the evaluator creates for an agent judge, which runs
in the case's runtime, gets the case's mocked servers; its empty install
does not clear them.
The per-runtime record outlived the case: nothing removed it when the
evaluator closed the runtime. Agents can now implement RuntimeReleaser,
and the evaluator calls it before closing a case's runtime, on success
and when setup fails after the MCP install. The Codex adapter drops the
case's record there.

The same-path test now runs both cases concurrently.

@zpzjzj zpzjzj left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@zpzjzj
zpzjzj added this pull request to the merge queue Nov 16, 2026
Merged via the queue into alibaba:main with commit d6c8b76 Nov 16, 2026
16 checks passed
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.

2 participants