Skip to content

codex: preserve other MCP servers when writing config - #223

Merged
Desperado merged 1 commit into
mainfrom
Desperado/qmax-code-handoff
Nov 14, 2026
Merged

Desperado merged 1 commit into
mainfrom
Desperado/qmax-code-handoff

Conversation

@Desperado

Copy link
Copy Markdown
Contributor

Summary

qmax-code writes its own [mcp_servers.qmax] entry into ~/.codex/config.toml. The previous line-matching writer could miss quoted or commented headers. It could also treat table-like text inside multiline strings as a table, which risked clobbering a user's other MCP servers or settings.

This PR switches to TOML parsing:

  • Only qmax's table range is replaced. Every other server, setting and comment is kept byte-for-byte.
  • Quoted ([mcp_servers."qmax"], [ 'mcp_servers' . 'qmax' ]) and commented headers are detected.
  • Invalid TOML, unreadable files and inline/dotted qmax definitions stop the update instead of rewriting unrelated settings.
  • The file is replaced atomically with owner-only permissions. An existing symlink is followed, not replaced.
  • Error messages never echo configuration values.
  • qmax-code setup detection uses the same parser.

Adds github.com/pelletier/go-toml/v2 (pure Go, no new runtime).

Tests

New internal/agent/codex_config_test.go covers:

  • coexistence with other servers and project tables
  • quoted and commented headers
  • nested qmax settings
  • multiline strings containing table-like text
  • invalid and unsupported layouts
  • read failures, idempotence and symlinks

internal/setup adds coverage for setup detection.

Local runs:

  • go test ./... passed (19 packages)
  • go vet ./... passed
  • go build passed
  • [email protected] run --new-from-rev=origin/main passed (0 issues, run with CGO_ENABLED=0 locally)

Not tested: Windows, or concurrent edits by another process. Updates are not serialized.

Replace line matching in the Codex config writer with TOML parsing so
qmax-code only replaces its own [mcp_servers.qmax] table and keeps every
other server, setting, and comment byte-for-byte.

- Detect quoted (`[mcp_servers."qmax"]`) and commented headers; ignore
  table-like text inside multiline strings.
- Refuse to write invalid TOML, unreadable files, or inline/dotted qmax
  definitions instead of risking unrelated settings.
- Write atomically with owner-only permissions; follow an existing
  symlink rather than replacing it.
- Error messages never include configuration values.
- Setup detection shares the same parser.
@qualitymaxapp

qualitymaxapp Bot commented Nov 14, 2026 •

Copy link
Copy Markdown

QualityMax Review

Verdict: COMMENT · Confidence: evidence-backed scan

Re-review: Open the QualityMax check and select Re-review after it completes.

Files eligible: 7 · Files reviewed: 7 · Files with findings: 0 · Findings: 0 · Inline cards: 0

Priority findings

priority location finding
— — No blocking findings

Review gates

gate status
AI diff review completed · eligible 6, reviewed 6 · MODEL-ONLY findings are advisory · batches reviewed 1 of 1 · LLM · served gemini-3.1-flash-lite
SAST completed · eligible 7, reviewed 7 · hybrid · served claude-haiku-4-5-20251001 · requested qwen3.7-plus
Overall review evidence clean
Inline evidence not needed

Important files

file risk note next step
— — No findings —

Change diagram — Flow

flowchart TD
    Start[Start WriteCodexMCPEntry] --> Lstat{Is Symlink?}
    Lstat -- Yes --> Resolve[Resolve Symlink]
    Resolve --> Read[Read Config File]
    Lstat -- No --> Read
    Read --> Exists{Entry Exists?}
    Exists --> Upsert[Upsert Entry]
    Upsert --> Temp[Create Temp File]
    Temp --> Write[Write Updated Config]
    Write --> Rename[Rename Temp to Path]
    Rename --> End[Return Success]
Loading

Review lifecycle

Use the inline cards to inspect evidence and suggested remediation. Re-run the QualityMax review after pushing a fix; unchanged cards are identified by their stable finding marker. Dismiss with a reason through the existing QualityMax/GitHub review feedback flow. 0 prior card(s) are stale/resolved on this head. @qmax Q&A is tracked separately.

