Skip to content

fix(adapters/codex): TOML splice no longer swallows neighboring config#7

Open
JoshKappler wants to merge 1 commit into
coder-company:mainfrom
JoshKappler:fix-codex-toml-splice
Open

fix(adapters/codex): TOML splice no longer swallows neighboring config#7
JoshKappler wants to merge 1 commit into
coder-company:mainfrom
JoshKappler:fix-codex-toml-splice

Conversation

@JoshKappler

Copy link
Copy Markdown

The block-end scan in the codex adapter only recognizes bare [header] lines. A header with an inline comment ([mcp_servers.exa] # search) or an [[array-of-tables]] header below the graphctx block doesn't end it, so uninstall and reinstall delete everything from the graphctx header down to the next bare header. My repro removed a user's [mcp_servers.exa] server, API key included. Two related edges: a user comment on the graphctx header itself makes install append a duplicate [mcp_servers.graphctx] table (invalid TOML, Codex won't parse it), and uninstall leaves [mcp_servers.graphctx.env] subtables behind, which implicitly re-create the server table.

First install is safe (graphctx appends itself last). The trigger is anything added below the block, then an uninstall or a reinstall in place.

Changes:

  • src/adapters/codex/index.ts: replaced the next-header regex with a line-aware scan (tableHeaderKey). It handles leading whitespace, inline comments, [[array]] tables, and CRLF. Uninstall removes the block plus its graphctx.* subtables so nothing orphaned re-creates the server. Reinstall replaces only the main block, so a user's env subtable survives updates. Trailing blank and comment-only lines stay with the following table, so a comment above the user's next server is untouched.
  • test/adapters/codex.test.ts: 7 new tests. Commented next header, [[array-of-tables]], reinstall not swallowing servers below, env subtable removed on uninstall and preserved on reinstall, annotated graphctx header replaced instead of duplicated, CRLF config.
  • README.md + docs/STATUS.md: test count 292 -> 299.

Verification (Windows 11, Node 22):

npx tsc --noEmit                            # clean
npx biome check src test                    # clean
npx vitest run test/adapters/codex.test.ts  # 13/13
npx vitest run                              # 299 tests; same result as main except
                                            # the 12 pre-existing win32 failures
                                            # (fixed in the Windows PR)

Note: all three PRs bump the README/STATUS test counters off the same base (292), so whichever merges second and third will conflict there. I'll rebase the counters as each one lands.

The block-end scan only recognized bare [header] lines, so a header
with an inline comment or an [[array-of-tables]] header below the
graphctx block did not end it: uninstall and re-install deleted
everything up to the next bare header (verified: it removed a user's
[mcp_servers.exa] block including its api_key). The find was equally
strict, so a user comment on our own header made install append a
duplicate [mcp_servers.graphctx] table (invalid TOML). Uninstall also
orphaned [mcp_servers.graphctx.env] subtables, which implicitly
re-create the server table.

- src/adapters/codex/index.ts: replace the next-header regex with a
  line-aware scan (tableHeaderKey): tolerates leading whitespace,
  inline comments, [[array]] tables, and CRLF. Uninstall removes the
  block plus its graphctx.* subtables; re-install replaces only the
  main block so a user's env subtable survives updates. Trailing
  blank and comment-only lines stay with the following table, so a
  user's comment above their next server is untouched.
- test/adapters/codex.test.ts: 7 new tests: commented next header,
  [[array-of-tables]], reinstall not swallowing servers below, env
  subtable removed on uninstall / preserved on reinstall, annotated
  graphctx header replaced not duplicated, CRLF config.
- README.md + docs/STATUS.md: test count 292 -> 299.

Verified: npx tsc --noEmit clean; npx biome check src test clean;
npx vitest run test/adapters/codex.test.ts 13/13; full npx vitest run
299 tests with only the 12 pre-existing win32 failures on this
Windows box (.cmd execFile + AF_UNIX socket, untouched here; same
set fails on unmodified main).
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