fix(vm-agent): enable Codex MCP bootstrap on standalone/cf-container runtimes#1675
Draft
simple-agent-manager[bot] wants to merge 5 commits into
Draft
fix(vm-agent): enable Codex MCP bootstrap on standalone/cf-container runtimes#1675simple-agent-manager[bot] wants to merge 5 commits into
simple-agent-manager[bot] wants to merge 5 commits into
Conversation
Codex agents on standalone/cf-container runtimes fail to load SAM MCP tools because writeAgentStartupConfig returns early when containerID is empty, skipping config.toml writing and SAM_MCP_TOKEN injection. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
…runtimes writeAgentStartupConfig returned early when containerID was empty, skipping writeCodexStartupConfig for standalone and cf-container sessions. This meant Codex never got SAM MCP config written to ~/.codex/config.toml and never received SAM_MCP_TOKEN env vars, so dispatched Codex tasks couldn't call get_instructions. Fix: move Codex handling before the containerID guard, and add writeCodexConfigLocally that writes config.toml to the local filesystem (mirroring writeCodexConfigToContainer). The local path uses resolveLocalAuthFileTargetPath for CODEX_HOME support and mergeManagedCodexMcpConfig for safe config merging. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Add two regression tests that exercise writeAgentStartupConfig directly: - TestWriteAgentStartupConfigCodexStandaloneWritesMcpConfig: proves Codex with containerID="" gets config.toml written and SAM_MCP_TOKEN injected. This test would fail on the pre-fix code where the containerID=="" guard returned early before reaching the Codex branch. - TestWriteAgentStartupConfigNonCodexStandaloneIsNoop: proves non-Codex agents (opencode, vibe, claude-code) are still correctly skipped when containerID is empty. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
…issions Address go-specialist review findings: - Distinguish os.IsNotExist from real read errors (permission denied, I/O error) when reading existing config.toml — prevents silently discarding user config on transient read failures. - Add explicit os.Chmod on .codex directory after MkdirAll, matching the sibling injectAuthFileCredential pattern — tightens permissions on pre-existing directories that may have looser umask defaults. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
…fety Add explicit os.Chmod(configPath, 0o600) after os.WriteFile, ensuring tight permissions even when the file pre-exists with looser umask defaults. Mirrors writeAuthFileToContainer's permission enforcement pattern. Addresses security-auditor MEDIUM finding. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
|
Contributor
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
get_instructionsbecausewriteAgentStartupConfigreturns early whenstartup.containerID == "", skipping Codex MCP config writing (~/.codex/config.toml) andSAM_MCP_TOKENenv var injection.containerID == ""early return inwriteAgentStartupConfig, and add awriteCodexConfigLocallyfunction that writesconfig.tomldirectly to the local filesystem (vs. docker exec) for standalone/cf-container sessions. The local path reusesresolveLocalAuthFileTargetPathforCODEX_HOMEsupport andmergeManagedCodexMcpConfigfor safe config merging, mirroring the container path's behavior.containerID(they may need separate fixes later). Container-based Codex is unchanged. Backward compatible.Changed files
packages/vm-agent/internal/acp/session_host_startup.go— reorderwriteAgentStartupConfigto call Codex beforecontainerIDearly return; branchwriteCodexStartupConfigon containerIDpackages/vm-agent/internal/acp/gateway.go— addwriteCodexConfigLocallywithos.Chmodhardening,os.IsNotExisterror discriminationpackages/vm-agent/internal/acp/gateway_test.go— 6 new tests (4 unit + 2 regression)tasks/active/2026-07-25-fix-codex-mcp-bootstrap.md— task fileValidation
pnpm lintpnpm typecheckpnpm testgo test ./internal/acp/... -count=1— 16 successful, 0 failedStaging Verification (REQUIRED for all code changes — merge-blocking)
DRAFT PR — staging verification deferred to merge time. Per
.claude/rules/13-staging-verification.md, staging is a merge gate. This PR is intentionally kept as a draft and will not be merged until staging verification is completed:~/.codex/config.tomlwritten with SAM MCP entries, confirmSAM_MCP_TOKENin process env, confirmget_instructionssucceedsStaging Verification Evidence
Draft PR — staging verification will be performed before merge.
UI Compliance Checklist (Required for UI changes)
N/A: Go-only vm-agent change, no UI surfaces touched.
End-to-End Verification (Required for multi-component changes)
resolveLocalAuthFileTargetPathreuse verified; Codex CLI config path assumption needs live verification~/.codex/config.tomlis the remaining gapData Flow Trace
Untested Gaps
~/.codex/config.tomlfrom standalone runtime — verified via unit tests that the file is written correctly; live verification deferred to staging (draft PR).Post-Mortem (Required for bug fix PRs)
What broke
Dispatched Codex tasks on standalone/cf-container runtimes could not call SAM MCP
get_instructions— Codex started without MCP config or SAM_MCP_TOKEN, so it had no way to reach SAM's MCP server for project instructions, policies, or tools.Root cause
writeAgentStartupConfiginsession_host_startup.goreturned early whenstartup.containerID == ""before reaching the Codex config writing branch. This early return was added for agents that only need container-based config (OpenCode, Vibe), but it also blocked Codex's config path for standalone/cf-container sessions wherecontainerIDis legitimately empty.Class of bug
Early-return guard that over-broadly gates agent-specific setup — a guard intended for one set of agents (container-dependent agents) inadvertently blocked another agent (Codex) that needs to run its setup regardless of container presence.
Why it wasn't caught
writeAgentStartupConfigwithagentType="openai-codex"andcontainerID=""— all existing Codex tests used container-based paths.containerID == ""early return looked correct in isolation — it only became wrong when Codex's standalone/cf-container support was introduced.SAMEnvFallback(which provides workspace identity vars for standalone sessions) intentionally excludesSAM_MCP_TOKEN, so the missing token wasn't caught by env-var audits.Process fix included in this PR
No new
.claude/rules/changes — the existing rules (02-quality-gates regression test requirements, 10-e2e-verification data flow tracing) would have caught this if applied. The regression tests added in this PR (TestWriteAgentStartupConfigCodexStandaloneWritesMcpConfig,TestWriteAgentStartupConfigNonCodexStandaloneIsNoop) are the primary process fix: they exercise the exact ordering bug at the function level and are proven discriminating (verified to fail on pre-fix code by the task-completion-validator).Post-mortem file
tasks/active/2026-07-25-fix-codex-mcp-bootstrap.mdSpecialist Review Evidence (Required for agent-authored PRs)
Exceptions (If any)
Agent Preflight (Required)
Classification
External References
N/A: No external APIs involved. Fix uses existing codebase patterns (resolveLocalAuthFileTargetPath, generateCodexMcpConfig, mergeManagedCodexMcpConfig).
Codebase Impact Analysis
packages/vm-agent/internal/acp/session_host_startup.go— writeAgentStartupConfig guard reordering, writeCodexStartupConfig branchingpackages/vm-agent/internal/acp/gateway.go— new writeCodexConfigLocally functionDocumentation & Specs
N/A: Internal vm-agent change. No public-facing docs reference the standalone Codex MCP bootstrap path.
Constitution & Risk Check