Proof legend: GROUNDED deterministic scanner evidence · MODEL-ONLY advisory model judgment · MODEL-REVIEWED patch model judgment, not reproduction.

QualityMax project results are available in the configured project.

Receipt · commit f6c78c9f3b77e32235650fa7693d2092545a2ebb · run 2026-11-14T20:41:24+00:00 · model served claude-haiku-4-5-20251001, gemini-3.1-flash-lite · model requested qwen3.7-plus, gemini-3.1-flash-lite · model review recorded — 2595 model output tokens · model source repository ai_review_preferences.preferred_model · re-review 2 · proof counts {}

@socket-security

Copy link
Copy Markdown

Review the following changes in direct dependencies. Learn more about Socket for GitHub.

Diff Package Supply Chain
Security
Vulnerability Quality Maintenance License
Addedgithub.com/​pelletier/​go-toml/​v2@​v2.2.498100100100100

View full report

@codecov-commenter

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 89.06250% with 7 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
internal/agent/codex_config.go 88.88% 7 Missing ⚠️

📢 Thoughts on this report? Let us know!

@qualitymaxapp qualitymaxapp 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.

QualityMax Review — canonical overview updated; no inline findings were created for this review.

@qualitymaxapp

qualitymaxapp Bot commented Nov 14, 2026

Copy link
Copy Markdown

QualityMax Code Health

Grade A · 100/100 · PASS — 0 finding(s) in 7 file(s).

No code-health findings.

Full report · Commit f6c78c9

@qualitymaxapp

qualitymaxapp Bot commented Nov 14, 2026

Copy link
Copy Markdown

⚠️ QualityMax Pipeline

Gate Result
🔍 AI diff review ✅ Clean · gemini-3.1-flash-lite · completed · 6 eligible / 6 reviewed · gemini-3.1-flash-lite
🔍 SAST completed · 7 eligible / 7 reviewed · claude-haiku-4-5-20251001
🔍 Canonical PR review delivery completed · 0 eligible / 0 reviewed · exact-head review #5907029234 and overview #6883855753 confirmed
🔍 Repository runtime evidence completed · 0 eligible / 0 reviewed · runtime execution passed for the assessed revision
🔍 Runtime evidence policy completed · 0 eligible / 0 reviewed · admissible runtime evidence satisfies this advisory runtime-only policy
🧪 Repo Tests ✅ 1562/1562 passed (go)
🤖 AI Tests ❌ 51/56 passed (go_test) — 1 issue(s)

Powered by QualityMax — AI-Powered Test Automation

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟡 Changes recommended

The config rewrite deletes unrelated comments, and two tests fail on Windows because of incompatible permission expectations and incomplete home-directory isolation.

3 open issues
What changed in this PR

This PR replaces line-based Codex configuration editing with TOML-aware updates to better protect user settings when registering qmax’s MCP server.

Changes:

  • Parses table names and validates configuration before replacing qmax entries.
  • Adds atomic file replacement, symlink handling, and errors that omit configuration values.
  • Shares parser-based setup detection and adds preservation, failure-handling, and filesystem tests.
File Description
internal/​setup/​orch.go Uses shared parser-based Codex entry detection.
internal/​setup/​orch_test.go Tests quoted headers, multiline strings, and invalid TOML.
internal/​agent/​setup_orch_test.go Adapts existing tests to the updated helper signatures.
internal/​agent/​codex_config.go Implements TOML-aware updates and atomic file replacement.
internal/​agent/​codex_config_test.go Adds configuration preservation and filesystem regression tests.
go.sum Records TOML dependency checksums.
go.mod Adds the pure-Go TOML parser dependency.

Review effort: Balanced

Comment on lines +104 to 106
if !skip {
out.Write(data[start:offset])
}
if err != nil {
t.Fatal(err)
}
if info.Mode().Perm() != 0600 {

func TestIsOrchInstalledCodexParsesTables(t *testing.T) {
home := t.TempDir()
t.Setenv("HOME", home)
@Desperado
Desperado merged commit a776d32 into main Nov 14, 2026
7 checks passed
@Desperado
Desperado deleted the Desperado/qmax-code-handoff branch November 14, 2026 21:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants