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(health): stop knowledge_loss firing on a pure-rename-only commit window (#3075)

Amanbb103e182556
diff --git a/packages/core/src/repowise/core/analysis/health/biomarkers/knowledge_loss.py b/packages/core/src/repowise/core/analysis/health/biomarkers/knowledge_loss.py
index f35aa5968..8ac77554c 100644
--- a/packages/core/src/repowise/core/analysis/health/biomarkers/knowledge_loss.py
+++ b/packages/core/src/repowise/core/analysis/health/biomarkers/knowledge_loss.py
@@ -81,6 +81,15 @@ class KnowledgeLossDetector:
if not primary:
return []
+ # ``recent_owner_commit_pct`` is None when the file's only recent
+ # commits were pure renames: ``_Authors.tally`` skips a rename when
+ # tallying authorship, so there is no authored activity in the window
+ # to judge the owner against, even though ``commit_count_90d`` (which
+ # counts the rename) kept the file out of ``is_stable`` (#2957). A
+ # missing signal is not evidence the owner went quiet.
+ if meta.get("recent_owner_commit_pct") is None:
+ return []
+
recent_share = _as_float(meta.get("recent_owner_commit_pct"))
share = recent_share / 100.0 if recent_share > 1.0 else recent_share
diff --git a/tests/unit/health/test_organizational_biomarkers.py b/tests/unit/health/test_organizational_biomarkers.py
index 32905ba4f..22b4f8ad1 100644
--- a/tests/unit/health/test_organizational_biomarkers.py
+++ b/tests/unit/health/test_organizational_biomarkers.py
@@ -167,6 +167,38 @@ def test_knowledge_loss_skips_without_owner_data():
assert KnowledgeLossDetector().detect(_ctx({"commit_count_90d": 3})) == []
+def test_knowledge_loss_skips_a_pure_rename_with_no_authored_activity():
+ """A file whose only recent commit is a pure rename has no authored
+ activity in the window: ``recent_owner_commit_pct`` is None (#2957), not
+ a real 0% share, so the quiet-owner check must not fire. The rename
+ itself still counts toward ``commit_count_90d``, keeping the file out of
+ ``is_stable`` and past the activity gate."""
+ meta = {
+ "bus_factor": 1,
+ "primary_owner_name": "Alice",
+ "commit_count_90d": 1,
+ "is_hotspot": False,
+ }
+ assert KnowledgeLossDetector().detect(_ctx(meta)) == []
+
+
+def test_knowledge_loss_still_fires_when_someone_else_authored_the_recent_commits():
+ """Contrast with the rename-only case: real authored commits by another
+ person, even a genuine 0% share for the primary owner, still flags the
+ quiet owner."""
+ meta = {
+ "bus_factor": 1,
+ "primary_owner_name": "Alice",
+ "recent_owner_name": "Bob",
+ "recent_owner_commit_pct": 0.0,
+ "commit_count_90d": 2,
+ "is_hotspot": False,
+ }
+ out = KnowledgeLossDetector().detect(_ctx(meta))
+ assert len(out) == 1
+ assert out[0].details["primary_owner"] == "Alice"
+
+
# ---- ownership_risk ------------------------------------------------------