Skip to content

fix(codex): broaden context7 config checks#1000

Merged
affaan-m merged 1 commit intomainfrom
fix/codex-context7-compat-tests
Mar 29, 2026
Merged

fix(codex): broaden context7 config checks#1000
affaan-m merged 1 commit intomainfrom
fix/codex-context7-compat-tests

Conversation

@affaan-m
Copy link
Copy Markdown
Owner

@affaan-m affaan-m commented Mar 29, 2026

Summary

  • accept either mcp_servers.context7 or mcp_servers.context7-mcp in the global Codex sanity check
  • document the repo expectation that Codex multi-agent is enabled and wired to the sample role files
  • add regression tests for the role wiring and the legacy-context7 compatibility path

Testing

  • npm install --ignore-scripts --silent
  • node tests/codex-config.test.js
  • node tests/scripts/codex-hooks.test.js

Supersedes the remaining relevant parts of #860.


Summary by cubic

Broadened Codex sanity checks to accept both mcp_servers.context7 and mcp_servers.context7-mcp, and clarified that multi‑agent is enabled by default. Added regression tests to validate role wiring and legacy context7 compatibility, plus safer hook path handling.

  • Bug Fixes

    • check-codex-global-state.sh now succeeds with either mcp_servers.context7 or mcp_servers.context7-mcp, and warns if both are present.
    • .codex/config.toml documents multi‑agent as on by default and clarifies local role mapping.
  • Refactors

    • Tests: verify multi‑agent is enabled and sample roles are referenced; ensure legacy [mcp_servers.context7] passes sync and global checks.
    • Script tests: handle quoted hook paths safely and invoke bash scripts with direct argv (no Windows path mangling).

Written for commit 0ebcfc3. Summary will update on new commits.

Summary by CodeRabbit

  • New Features

    • Multi-agent collaboration is now stable and enabled by default.
  • Bug Fixes

    • Improved handling of MCP configuration sections to support both legacy and current naming conventions, with enhanced validation and warnings for misconfigurations.

@ecc-tools
Copy link
Copy Markdown
Contributor

ecc-tools bot commented Mar 29, 2026

Analyzing 5000 commits...

@affaan-m affaan-m merged commit 527c793 into main Mar 29, 2026
5 of 39 checks passed
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai bot commented Mar 29, 2026

Caution

Review failed

The pull request is closed.

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 3b7b04da-900b-42e2-a846-528cd7fd08b8

📥 Commits

Reviewing files that changed from the base of the PR and between bec1ebf and 0ebcfc3.

📒 Files selected for processing (4)
  • .codex/config.toml
  • scripts/codex/check-codex-global-state.sh
  • tests/codex-config.test.js
  • tests/scripts/codex-hooks.test.js

📝 Walkthrough

Walkthrough

This PR updates Codex configuration documentation and validation logic to support both legacy and current MCP server section naming conventions while marking multi-agent collaboration as stable. Configuration changes document role-specific agent setup, and script validation logic now handles dual naming support with improved error reporting.

Changes

