Skip to content

fix(mcp): prevent PR tools from timing out on stdio transport - #3339

Closed
hopstreax wants to merge 1 commit into
Graphify-Labs:v8from
hopstreax:fix/3318-mcp-stdio-pr-timeout
Closed

hopstreax wants to merge 1 commit into
Graphify-Labs:v8from
hopstreax:fix/3318-mcp-stdio-pr-timeout

Conversation

@hopstreax

Copy link
Copy Markdown
Contributor

Summary

Fixes #3318.

PR-related MCP tools (list_prs, triage_prs, and get_pr_impact) could time out when Graphify was running over the stdio transport.

The MCP server replaces stdin with a pipe that remains open for the lifetime of the process. PR-related git/gh subprocesses inherited that stdin, and Git for Windows could block while inspecting the handle. This caused the subprocess timeouts to cascade into MCP client request timeouts.

This PR also fixes an independent gh repo view argument bug where --repo was incorrectly used even though gh repo view expects the repository as a positional argument.

Changes

  • Pass stdin=subprocess.DEVNULL to non-interactive PR subprocesses:

    • _gh
    • _detect_default_branch Git fallback
    • fetch_pr_files
    • fetch_worktrees
  • Fix gh repo view to pass the repository positionally.

  • Prevent an explicitly supplied remote repo from falling back to the local repository's Git branch.

  • Add regression tests for stdin isolation and repository argument handling.

Why

Before this fix, list_prs could follow this timeout chain:

_detect_default_branch
  → gh repo view       30s timeout
  → git symbolic-ref    5s timeout

fetch_prs
  → gh pr list         30s timeout

≈ 65s total → MCP client request timeout

The issue was specific to the MCP stdio process environment. gh authentication and network access were working normally.

With child stdin redirected to DEVNULL, the PR tools no longer inherit the MCP transport's open stdin pipe.

Verification

  • pytest tests/test_prs.py → 52 passed
  • pytest tests/test_serve_http.py tests/test_serve.py → 146 passed, 1 skipped
  • git diff --check → clean

No changes were made to serve.py, export.py, or unrelated subprocess paths.

@graphify-labs graphify-labs 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.

Graphify reviewed this change.

Looks safe to merge — no coupling regressions and no blocking issues, checked against the code graph (not a self-assessment).

Formal verification. 4 change(s) tested, no difference found (not proven).


Graphify review — findings

Isolates every subprocess in prs.py with stdin=subprocess.DEVNULL so gh/git calls never inherit and block on the MCP stdio server's open stdin pipe. Fixes _detect_default_branch to pass an explicit repo positionally to gh repo view instead of the invalid --repo flag, and skips the local git symbolic-ref fallback entirely when an explicit repo is given, returning "main" rather than reading the current working directory's branch.

No blocking issues surfaced.

Analysis details — impact, health, verification

Impact & health

Graphify review

Impact — 324 functions depend on the 122 functions this change touches.

Health — this change adds coupling hotspots:

  • new: dispatch_command() — 2 callers, 123 callees
  • new: _build_server() — 2 callers, 16 callees
  • new: cmd_prs() — 2 callers, 12 callees
  • new: _status_color() — 4 callers, 5 callees
  • new: fetch_prs() — 5 callers, 4 callees
  • new: _main() — 4 callers, 3 callees
  • new: render_dashboard() — 1 callers, 10 callees
  • new: render_pr_detail() — 1 callers, 8 callees
  • …and 5 more — each is listed as a finding

Verification — 324 functions in the blast radius were not formally verified this run (proofs are advisory here).

Gate & verification

graphify gate

PASS — objectively clean (no health regressions, tests not run — proofs not run this pass (advisory)). Grounded, not self-assessed.

Advisory (not blocking):

  • verification_scope: 136 function(s) in the blast radius were not formally verified this run

Formal verification

No difference found (not proven): No behavior difference found in \_detect\_default\_branch (not a proof).

The verifier ran both versions of \_detect\_default\_branch on many inputs and saw identical behavior every time. Strong evidence the change is safe, but evidence, not a proof.

Guarantee: Empirical: differential testing (both versions run on many generated inputs). A divergence on an untested input remains possible, so this is 'no counterexample found', not 'proven equivalent'.

Note: An input the sampler did not try could still differ.

No difference found (not proven): No behavior difference found in fetch\_pr\_files (not a proof).

The verifier ran both versions of fetch\_pr\_files on many inputs and saw identical behavior every time. Strong evidence the change is safe, but evidence, not a proof.

Guarantee: Empirical: differential testing (both versions run on many generated inputs). A divergence on an untested input remains possible, so this is 'no counterexample found', not 'proven equivalent'.

Note: An input the sampler did not try could still differ.

No difference found (not proven): No behavior difference found in fetch\_worktrees (not a proof).

The verifier ran both versions of fetch\_worktrees on many inputs and saw identical behavior every time. Strong evidence the change is safe, but evidence, not a proof.

Guarantee: Empirical: differential testing (both versions run on many generated inputs). A divergence on an untested input remains possible, so this is 'no counterexample found', not 'proven equivalent'.

Note: An input the sampler did not try could still differ.

No difference found (not proven): No behavior difference found in \_gh (not a proof).

The verifier ran both versions of \_gh on many inputs and saw identical behavior every time. Strong evidence the change is safe, but evidence, not a proof.

Guarantee: Empirical: differential testing (both versions run on many generated inputs). A divergence on an untested input remains possible, so this is 'no counterexample found', not 'proven equivalent'.

Note: An input the sampler did not try could still differ.

· 13 more finding(s) on lines outside this diff (see the check run).

@safishamsi

Copy link
Copy Markdown
Member

Shipped in v0.9.55 — landed on v8 via cherry-pick with your authorship preserved. Thanks @hopstreax — the MCP prs tools no longer hang the stdio transport (subprocess stdin detached). Release: https://github.com/Graphify-Labs/graphify/releases/tag/v0.9.55

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.

MCP stdio server: PR tools time out because children inherit the never-EOF stdin pipe and git blocks on it (+ gh repo view --repo is not a valid flag)

2 participants