Skip to content

Windows: graph_stats hangs under MCP hosts — _git_head runs git without stdin=DEVNULL (export.py, watch.py) #4440

Open

Description

@SagitariusAI

Summary

On Windows, the graph_stats MCP tool (and the graphify://stats resource) can hang indefinitely when the server is run by an MCP host such as Claude Code. Root cause: graphify.export._git_head and graphify.watch._git_head run git rev-parse HEAD via subprocess.run(..., capture_output=True, timeout=3) without stdin=, so the git child inherits the server's stdin — the MCP stdio pipe. Under asyncio/libuv hosts that pipe is an overlapped-mode pipe, and git blocks on it.

prs.py already passes stdin=subprocess.DEVNULL to every gh/git call; these two call sites were missed.

Version: graphifyy 0.9.89, mcp 1.30.0, Python 3.12 (uv tool install), Windows 11, Git for Windows.

Observed

  • Under a plain Python mcp client, the 3s timeout fires: graph_stats takes a constant 3.0s and the Built at commit: staleness line silently loses its HEAD comparison (because _git_head returns None). Measured on two graphs (5,497 and 22,709 nodes).
  • Under Claude Code (Windows), the kill-after-timeout never returns: graph_stats hung for 592s until the user interrupted. The host log then shows the correct result arriving as Received a response for an unknown message ID.
  • Only graphs with a built_at_commit trigger it (the git call is skipped otherwise), which initially made it look like a "large graph" problem.
  • With stdin=subprocess.DEVNULL added: 0.03s, and the staleness line is correct (HEAD is fe5410b, graph built at abd900b: graph may be stale).

Reproduction

  1. Build a graph inside a git repo so graph.json carries built_at_commit.
  2. Run graphify-mcp --graph <that>/graph.json as an MCP server from an asyncio-based client on Windows (e.g. mcp.client.stdio.stdio_client).
  3. call_tool("graph_stats", {}) → 3.0s (timeout path). Under Claude Code → hangs.

In-process bisect: calling _git_head() from a plain script in the same interpreter takes 0.03s; the same call inside the running MCP server hits the timeout; injecting stdin=DEVNULL into that subprocess.run makes it 0.03s inside the server too. _filter_blank_stdin is not a factor (same result with it disabled).

Fix (two one-line changes)

--- a/graphify/export.py
+++ b/graphify/export.py
@@ def _git_head(cwd=None):
         r = _sp.run(
-            ["git", "rev-parse", "HEAD"], capture_output=True, text=True, timeout=3,
+            ["git", "rev-parse", "HEAD"], stdin=_sp.DEVNULL, capture_output=True, text=True, timeout=3,
             cwd=str(cwd) if cwd is not None else None,
         )

Same change in graphify/watch.py _git_head. Any other subprocess.run reached from a tool handler without stdin= has the same exposure on Windows.

Related background on the general hazard: python/cpython bpo-44527 and alexalexalex222/frontend-design-loop-mcp#1 (same mechanism: child inherits the MCP stdio pipe, kill after timeout never returns).

Happy to open a PR with the two-line change if useful.

Activity

  1. github-actions commented on Oct 13, 2026

    @github-actions

    Thanks for opening this issue, @SagitariusAI. A maintainer will take a look soon.

    If you would like to discuss it in real time, come say hi on our Discord server. For longer-form questions and ideas there is also GitHub Discussions.

    To help us triage, please make sure the report includes what you expected, what actually happened, and the steps (and a small sample) to reproduce it.

  2. ayushcodes10 commented on Oct 16, 2026

    @ayushcodes10
    Contributor

    Already fixed on v8: commit 9dfe132 (fix(mcp): don't hand git the server's stdin in _git_head (#4440)) adds stdin=subprocess.DEVNULL to both export.py and watch.py's _git_head, matching the two line fix proposed here. Landed via #4441 (closed, not auto linked since it was cherry picked rather than merged through the PR button, same pattern as #2780/#2779, #4413/#4414, and #4435/#4442). Might be worth closing this one too.

  3. omsenjalia commented on Oct 18, 2026

    @omsenjalia
    Contributor

    Fixed on v8 by 9dfe132: _git_head in both export.py and watch.py now passes stdin=subprocess.DEVNULL, and tests/test_git_head_stdin.py covers it (passes on Windows). It was cherry-picked, so the issue didn't close automatically. Safe to close.

  4. omsenjalia commented on Oct 18, 2026

    @omsenjalia
    Contributor

    This looks fixed on the v8 branch by 9dfe1325 (fix(mcp): don't hand git the server's stdin in _git_head (#4440)). Could a maintainer confirm and close?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions