Skip to content

fix: add CODEX_HOME env var to MCP gateway step for Codex engine workflows#27457

Merged
lpcox merged 2 commits intomainfrom
fix/codex-home-gateway-env
Apr 20, 2026
Merged

fix: add CODEX_HOME env var to MCP gateway step for Codex engine workflows#27457
lpcox merged 2 commits intomainfrom
fix/codex-home-gateway-env

Conversation

@lpcox
Copy link
Copy Markdown
Collaborator

@lpcox lpcox commented Apr 20, 2026

Problem

PR #27418 adds code in codex_mcp.go that copies the converted MCP config into ${CODEX_HOME}/config.toml during the "Start MCP Gateway" step. However, CODEX_HOME is only defined as an environment variable on the agent execution step (in codex_engine.go), not on the gateway setup step.

This causes mkdir -p "${CODEX_HOME}" to expand to mkdir -p "", which fails with:

mkdir: cannot create directory '': No such file or directory

Root Cause

The collectMCPEnvironmentVariables() function in mcp_environment.go collects env vars for the "Start MCP Gateway" step but did not include CODEX_HOME. When PR #27418 references ${CODEX_HOME} in that step, it resolves to an empty string.

Fix

Add CODEX_HOME=/tmp/gh-aw/mcp-config to collectMCPEnvironmentVariables() only when the engine is codex, matching the value already hardcoded on the agent step in codex_engine.go:283.

Changes

  • pkg/workflow/mcp_environment.go: Add CODEX_HOME to the gateway step env for Codex engine workflows
  • pkg/workflow/mcp_environment_test.go: Add tests verifying CODEX_HOME is present for codex and absent for copilot/claude/empty engines

Testing

  • New unit tests pass for both positive (codex) and negative (copilot, claude, empty) cases
  • Existing MCP environment tests unaffected
  • Lock file recompilation confirms CODEX_HOME appears only in codex workflow lock files

Relates to #27418

…flows

The MCP gateway setup step needs CODEX_HOME to be available as an
environment variable so that the Codex config sync (copying the
converted MCP config into CODEX_HOME) can reference it. Without this,
mkdir -p "${CODEX_HOME}" expands to an empty string and fails.

Adds CODEX_HOME=/tmp/gh-aw/mcp-config to collectMCPEnvironmentVariables
only when the engine is codex, matching the value already set on the
agent execution step in codex_engine.go.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot AI review requested due to automatic review settings April 20, 2026 23:20
@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Apr 20, 2026

Smoke CI completed successfully!

@github-actions
Copy link
Copy Markdown
Contributor

✅ smoke-ci: safeoutputs CLI comment only run (24695393438)

Generated by Smoke CI for issue #27457 ·

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Adds the missing CODEX_HOME environment variable to the MCP gateway startup step for Codex workflows, preventing ${CODEX_HOME} from expanding to an empty string during gateway setup.

Changes:

  • Extend collectMCPEnvironmentVariables() to include CODEX_HOME for Codex workflows.
  • Add unit tests ensuring CODEX_HOME is present for Codex and absent for other engines.
Show a summary per file
File Description
pkg/workflow/mcp_environment.go Adds conditional CODEX_HOME env var injection for Codex in MCP gateway env collection.
pkg/workflow/mcp_environment_test.go Adds tests covering CODEX_HOME inclusion/exclusion based on engine.

Copilot's findings

Tip

Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

  • Files reviewed: 2/2 changed files
  • Comments generated: 2

Comment on lines +193 to +198
// Codex engine needs CODEX_HOME available in the gateway setup step so that
// the converted MCP config can be copied into the writable Codex home directory.
// This matches the value set on the agent step in codex_engine.go.
if workflowData != nil && workflowData.AI == string(constants.CodexEngine) {
envVars["CODEX_HOME"] = "/tmp/gh-aw/mcp-config"
}
Copy link

Copilot AI Apr 20, 2026

Choose a reason for hiding this comment

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

The CODEX_HOME env var is currently gated on workflowData.AI == "codex" (the logical engine ID). This will miss custom engine definitions that are backed by the Codex runtime via engine.definition.runtime-id (supported by the EngineCatalog), and those workflows would still hit the same empty ${CODEX_HOME} failure when the Codex runtime emits CODEX_HOME references in the gateway step. Consider keying this off the resolved runtime adapter instead (e.g., pass the CodingAgentEngine into collectMCPEnvironmentVariables and check engine.GetID() == string(constants.CodexEngine)).

Copilot uses AI. Check for mistakes.
Comment on lines +187 to +189
mcpTools := []string{"github"}
workflowData := &WorkflowData{AI: "codex"}

Copy link

Copilot AI Apr 20, 2026

Choose a reason for hiding this comment

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

This test hardcodes the engine name as the string "codex". To avoid drift with the supported engine IDs, consider using string(constants.CodexEngine) (and similarly for the non-codex cases) so renames/aliases are caught at compile time.

Copilot uses AI. Check for mistakes.
@lpcox
Copy link
Copy Markdown
Collaborator Author

lpcox commented Apr 20, 2026

@copilot address this review feedback #27457 (review)

Agent-Logs-Url: https://github.com/github/gh-aw/sessions/27e0a550-30d5-4846-8d4e-03d3761d5659

Co-authored-by: lpcox <15877973+lpcox@users.noreply.github.com>
@lpcox lpcox merged commit 033b3a0 into main Apr 20, 2026
23 of 24 checks passed
@lpcox lpcox deleted the fix/codex-home-gateway-env branch April 20, 2026 23:38
Copilot stopped work on behalf of lpcox due to an error April 20, 2026 23:38
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.

3 participants