Skip to content

fix(codex-migration): three bugs in codex config.toml generation (#26250) - #26259

Closed
zccyman wants to merge 0 commit into
NousResearch:mainfrom
atyou2happy:fix/codex-migration-three-bugs-26250
Closed

fix(codex-migration): three bugs in codex config.toml generation (#26250)#26259
zccyman wants to merge 0 commit into
NousResearch:mainfrom
atyou2happy:fix/codex-migration-three-bugs-26250

Conversation

@zccyman

@zccyman zccyman commented May 15, 2026

Copy link
Copy Markdown
Contributor

Summary

Fixes three independent bugs in codex_runtime_plugin_migration.py that combine to produce a ~/.codex/config.toml that codex refuses to load with duplicate key errors.

Closes #26250

Bug A — default_permissions inside open [mcp_servers.*] table scope

Root cause: render_codex_toml_section() emitted default_permissions inside the managed block. When the block is appended after user-owned [mcp_servers.*] tables, TOML's lexer treats default_permissions = ":workspace" as a key of the most-recent table header. On re-migration, the duplicate key triggers codex's strict Toml parser.

Fix: Move default_permissions emission to the top of migrate(), prepending it at the very top of the rewritten config — before any table header opens.

Bug B — [plugins."<name>@<marketplace>"] tables duplicated on re-run

Root cause: _strip_existing_managed_block() only removes content between MIGRATION_MARKER and MIGRATION_END_MARKER. Plugin entries written by codex itself (outside the markers) survive the strip. _query_codex_plugins() emits fresh [plugins.X] entries, producing duplicates.

Fix: Add _scan_existing_plugins() that scans the un-managed content for existing [plugins.X] entries. migrate() filters them out before re-emitting.

Bug C — HERMES_HOME from os.environ leaks into user's config

Root cause: _build_hermes_tools_mcp_entry() burns HERMES_HOME and PYTHONPATH from os.environ into the [mcp_servers.hermes-tools] env dict. This persists stale paths (e.g. a long-deleted pytest tempdir or old profile path) into the user's ~/.codex/config.toml.

Fix: Remove HERMES_HOME and PYTHONPATH from the rendered env dict. The MCP subprocess inherits the parent's environment when codex spawns it — no need to hardcode at migrate-time.

Files Changed

File Change
hermes_cli/codex_runtime_plugin_migration.py +86, −28

Test Results

tests/hermes_cli/test_codex_runtime_plugin_migration.py ... 56 passed

Design Decisions

  1. Bug A: prepend at file-top vs. wrap in [hermes] table — TOML's default_permissions is a top-level key. Wrapping it in [hermes] would break codex's schema. Prepend before any table header is the only scope-safe approach.
  2. Bug B: scan-and-filter vs. own the namespace — Stripping ALL [plugins.*] from the file would delete user-managed codex plugins. Scan-and-filter is safer.
  3. Bug C: remove entirely vs. resolve at runtime — The MCP server entry doesn't need HERMES_HOME/PYTHONPATH because codex spawns it as a subprocess that inherits the active environment.

@alt-glitch alt-glitch added type/bug Something isn't working comp/cli CLI entry point, hermes_cli/, setup wizard P2 Medium — degraded but workaround exists labels May 15, 2026
NishantEC

This comment was marked as outdated.

@zccyman

zccyman commented May 15, 2026

Copy link
Copy Markdown
Contributor Author

Thanks @NishantEC for taking a look! 🙏

@zccyman zccyman closed this May 18, 2026
@zccyman
zccyman force-pushed the fix/codex-migration-three-bugs-26250 branch from 40a487a to 43e566f Compare May 18, 2026 00:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

comp/cli CLI entry point, hermes_cli/, setup wizard P2 Medium — degraded but workaround exists type/bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

hermes codex-runtime migrate produces invalid ~/.codex/config.toml (duplicate keys, scoped default_permissions, leaked HERMES_HOME)

3 participants