Cohort / File(s) Summary
Configuration Updates
.codex/config.toml
Marked multi-agent collaboration as stable with added inline comments documenting role limits and mapping to agent configuration files (agents/*.toml).
MCP Section Validation
scripts/codex/check-codex-global-state.sh
Enhanced validation to track legacy mcp_servers.context7 and current mcp_servers.context7-mcp sections via separate boolean flags; now fails when neither exists, succeeds when either exists, and warns when both coexist.
Config Test Coverage
tests/codex-config.test.js
Added helper functions escapeRegExp and getTomlSection to extract TOML sections; added test cases validating multi_agent = true and role config file references for explorer, reviewer, and docs-researcher roles.
Hook Integration Tests
tests/scripts/codex-hooks.test.js
Removed static eval "$*" detection and toBashPath() platform-specific path conversion; simplified path handling and added test case for legacy context7 MCP server section compatibility with check-codex-global-state.sh.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~22 minutes

Possibly related PRs

Poem

🐰 The codex hops with agents true,
Legacy and new both in view,
Config marks the path so clear,
Multi-agent loops, stability's here! ✨

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/codex-context7-compat-tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@ecc-tools
Copy link
Copy Markdown
Contributor

ecc-tools bot commented Mar 29, 2026

Analysis Failed

Not Found - https://docs.github.com/rest/git/refs#get-a-reference

Troubleshooting
Cause Resolution
Large repository Analysis may timeout on repos with extensive history
API rate limits Wait 15 minutes before retrying
Network issues Queue timeout is 15 minutes; retry may succeed
Permissions Verify app has Contents: Read access

Retry: /ecc-tools analyze


Report Issue | ECC Tools

@greptile-apps
Copy link
Copy Markdown
Contributor

greptile-apps bot commented Mar 29, 2026

Greptile Summary

This PR broadens the Codex global sanity check to accept either [mcp_servers.context7] or [mcp_servers.context7-mcp] (instead of only treating context7-mcp as a warn-level legacy entry), adds a documentation block for the multi-agent agents table in config.toml, and ships new tests for multi_agent wiring and the compatibility path.

Two issues need to be resolved before merging:

  • Duplicate [agents] header in .codex/config.toml — the [agents] section key appears twice in a row (lines 104–105). The TOML spec prohibits redefining a table; strict parsers will reject the file outright.
  • Residual hard-fail for mcp_servers.context7 in the loopcheck-codex-global-state.sh still iterates over 'mcp_servers.context7' as a mandatory section. A user whose global config only contains [mcp_servers.context7-mcp] (the exact legacy case this PR targets) will still hit fail \"MCP section [mcp_servers.context7] missing\" and see the script exit 1. The new OR-check added below the loop cannot override that earlier failure.
  • Additionally, the variable names has_context7_legacy / has_context7_current are semantically reversed relative to which name is canonical, and the new integration test only exercises the canonical-name path rather than the legacy context7-mcp path it is meant to guard.

Confidence Score: 4/5

Not safe to merge as-is: the duplicate TOML header breaks spec compliance and the loop still hard-fails for context7-mcp-only configs, leaving the PR's primary goal unmet.

Two P1 issues remain: a duplicate TOML table header that strict parsers will reject, and a logical gap where the legacy compatibility path the PR intends to enable still triggers a script failure because the old loop entry for mcp_servers.context7 was not removed. Both are straightforward one-line fixes.

.codex/config.toml (duplicate [agents] header) and scripts/codex/check-codex-global-state.sh (loop still enforces mcp_servers.context7 separately).

Important Files Changed

Filename Overview
.codex/config.toml Updated multi-agent comment and added [agents] documentation block, but introduced a duplicate [agents] TOML table header that violates the TOML spec and will cause parse errors in strict parsers.
scripts/codex/check-codex-global-state.sh Adds an OR-check accepting either context7 or context7-mcp, but the existing loop still hard-requires mcp_servers.context7, so users with only context7-mcp still get a script failure — defeating the PR's main goal.
tests/codex-config.test.js Adds escapeRegExp/getTomlSection helpers and two new tests for multi_agent = true and role-file wiring; logic is sound but depends on the config.toml being valid TOML.
tests/scripts/codex-hooks.test.js Drops Windows toBashPath shim (narrows platform support), adds a legacy-context7 integration test — but the test only exercises the context7 (canonical) name, not the context7-mcp legacy path it is meant to guard.

Flowchart

%%{init: {'theme': 'neutral'}}%%
flowchart TD
    A[check-codex-global-state.sh] --> B{config.toml exists?}
    B -- no --> Z[exit 1]
    B -- yes --> C[Loop: check github / memory / sequential-thinking / context7]
    C -->|context7 missing| D["fail 'MCP section context7 missing' ❌\nfailures++"]
    C -->|all found| E[New OR-check block]
    D --> E
    E --> F{has_context7_legacy=1 OR has_context7_current=1?}
    F -- yes --> G["ok 'context7 or context7-mcp exists' ✅"]
    F -- no --> H["fail 'context7 or context7-mcp missing' ❌"]
    G --> I{failures == 0?}
    H --> I
    D -. failures already > 0 .-> I
    I -- yes --> J[PASS / exit 0]
    I -- no --> K[FAIL / exit 1]
    style D fill:#f88,stroke:#c00
    style H fill:#f88,stroke:#c00
    style G fill:#8f8,stroke:#080
    style J fill:#8f8,stroke:#080
    style K fill:#f88,stroke:#c00
Loading

Comments Outside Diff (1)

  1. scripts/codex/check-codex-global-state.sh, line 102-134 (link)

    P1 Residual loop check defeats the context7-mcp compatibility path

    The loop at lines 102–113 still includes 'mcp_servers.context7' as a hard-required entry. When a user's global config only contains [mcp_servers.context7-mcp] (the "legacy" case the PR is trying to support), the loop emits fail "MCP section [mcp_servers.context7] missing" and increments failures before the new OR-check at lines 126–130 even runs. Because failures > 0 the script ultimately exits 1, which is the exact failure this PR is supposed to fix.

    The new OR-check below the loop passes correctly, but it can never override the earlier hard failure from the loop.

    Fix: remove 'mcp_servers.context7' from the loop (the new block already handles it) so that the loop only enforces the three truly invariant sections:

    for section in \
        'mcp_servers.github' \
        'mcp_servers.memory' \
        'mcp_servers.sequential-thinking'
      do
    

    The combined has_context7_legacy / has_context7_current block immediately after will then be the sole arbiter of the context7 requirement.

Reviews (1): Last reviewed commit: "fix(codex): broaden context7 config chec..." | Re-trigger Greptile

Comment on lines 104 to +105
[agents]
[agents]
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.

P1 Duplicate [agents] TOML table header

The [agents] section header appears twice in a row (lines 104 and 105). The TOML specification prohibits redefining a table; strict TOML parsers (including the reference implementation) will reject this with a parse error such as Cannot define table 'agents': key already defined. Even lenient parsers may silently drop the first definition.

The first [agents] on line 104 should be removed — the comment and the keys (max_threads, max_depth) belong under the single [agents] header.

Suggested change
[agents]
[agents]
[agents]
# Multi-agent role limits and local role definitions.
# These map to `.codex/agents/*.toml` and mirror the repo's explorer/reviewer/docs workflow.
max_threads = 6
max_depth = 1

Comment on lines +115 to +124
has_context7_legacy=0
has_context7_current=0

if rg -n '^\[mcp_servers\.context7\]' "$CONFIG_FILE" >/dev/null 2>&1; then
has_context7_legacy=1
fi

if rg -n '^\[mcp_servers\.context7-mcp\]' "$CONFIG_FILE" >/dev/null 2>&1; then
warn "Legacy [mcp_servers.context7-mcp] exists (context7 is preferred)"
has_context7_current=1
fi
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.

P2 Variable names are semantically reversed

has_context7_legacy is set when [mcp_servers.context7] is found (the canonical/preferred name per the comment on line 48 of config.toml), while has_context7_current is set for [mcp_servers.context7-mcp] (the name that was previously warned as legacy). This is the opposite of what the names suggest, which makes the code harder to maintain. Consider renaming:

  • has_context7_legacyhas_context7 (canonical preferred name)
  • has_context7_currenthas_context7_mcp (old context7-mcp alias)

Comment on lines +73 to +131
if (
test('sync and global sanity checks accept the legacy context7 MCP section', () => {
const homeDir = createTempDir('codex-sync-home-');
const codexDir = path.join(homeDir, '.codex');
const configPath = path.join(codexDir, 'config.toml');
const config = [
'approval_policy = "on-request"',
'sandbox_mode = "workspace-write"',
'web_search = "live"',
'persistent_instructions = ""',
'',
'[features]',
'multi_agent = true',
'',
'[profiles.strict]',
'approval_policy = "on-request"',
'sandbox_mode = "read-only"',
'web_search = "cached"',
'',
'[profiles.yolo]',
'approval_policy = "never"',
'sandbox_mode = "workspace-write"',
'web_search = "live"',
'',
'[mcp_servers.context7]',
'command = "npx"',
'args = ["-y", "@upstash/context7-mcp"]',
'',
'[mcp_servers.github]',
'command = "npx"',
'args = ["-y", "@modelcontextprotocol/server-github"]',
'',
'[mcp_servers.memory]',
'command = "npx"',
'args = ["-y", "@modelcontextprotocol/server-memory"]',
'',
'[mcp_servers.sequential-thinking]',
'command = "npx"',
'args = ["-y", "@modelcontextprotocol/server-sequential-thinking"]',
'',
].join('\n');

try {
fs.mkdirSync(codexDir, { recursive: true });
fs.writeFileSync(configPath, config);

const syncResult = runBash(syncScript, [], { HOME: homeDir, CODEX_HOME: codexDir });
assert.strictEqual(syncResult.status, 0, syncResult.stderr || syncResult.stdout);

const checkResult = runBash(checkScript, [], { HOME: homeDir, CODEX_HOME: codexDir });
assert.strictEqual(checkResult.status, 0, checkResult.stderr || checkResult.stdout);
assert.match(checkResult.stdout, /MCP section \[mcp_servers\.context7\] or \[mcp_servers\.context7-mcp\] exists/);
} finally {
cleanup(homeDir);
}
})
)
passed++;
else failed++;
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.

P2 Test only covers context7 (canonical name), not the context7-mcp legacy path

The PR description says the goal is to accept either mcp_servers.context7 or mcp_servers.context7-mcp. The new test config on line 97 uses [mcp_servers.context7] (the canonical name), which already passed before this PR. The regression case — a user whose global config only has [mcp_servers.context7-mcp] — is never exercised, so the test would pass even with the broken loop logic described above.

Adding a second sub-test (or a separate test case) that writes a config with only [mcp_servers.context7-mcp] and asserts the check script exits 0 would make this a true regression guard.

Copy link
Copy Markdown
Contributor

@cubic-dev-ai cubic-dev-ai bot left a comment

Choose a reason for hiding this comment

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

3 issues found across 4 files

Prompt for AI agents (unresolved issues)

Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.


<file name=".codex/config.toml">

<violation number="1" location=".codex/config.toml:105">
P1: Duplicate `[agents]` table declaration makes the TOML invalid and breaks config parsing.</violation>
</file>

<file name="tests/scripts/codex-hooks.test.js">

<violation number="1" location="tests/scripts/codex-hooks.test.js:37">
P2: Normalize `scriptPath` before invoking bash; passing raw OS paths here can break bash-based tests on win32.</violation>
</file>

<file name="scripts/codex/check-codex-global-state.sh">

<violation number="1" location="scripts/codex/check-codex-global-state.sh:126">
P1: The new context7 compatibility block is ineffective because `[mcp_servers.context7]` is still required earlier, so legacy-only `[mcp_servers.context7-mcp]` configs still fail.</violation>
</file>

Reply with feedback, questions, or to request a fix. Tag @cubic-dev-ai to re-run a review.

Comment on lines +105 to +106
[agents]
# Multi-agent role limits and local role definitions.
Copy link
Copy Markdown
Contributor

@cubic-dev-ai cubic-dev-ai bot Mar 29, 2026

Choose a reason for hiding this comment

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

P1: Duplicate [agents] table declaration makes the TOML invalid and breaks config parsing.

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At .codex/config.toml, line 105:

<comment>Duplicate `[agents]` table declaration makes the TOML invalid and breaks config parsing.</comment>

<file context>
@@ -101,6 +102,9 @@ sandbox_mode = "workspace-write"
 web_search = "live"
 
 [agents]
+[agents]
+# Multi-agent role limits and local role definitions.
+# These map to `.codex/agents/*.toml` and mirror the repo's explorer/reviewer/docs workflow.
</file context>
Suggested change
[agents]
# Multi-agent role limits and local role definitions.
# Multi-agent role limits and local role definitions.
Fix with Cubic

has_context7_current=1
fi

if [[ "$has_context7_legacy" -eq 1 || "$has_context7_current" -eq 1 ]]; then
Copy link
Copy Markdown
Contributor

@cubic-dev-ai cubic-dev-ai bot Mar 29, 2026

Choose a reason for hiding this comment

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

P1: The new context7 compatibility block is ineffective because [mcp_servers.context7] is still required earlier, so legacy-only [mcp_servers.context7-mcp] configs still fail.

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At scripts/codex/check-codex-global-state.sh, line 126:

<comment>The new context7 compatibility block is ineffective because `[mcp_servers.context7]` is still required earlier, so legacy-only `[mcp_servers.context7-mcp]` configs still fail.</comment>

<file context>
@@ -112,10 +112,25 @@ if [[ -f "$CONFIG_FILE" ]]; then
+    has_context7_current=1
+  fi
+
+  if [[ "$has_context7_legacy" -eq 1 || "$has_context7_current" -eq 1 ]]; then
+    ok "MCP section [mcp_servers.context7] or [mcp_servers.context7-mcp] exists"
   else
</file context>
Fix with Cubic


function runBash(scriptPath, args = [], env = {}, cwd = repoRoot) {
return spawnSync('bash', [toBashPath(scriptPath), ...args], {
return spawnSync('bash', [scriptPath, ...args], {
Copy link
Copy Markdown
Contributor

@cubic-dev-ai cubic-dev-ai bot Mar 29, 2026

Choose a reason for hiding this comment

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

P2: Normalize scriptPath before invoking bash; passing raw OS paths here can break bash-based tests on win32.

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At tests/scripts/codex-hooks.test.js, line 37:

<comment>Normalize `scriptPath` before invoking bash; passing raw OS paths here can break bash-based tests on win32.</comment>

<file context>
@@ -32,50 +33,30 @@ function cleanup(dirPath) {
-
 function runBash(scriptPath, args = [], env = {}, cwd = repoRoot) {
-  return spawnSync('bash', [toBashPath(scriptPath), ...args], {
+  return spawnSync('bash', [scriptPath, ...args], {
     cwd,
     env: {
</file context>
Suggested change
return spawnSync('bash', [scriptPath, ...args], {
const bashScriptPath = process.platform === 'win32'
? String(scriptPath).replace(/^([A-Za-z]):/, (_, driveLetter) => `/${driveLetter.toLowerCase()}`).replace(/\\/g, '/')
: scriptPath;
return spawnSync('bash', [bashScriptPath, ...args], {
Fix with Cubic

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