LearnNewsExamplesServices
Frontmatter
titlefix: Add cwd to PullRequestService execAsync calls (#9895)
authortobiu
stateMerged
createdAtApr 11, 2026, 10:15 PM
updatedAtApr 11, 2026, 10:19 PM
closedAtApr 11, 2026, 10:19 PM
mergedAtApr 11, 2026, 10:19 PM
branchesdevagent/9895-pr-service-cwd-fix
urlhttps://github.com/neomjs/neo/pull/9896
Merged
tobiu
tobiu commented on Apr 11, 2026, 10:15 PM

Summary

Resolves #9895

Changes

PullRequestService.mjs — Two-line fix

Added {cwd: aiConfig.projectRoot} to both execAsync calls:

- const {stdout} = await execAsync(`gh pr checkout ${prNumber}`);
+ const {stdout} = await execAsync(`gh pr checkout ${prNumber}`, {cwd: aiConfig.projectRoot});

- const {stdout} = await execAsync(`gh pr diff ${prNumber}`);
+ const {stdout} = await execAsync(`gh pr diff ${prNumber}`, {cwd: aiConfig.projectRoot});

Root Cause

PullRequestService was the only service that didn't pass {cwd} to execAsync. SyncService passes it on all 5 of its calls. When the MCP server process is spawned via stdio transport (e.g., from Antigravity/Gemini CLI), the process CWD can be / rather than the git repo root. gh pr diff and gh pr checkout require being inside a git repository to resolve the PR context.

Verification

Verified live after applying the fix and restarting the MCP server:

  • Before: get_pull_request_diff(9894)GH_CLI_ERROR, exit code 1
  • After: get_pull_request_diff(9894) → ✅ Full diff content returned

Scope

1 file, 2 insertions, 2 deletions. Zero architectural risk.

tobiu
tobiu commented on Apr 11, 2026, 10:17 PM

Input from Claude Opus 4.6 (Antigravity):

❋ # PR Review Summary

Status: Approved

Two-line bug fix with live verification. The PR body is a textbook Fat Ticket — root cause analysis, before/after verification, scope boundary. The fix itself was validated by using the get_pull_request_diff MCP tool to review this very PR, which is a satisfying closed loop.


📊 Evaluation Metrics

  • [ARCH_ALIGNMENT]: 100 - Aligns PullRequestService with the existing SyncService pattern. Uses aiConfig.projectRoot which is already the canonical repo root resolved in config.mjs line 9.
  • [CONTENT_COMPLETENESS]: 95 - PR body documents root cause, verification steps, and scope. The existing JSDoc on getPullRequestDiff and checkoutPullRequest didn't need changes since the cwd option is an internal implementation detail, not API surface. Minor deduction: no inline code comment explaining why cwd is needed (though the git log will carry the Fat Ticket context via squash merge).
  • [EXECUTION_QUALITY]: 100 - Fix is minimal and correct. Verified live with MCP server restart. No side effects — aiConfig.projectRoot is already imported and used throughout the server. Both get_pull_request_diff and get_conversation now work (the latter was already working via GraphQL, not gh CLI).
  • [PRODUCTIVITY]: 100 - Bug discovered, ticketed, fixed, and verified in-session. The MCP server restart verification loop was an efficient strategy.
  • [IMPACT]: 60 - Unblocks get_pull_request_diff and checkout_pull_request MCP tools for all agents operating in headless/stdio environments. Impact is moderate because agents could fall back to gh pr diff via shell (as we did during the #9894 review).
  • [COMPLEXITY]: 5 - Two lines changed. No logic, no branching, no tests needed.
  • [EFFORT_PROFILE]: Quick Win - Textbook quick win. High ROI (unblocks MCP tooling) with near-zero complexity.

🕸️ Context & Graph Linking

  • Target Epic / Issue ID: Resolves #9895
  • Related Graph Nodes: #9894 (PR where the bug was discovered during review), PullRequestService.mjs, SyncService.mjs (reference implementation for the {cwd} pattern), aiConfig.projectRoot

🧠 Graph Ingestion Notes

  • [KB_GAP]: None. The bug was an implementation oversight, not a knowledge gap.
  • [TOOLING_GAP]: The MCP server's get_pull_request_diff tool silently failed with a generic GH_CLI_ERROR without indicating that the root cause was a CWD mismatch. Future improvement: the error handler could detect CWD-related failures and surface a more diagnostic message (e.g., "gh pr diff requires being in a git repository — ensure cwd is set").
  • [RETROSPECTIVE]: This fix validates the "restart-and-verify" workflow for MCP server changes. The user's suggestion to restart Antigravity mid-session to reload MCP servers was the correct verification strategy — it proved the fix works in the actual headless environment, not just from a developer shell. This pattern should be the standard for MCP server bug fixes.

📋 Required Actions

None — approved for merge.