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(ingestion): make the per-file git-index timeout generous and configurable (#1837)

Nehal K452c962b839f
diff --git a/packages/core/src/repowise/core/ingestion/git_indexer/_constants.py b/packages/core/src/repowise/core/ingestion/git_indexer/_constants.py
index 3d14f5789..c19aaab63 100644
--- a/packages/core/src/repowise/core/ingestion/git_indexer/_constants.py
+++ b/packages/core/src/repowise/core/ingestion/git_indexer/_constants.py
@@ -6,6 +6,8 @@ the commit-depth defaults, decay half-lives, and skip heuristics.
from __future__ import annotations
+import math
+import os
import re
from typing import Any
@@ -382,4 +384,36 @@ _MAX_BLAME_SIZE_BYTES: int = 100 * 1024 # 100 KB
# Maximum seconds to wait for a single file's git indexing. If exceeded the
# file is recorded with whatever data was collected before the timeout and the
# semaphore slot is released so other files can proceed.
-_FILE_INDEX_TIMEOUT_SECS: float = 45.0
+#
+# The default is deliberately generous: a first full index of a large
+# repository can run several slow git subprocesses per file (log, blame,
+# renames), and a premature fire here would silently record partial data for
+# files that were simply still working. Override per-repo or per-machine
+# with ``REPOWISE_GIT_INDEX_TIMEOUT_S`` (a positive float, seconds).
+_FILE_INDEX_TIMEOUT_SECS_ENV = "REPOWISE_GIT_INDEX_TIMEOUT_S"
+_FILE_INDEX_TIMEOUT_SECS_DEFAULT: float = 120.0
+
+
+def _resolve_file_index_timeout() -> float:
+ """Seconds one file's git indexing may take, from env or the default.
+
+ An unparseable or non-positive value keeps the default rather than
+ silently dropping the budget (matching the other ``REPOWISE_*_TIMEOUT_S``
+ resolvers in the codebase).
+ """
+ raw = os.environ.get(_FILE_INDEX_TIMEOUT_SECS_ENV, "").strip()
+ if not raw:
+ return _FILE_INDEX_TIMEOUT_SECS_DEFAULT
+ try:
+ seconds = float(raw)
+ except ValueError:
+ seconds = float("nan")
+ # NaN and inf both fail ``isfinite``/``> 0``, so they land on the default
+ # rather than on a budget asyncio.wait_for would treat as already expired
+ # (or one it would never fire at all).
+ if not math.isfinite(seconds) or not seconds > 0:
+ return _FILE_INDEX_TIMEOUT_SECS_DEFAULT
+ return seconds
+
+
+_FILE_INDEX_TIMEOUT_SECS: float = _resolve_file_index_timeout()
diff --git a/tests/unit/ingestion/test_git_index_timeout.py b/tests/unit/ingestion/test_git_index_timeout.py
new file mode 100644
index 000000000..731b43a84
--- /dev/null
+++ b/tests/unit/ingestion/test_git_index_timeout.py
@@ -0,0 +1,42 @@
+"""Unit tests for the git-index file timeout resolver.
+
+The per-file git indexing timeout must not fire early on a legitimately
+long first-time index of a large repository. It is therefore configurable
+via ``REPOWISE_GIT_INDEX_TIMEOUT_S`` and defaults generously.
+"""
+
+from __future__ import annotations
+
+import importlib
+from collections.abc import Iterator
+
+import pytest
+
+import repowise.core.ingestion.git_indexer._constants as constants
+
+
[email protected](autouse=True)
+def _reset_env(monkeypatch: pytest.MonkeyPatch) -> Iterator[None]:
+ """Clear the override between tests and reload the module constants."""
+ monkeypatch.delenv("REPOWISE_GIT_INDEX_TIMEOUT_S", raising=False)
+ yield
+ importlib.reload(constants)
+
+
+def test_default_timeout_is_generous() -> None:
+ assert constants._FILE_INDEX_TIMEOUT_SECS == 120.0
+
+
+def test_env_override_is_honoured(monkeypatch: pytest.MonkeyPatch) -> None:
+ monkeypatch.setenv("REPOWISE_GIT_INDEX_TIMEOUT_S", "300")
+ importlib.reload(constants)
+ assert constants._FILE_INDEX_TIMEOUT_SECS == 300.0
+
+
[email protected]("bad", ["abc", "0", "-5", " ", "nan", "inf"])
+def test_bad_env_value_falls_back_to_default(
+ monkeypatch: pytest.MonkeyPatch, bad: str
+) -> None:
+ monkeypatch.setenv("REPOWISE_GIT_INDEX_TIMEOUT_S", bad)
+ importlib.reload(constants)
+ assert constants._FILE_INDEX_TIMEOUT_SECS == 120.0