Skip to content

fix(mcp): don't hand git the server's stdin in _git_head - #4441

Closed
bercedev wants to merge 1 commit into
Graphify-Labs:v8from
bercedev:fix/mcp-git-stdin
Closed

bercedev wants to merge 1 commit into
Graphify-Labs:v8from
bercedev:fix/mcp-git-stdin

Conversation

@bercedev

Copy link
Copy Markdown
Contributor

What does this PR do?

Fixes #4440.

graph_stats asks git for HEAD so it can say whether the graph is stale. _git_head ran git rev-parse HEAD without stdin=, so the child inherited the server's stdin, which under an MCP stdio host is the protocol pipe. On Windows git blocks on that pipe: the call sits on the 3s timeout and the staleness line loses its HEAD comparison, or it hangs outright under Claude Code.

prs.py already passes stdin=subprocess.DEVNULL to every gh/git call (#3318). The two _git_head copies in export.py and watch.py were missed, so this adds it there.

I went through the other subprocess calls in graphify/. export._git_head is the only unguarded one a tool handler reaches (serve.py imports it for graph_stats). watch._git_head is the same function for the CLI path, so I changed it too rather than leave the two copies different.

Type of change

  • Bug fix
  • New feature
  • Documentation
  • Tests or CI
  • Refactor
  • Security fix

Verification & Invariants

Invariant: a subprocess started by the server never inherits the MCP stdio pipe.

  • Read the CONTRIBUTING.md guide.
  • Reproduced the issue and identified the invariant.
  • Made the smallest fix necessary.
  • Added a regression test (if bug fix) or isolated boundary test.
  • Kept the PR description synchronized with the final implementation.
  • Documented any limitations / unsupported cases explicitly.

Limitation: I don't have a Windows machine, so I did not reproduce the hang. On Linux git doesn't block on that pipe. The test pins the argument, the same way TestSubprocessStdinIsolation does for prs.py.

How was this tested?

# without the fix
uv run --frozen pytest tests/test_git_head_stdin.py -q
2 failed

# with the fix
uv run --frozen pytest tests/test_git_head_stdin.py tests/test_watch_manifest_location.py tests/test_serve_http.py tests/test_prs.py -q
74 passed, 1 skipped

uv run --frozen pytest -q
7685 passed, 184 skipped

Linux, Python from the repo's uv.lock.

Graphify-specific checklist

  • I updated generated skill artifacts (uv run python -m tools.skillgen --bless) when changing their source fragments.
  • I confirmed that AST/structural extraction remains deterministic (no ambient state dependencies like ENV variables).
  • I reviewed changes for security implications (no unsafe interpolation into shell/Python).
  • I confirmed no API keys or local-only graph data are included.
  • (If applicable) I disclosed AI authorship in my commit messages.

Note: I used Claude Code while working on this fix. I reviewed and ran all of it myself.

…bs#4440)

graph_stats asks git for HEAD to report staleness. The child inherited the
MCP stdio pipe, and on Windows git blocks on it: the call sat on the 3s
timeout, or hung under Claude Code. prs.py already isolates stdin (Graphify-Labs#3318);
these two _git_head copies were missed.
@bercedev
bercedev requested a review from safishamsi as a code owner October 13, 2026 22:11
@github-actions github-actions Bot added the contributor Pull request from a returning community contributor label Oct 13, 2026
@github-actions

Copy link
Copy Markdown

Thanks for the pull request, @bercedev. A maintainer will review it soon.

Want to talk it through while it is in review? Come join us on our Discord server. For longer-form discussion there is also GitHub Discussions.

A couple of things that speed up review: make sure the test suite passes on Python 3.10 and 3.13, and that the change keeps extraction deterministic.

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

Code graph out of date: Health delta baseline: last indexed commit e8eb76e, 18 commit(s) behind this PR's base. Impact and hotspot numbers below may be wrong.

No verdict: the code graph is out of date. Static checks found no blocking issues, but they compared against an outdated graph. The next push after the repository re-indexes gets a full review.

Not checked: tests were not run; formal verification proved 0 of 2 changed function(s) (1 sampled, not proven, 1 not verified).

Formal verification. PR-changed functions: 1/2 verified (0 proven, 1 may-equivalent, 0 distinguished) · 1 not verified (1 unsupported).

Not verified on this run: \_git\_head (unsupported).


Graphify review — findings

Fixes _git_head in both export and watch so git rev-parse HEAD runs with stdin=DEVNULL instead of inheriting the caller's stdin. Under an MCP stdio host on Windows, that inherited protocol pipe blocks git, so graph_stats no longer stalls on the 3-second timeout or hangs. A parametrized test asserts both modules pass DEVNULL.

No blocking issues surfaced.

Analysis details — impact, health, verification

Impact & health

Graphify review

Impact — 847 functions depend on the 144 functions this change touches.

Health — grade A; 10 existing hotspot(s) in the area this change touches (pre-existing, not introduced here):

  • _rebuild_code() — 177 callers, 59 callees (high)
  • to_json() — 77 callers, 10 callees (high)
  • to_obsidian() — 41 callers, 14 callees (high)
  • main() — 110 callers, 3 callees (high)
  • dispatch_command() — 2 callers, 132 callees (high)
  • _make_graph() — 37 callers, 6 callees (high)
  • run_pipeline() — 8 callers, 13 callees (high)
  • to_canvas() — 20 callers, 5 callees (high)
  • …and 2 more

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

Health delta baseline: last indexed commit e8eb76e, 18 commit(s) behind this PR's base.

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: 600 function(s) in the blast radius were not formally verified this run

Test selection

Test selection

53 of 413 test file(s) selected (13%) via static blast radius.

  • tests/test_atomic_canvas_export.py — impact
  • tests/test_atomic_writes.py — impact
  • tests/test_build.py — impact
  • tests/test_cache_stale_import_target.py — impact
  • tests/test_carried_hyperedge_remap.py — impact
  • tests/test_cli_export.py — impact
  • tests/test_community_labels_skill.py — impact
  • tests/test_compact_graph_json.py — impact
  • tests/test_confidence.py — impact
  • tests/test_cross_extension_reexport_self_cycle.py — impact
  • tests/test_dedup_shrink_refuses_force_write.py — impact
  • tests/test_elixir_import_resolution.py — impact
  • tests/test_elixir_qualified_calls.py — impact
  • tests/test_elixir_unqualified_call_scope.py — impact
  • tests/test_export.py — impact
  • tests/test_export_control_characters.py — impact
  • tests/test_export_direction.py — impact
  • tests/test_export_idempotent_writes.py — impact
  • tests/test_export_path_length.py — impact
  • tests/test_external_stub_endpoints.py — impact
  • tests/test_git_head_stdin.py — changed-test
  • tests/test_go_qualified_resolution.py — impact
  • tests/test_god_nodes_exclude_hubs.py — impact
  • tests/test_hyperedge_roundtrip.py — impact
  • tests/test_hypergraph.py — impact
  • tests/test_incremental_unscanned_placeholders.py — impact
  • tests/test_java_member_calls.py — impact
  • tests/test_js_import_resolution.py — impact
  • tests/test_kotlin_grammar.py — impact
  • tests/test_labeling.py — impact
  • tests/test_language_override_lifecycle.py — impact
  • tests/test_lost_saved_semantic_nodes.py — impact
  • tests/test_markdown_code_spans.py — impact
  • tests/test_no_cluster_undeclared_endpoints.py — impact
  • tests/test_obsidian_dangling_member.py — impact
  • tests/test_obsidian_filename_cap.py — impact
  • tests/test_obsidian_unicode_tags.py — impact
  • tests/test_obsidian_vault_migration.py — impact
  • tests/test_pipeline.py — impact
  • tests/test_pr10_watch_overrides.py — impact
  • tests/test_python_inherited_method_calls.py — impact
  • tests/test_python_property_reads.py — impact
  • tests/test_reflect.py — impact
  • tests/test_rust_use_trees.py — impact
  • tests/test_semantic_origin_stamp.py — impact
  • tests/test_serve.py — impact
  • tests/test_serve_http.py — impact
  • tests/test_skill_persisted_scan_options.py — impact
  • tests/test_terraform.py — impact
  • tests/test_terraform_modules.py — impact
  • … and 3 more

Selection is safe under the controlled-regression assumption; always-run tests + a periodic full run are the backstops. Advisory — it never changes the check verdict.

Formal verification

Could not verify: Could not verify \_git\_head.

The verifier did not have enough to check \_git\_head, so it is saying so rather than guessing. No false assurance is the whole point.

Guarantee: No guarantee either way, this is an honest abstention, not a pass.

Note: Reason: no capturable inputs from the test suite; property tier: parameter `cwd` is annotated `'str | Path | None'` — outside the synthesizable primitive/collection set

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

The verifier ran both versions of \_git\_head 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.

safishamsi added a commit that referenced this pull request Oct 14, 2026
Eight community PRs: Windows MCP-stdio hang (#4441), Rust use->declaration
(#4443), JS/TS file-scope callback param shadowing (#4457), sibling-file-id
symbol retention (#4452), TS class-field receiver scoping (#4297), Ollama
/api/chat num_ctx (#4414), cluster label retention on majority overlap (#4451),
and an ingest symlink test fix (#4442). AST cache schema bumped to 16.

Co-Authored-By: Claude Opus 4.8 <[email protected]>
@safishamsi

Copy link
Copy Markdown
Member

Landed in 0.9.91 as 9dfe132 (cherry-picked with your authorship preserved, so it shows on your contributions). Thanks @bercedev! Released to PyPI: https://pypi.org/project/graphifyy/0.9.91/

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

Labels

contributor Pull request from a returning community contributor

Projects

None yet

Development

Successfully merging this pull request may close these issues.

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

2 participants