Skip to content

Codebase intelligence for AI and humans: code health scores, auto-generated docs, git analytics, dead code detection, and architectural decisions via MCP.

fix(suspects): keep git off the MCP stdin pipe so suspects cannot hang (#3888)

Raghav Chamadiya32498c89432c
diff --git a/packages/core/src/repowise/core/suspects/git_text.py b/packages/core/src/repowise/core/suspects/git_text.py
index 6c17a5f23..4cb2ace94 100644
--- a/packages/core/src/repowise/core/suspects/git_text.py
+++ b/packages/core/src/repowise/core/suspects/git_text.py
@@ -19,6 +19,8 @@ import subprocess
from collections.abc import Iterable
from pathlib import Path
+from repowise.core.analysis import git_cli
+
MAX_DIFF_FILES = 100
_BATCH = 100
_HUNK_RE = re.compile(r"^@@ [^@]+ @@ ?(.*)$", re.MULTILINE)
@@ -39,11 +41,8 @@ def strip_person_trailers(body: str) -> str:
def _git(repo: Path, *args: str) -> str | None:
"""Stdout, or ``None`` when git fails (one unknown sha fails the whole call)."""
try:
- return subprocess.run(
- ["git", "-C", str(repo), *args],
- capture_output=True, text=True, encoding="utf-8", errors="replace", check=True,
- ).stdout
- except (OSError, subprocess.CalledProcessError):
+ return git_cli._git(list(args), str(repo))
+ except (OSError, subprocess.SubprocessError):
return None
diff --git a/packages/core/src/repowise/core/suspects/index.py b/packages/core/src/repowise/core/suspects/index.py
index d7cc34196..5c1d4ba2d 100644
--- a/packages/core/src/repowise/core/suspects/index.py
+++ b/packages/core/src/repowise/core/suspects/index.py
@@ -14,14 +14,13 @@ from __future__ import annotations
import asyncio
import json
-import subprocess
from datetime import UTC, datetime, timedelta
from pathlib import Path
from typing import Any
from repowise.core.fts_query import meaningful_terms
-from .git_text import read_change_texts
+from .git_text import _git, read_change_texts
from .rank import Candidate, SuspectContext, Symptom, prepare, rank_suspects
#: The window the measurement used (prereg/suspects.md): 14 days before the symptom.
@@ -39,14 +38,7 @@ def _aware(value: datetime) -> datetime:
def _tracked_files(repo_path: Path) -> frozenset[str]:
- try:
- out = subprocess.run(
- ["git", "-C", str(repo_path), "ls-files"],
- capture_output=True, text=True, encoding="utf-8", errors="replace", check=True,
- ).stdout
- except (OSError, subprocess.CalledProcessError):
- return frozenset()
- return frozenset(out.splitlines())
+ return frozenset((_git(repo_path, "ls-files") or "").splitlines())
async def _imports(session: Any, repo_id: str) -> dict[str, set[str]]:
diff --git a/tests/unit/test_suspects.py b/tests/unit/test_suspects.py
index a27cf6ef9..1da8ad385 100644
--- a/tests/unit/test_suspects.py
+++ b/tests/unit/test_suspects.py
@@ -137,6 +137,23 @@ def test_person_trailers_never_reach_the_text(tmp_path):
assert "Ann" not in got[head][0] and "Bob" not in got[head][0]
+def test_git_never_inherits_stdin_and_cannot_hang(monkeypatch, tmp_path):
+ # Under the stdio MCP server on Windows an inherited stdin pipe blocks git.
+ import subprocess
+
+ from repowise.core.suspects import git_text
+
+ seen = {}
+
+ def fake_run(argv, **kw):
+ seen.update(kw)
+ raise subprocess.TimeoutExpired(argv, kw["timeout"])
+
+ monkeypatch.setattr(git_text.subprocess, "run", fake_run)
+ assert git_text._git(tmp_path, "ls-files") is None
+ assert seen["stdin"] is subprocess.DEVNULL and seen["timeout"] > 0
+
+
def test_text_evidence_skips_filler_and_the_repo_name_but_is_never_empty():
cands = [
Candidate("a", "repowise shows the invoice total", NOW, ("billing/invoice.py",)),