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 hidden_coupling deducting from the score, keep it as advisory (#2596)

Raghav Chamadiya665c6ad92164
diff --git a/docs/architecture/code-health.md b/docs/architecture/code-health.md
index 72fe2fe3d..cd116d03c 100644
--- a/docs/architecture/code-health.md
+++ b/docs/architecture/code-health.md
@@ -302,11 +302,11 @@ are **54 marker ids**. They divide by what each is permitted to affect:
| Group | Count | Scores into |
|---|---:|---|
-| Defect-scoring | 26 | `defect` (8 of them also `maintainability`) |
+| Defect-scoring | 25 | `defect` (8 of them also `maintainability`) |
| Performance | 20 | `performance` only |
| SQL | 3 | `maintainability` only |
| Governance | 3 | nothing — the finding surfaces, the score is untouched |
-| Advisory | 2 | nothing — measured by construction, kept out of impact-ranked lists unless requested |
+| Advisory | 3 | nothing — measured by construction, kept out of impact-ranked lists unless requested |
The authority is `scoring._BIOMARKER_DIMENSIONS`. Any biomarker **not** listed
there defaults into `defect`, which is why every `sql_*` and every performance
@@ -317,7 +317,7 @@ golden guarantee (§6).
| Category | Cap | Markers |
|------------------------|------|------------|
-| Organizational | −3.5‡ | developer_congestion, knowledge_loss, hidden_coupling, function_hotspot, code_age_volatility, ownership_risk, churn_risk, change_entropy, co_change_scatter, prior_defect, ungoverned_hotspot†, stale_governance†, contradictory_decision† |
+| Organizational | −3.5‡ | developer_congestion, knowledge_loss, function_hotspot, code_age_volatility, ownership_risk, churn_risk, change_entropy, co_change_scatter, prior_defect, ungoverned_hotspot†, stale_governance†, contradictory_decision† |
| Structural complexity | −2.5 | brain_method, low_cohesion, god_class, nested_complexity, bumpy_road, complex_conditional |
| Test coverage | −2.0 | untested_hotspot, coverage_gap |
| Test coverage gradient | −2.0 | coverage_gradient |
@@ -336,6 +336,11 @@ number.
where `structure` is the file's capped deduction from every other defect
category, so git history alone costs a file at most 1.0.
+`hidden_coupling` is advisory: still detected, stored and listed, it deducts
+nothing. On its own it ranks defect-prone files near chance (AUC about 0.55), and
+a pre-registered test on 12 repositories no earlier health study used found the
+score without it non-inferior at predicting defects.
+
The maintainability dimension has its own independent tables
(`_MAINTAINABILITY_CATEGORY`, caps: structural_complexity 4.0,
size_and_complexity 2.0, duplication 2.0, error_handling 2.0, sql 2.0), and the
diff --git a/docs/layers/CODE_HEALTH.md b/docs/layers/CODE_HEALTH.md
index 71dbf0882..fbf1774bf 100644
--- a/docs/layers/CODE_HEALTH.md
+++ b/docs/layers/CODE_HEALTH.md
@@ -74,18 +74,18 @@ per-line blame index built for every file.
## The markers, and what each is allowed to do
-Repowise ships **51 registered detectors (54 marker ids)**, but only **26 are
+Repowise ships **51 registered detectors (54 marker ids)**, but only **25 are
permitted to move the headline number**. That restriction is deliberate: the
defect score carries published accuracy claims, so only markers that earned
their weight against a bug corpus may affect it.
| Tier | Markers | What it may do |
|---|---:|---|
-| **Defect-scoring** | **26** | Calibrated weights; moves the 1-10 score |
+| **Defect-scoring** | **25** | Calibrated weights; moves the 1-10 score |
| **Performance** | **20** | Own pillar, own cap; never touches the defect score |
| **Maintainability-only (SQL)** | **3** | Maintainability only |
| **Governance** | **3** | Surfaces as a finding; never deducts |
-| **Advisory** | **2** | Measured and reported; never deducts, and stays out of impact-ranked lists unless asked for |
+| **Advisory** | **3** | Measured and reported; never deducts, and stays out of impact-ranked lists unless asked for |
Nothing is inert, but "doesn't move the number" means three different things:
@@ -446,6 +446,12 @@ editor, or a list already filtered to one marker -- gets it without asking.
|---|---|---|
| `assertion_free_test` | Python · TypeScript / JavaScript | A test case that runs the code under test and checks nothing |
| `mock_saturated_test` | Python · TypeScript / JavaScript | Mock-setup statements per assertion in a test function |
+| `hidden_coupling` | every language with git history | Files that change together with no import between them |
+
+`hidden_coupling` is here for the other reason: it was measured and carried no
+signal. Alone it ranks defect-prone files near chance (AUC about 0.55), and a
+pre-registered test on 12 repositories no earlier health study used found the
+score without it non-inferior at predicting defects, so it stopped deducting.
A marker earns weight by clearing the house precision bar (roughly 70%
hand-labelled) on a real corpus. `mock_saturated_test` has not, and precision is
diff --git a/packages/core/src/repowise/core/analysis/health/biomarkers/README.md b/packages/core/src/repowise/core/analysis/health/biomarkers/README.md
index ab895300e..ea1099641 100644
--- a/packages/core/src/repowise/core/analysis/health/biomarkers/README.md
+++ b/packages/core/src/repowise/core/analysis/health/biomarkers/README.md
@@ -51,7 +51,8 @@ Organizational (cap −3.5):
- `developer_congestion` — too many active authors competing on a file.
- `knowledge_loss` — primary authors no longer active (de-rated to 0.4).
- `hidden_coupling` — files that co-change in history without an explicit
- import edge between them.
+ import edge between them. Advisory: filed here, deducts nothing (it showed no
+ defect signal on a held-out, pre-registered test).
- `function_hotspot` — functions that are both structurally complex and
frequently modified (per-function churn from the FULL-tier blame index).
- `code_age_volatility` — dormant functions (median line age ≥ 1y) that
diff --git a/packages/core/src/repowise/core/analysis/health/engine.py b/packages/core/src/repowise/core/analysis/health/engine.py
index 6ebee40b3..9d1302bd3 100644
--- a/packages/core/src/repowise/core/analysis/health/engine.py
+++ b/packages/core/src/repowise/core/analysis/health/engine.py
@@ -111,6 +111,9 @@ log = structlog.get_logger(__name__)
# and a declining call's arguments are not scanned, so an assertion passed as an
# argument still does not stand in for the header's oracle.
#
+# v34: ``hidden_coupling`` is advisory: still detected and stored, it no longer
+# deducts from the defect score, so every stored score that carried one moves.
+#
# v33: git history windows are measured from the indexed commit's committer
# date instead of wall-clock time, by default. ``code_age_volatility`` and the
# per-function blame rollup read line ages from the same anchor, so a store
@@ -312,7 +315,7 @@ log = structlog.get_logger(__name__)
# forms. Files that were counted untested and are not become tested, which
# moves untested-hotspot findings and the scores that carry them, on every
# language with a prefix or spec convention rather than Ruby alone.
-HEALTH_ANALYZER_VERSION = 33
+HEALTH_ANALYZER_VERSION = 34
def walked_functions(
diff --git a/packages/core/src/repowise/core/analysis/health/scoring.py b/packages/core/src/repowise/core/analysis/health/scoring.py
index f04b40c97..e2698e801 100644
--- a/packages/core/src/repowise/core/analysis/health/scoring.py
+++ b/packages/core/src/repowise/core/analysis/health/scoring.py
@@ -169,8 +169,8 @@ _BIOMARKER_WEIGHT_MULTIPLIER: dict[str, float] = {
# (0.3 x 0.5 = 0.15/finding) + the 0.5 category cap keep the impact
# bounded at half a point per file regardless of hit count.
"error_handling": 0.5,
- # (coverage_gap, hidden_coupling, large_assertion_block,
- # duplicated_assertion_block default to 1.0 - kept at prior)
+ # (coverage_gap, large_assertion_block, duplicated_assertion_block
+ # default to 1.0 - kept at prior)
# Governance - additive pass, weights are informational
"contradictory_decision": 1.0,
"stale_governance": 0.9,
@@ -196,6 +196,7 @@ _BIOMARKER_CATEGORY: dict[str, str] = {
"coverage_gradient": "test_coverage_gradient",
"developer_congestion": "organizational",
"knowledge_loss": "organizational",
+ # Advisory (deducts nothing); kept here so history-grouped surfaces file it.
"hidden_coupling": "organizational",
"function_hotspot": "organizational",
"code_age_volatility": "organizational",
@@ -237,8 +238,9 @@ DIMENSIONS: tuple[str, ...] = ("defect", "maintainability", "performance")
# The one dimension that does not score. Deliberately NOT in ``DIMENSIONS``,
# which is exactly the set ``score_file`` returns a number for: keeping it out
# means there is no weight, category or cap table it can acquire. A marker homes
-# here when no defect corpus labels what it measures, so it can never be
-# calibrated. It still carries a severity, a reason and a home for display.
+# here when no defect corpus labels what it measures, or when a held-out test
+# found no defect signal in it. It still carries a severity, a reason and a home
+# for display.
ADVISORY_DIMENSION: str = "advisory"
# Every dimension label a finding may carry, scored or not. Surfaces that filter
@@ -316,6 +318,9 @@ _BIOMARKER_DIMENSIONS: dict[str, set[str]] = {
# independent, and a marker in only one of them still deducts from defect.
"assertion_free_test": {ADVISORY_DIMENSION},
"mock_saturated_test": {ADVISORY_DIMENSION},
+ # Near-chance defect AUC alone, and dropping it was non-inferior on a fresh
+ # 12-repo pre-registered test (docs/architecture/code-health.md).
+ "hidden_coupling": {ADVISORY_DIMENSION},
}
# Maintainability per-biomarker weight multipliers. Expert-set by definition -
@@ -530,7 +535,9 @@ _PERFORMANCE_HOME: frozenset[str] = frozenset(
# The display half of the pairing above; ``test_advisory_dimension.py`` locks
# the two together for every registered biomarker.
-_ADVISORY_HOME: frozenset[str] = frozenset({"assertion_free_test", "mock_saturated_test"})
+_ADVISORY_HOME: frozenset[str] = frozenset(
+ {"assertion_free_test", "mock_saturated_test", "hidden_coupling"}
+)
def severity_deduction(sev: Severity) -> float:
diff --git a/packages/ui/src/health/biomarker-glossary.ts b/packages/ui/src/health/biomarker-glossary.ts
index eb74f76cb..2a7466329 100644
--- a/packages/ui/src/health/biomarker-glossary.ts
+++ b/packages/ui/src/health/biomarker-glossary.ts
@@ -134,7 +134,7 @@ export const BIOMARKER_GLOSSARY: Record<string, BiomarkerInfo> = {
label: "Hidden coupling",
category: "organizational",
description:
- "Two files co-change in git history but have no explicit import between them. The implicit contract is invisible at the source level, so changes slip out of sync and break in production.",
+ "Two files co-change in git history but have no explicit import between them. The implicit contract is invisible at the source level, so changes slip out of sync and break in production. Advisory: it costs this file no points.",
},
complex_conditional: {
label: "Complex conditional",
@@ -382,13 +382,15 @@ export type BiomarkerDimension = "defect" | "maintainability" | "performance" |
/**
* Biomarkers that home to the non-scoring `advisory` dimension. They measure
- * something real that no defect corpus labels, so they never deduct and the
- * chip has to say so rather than borrowing the defect pillar's label. Mirror of
+ * something real that no defect corpus labels, or that showed no defect signal
+ * when tested, so they never deduct and the chip has to say so rather than
+ * borrowing the defect pillar's label. Mirror of
* ``_ADVISORY_HOME`` in core's `scoring.py`.
*/
export const ADVISORY_HOME_BIOMARKERS: ReadonlySet<string> = new Set([
"assertion_free_test",
"mock_saturated_test",
+ "hidden_coupling",
]);
/**
diff --git a/tests/unit/health/test_advisory_dimension.py b/tests/unit/health/test_advisory_dimension.py
index e9d1ba002..d860d9384 100644
--- a/tests/unit/health/test_advisory_dimension.py
+++ b/tests/unit/health/test_advisory_dimension.py
@@ -81,6 +81,16 @@ def test_advisory_findings_carry_zero_health_impact():
assert findings[0].dimension == ADVISORY_DIMENSION
+def test_hidden_coupling_is_advisory():
+ """Dropped from the score by a pre-registered test; still detected."""
+ assert is_advisory("hidden_coupling")
+ history = [_result("prior_defect")]
+ alone, _ = score_file(history)
+ with_coupling, deductions = score_file([*history, _result("hidden_coupling")])
+ assert with_coupling == alone
+ assert deductions[1] == 0.0
+
+
def test_advisory_findings_do_not_dilute_a_real_deduction():
"""Adding an advisory finding to a scored one leaves the score alone."""
scored_only, _ = score_file([_result("brain_method")])
diff --git a/tests/unit/health/test_model_version_coupling.py b/tests/unit/health/test_model_version_coupling.py
index f0ba67ea0..b9d058d82 100644
--- a/tests/unit/health/test_model_version_coupling.py
+++ b/tests/unit/health/test_model_version_coupling.py
@@ -22,7 +22,7 @@ from repowise.core.analysis.health.refactoring.identity import (
# The three stamps as they stand together. Moving either identity model means
# moving the analyzer with it, and updating this tuple in the same commit.
-_STAMPS = (33, 2, 2)
+_STAMPS = (34, 2, 2)
def test_the_identity_models_and_the_analyzer_stamp_are_pinned_together() -> None:
diff --git a/tests/unit/health/test_scoring_snapshot.py b/tests/unit/health/test_scoring_snapshot.py
index f330a42ef..44681fe5c 100644
--- a/tests/unit/health/test_scoring_snapshot.py
+++ b/tests/unit/health/test_scoring_snapshot.py
@@ -101,7 +101,7 @@ _EXPECTED_BIOMARKER_CATEGORY = {
"coverage_gradient": "test_coverage_gradient",
"developer_congestion": "organizational",
"knowledge_loss": "organizational",
- "hidden_coupling": "organizational",
+ "hidden_coupling": "organizational", # advisory: moves no score
"function_hotspot": "organizational",
"code_age_volatility": "organizational",
"ownership_risk": "organizational",