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(risk): emit is_hotspot from the backend, not client re-derivation (#1797)

Sloe14b571cc718c
diff --git a/packages/server/src/repowise/server/mcp_server/tool_risk/assessment.py b/packages/server/src/repowise/server/mcp_server/tool_risk/assessment.py
index da82ce77b..eeb84d985 100644
--- a/packages/server/src/repowise/server/mcp_server/tool_risk/assessment.py
+++ b/packages/server/src/repowise/server/mcp_server/tool_risk/assessment.py
@@ -413,6 +413,7 @@ async def _assess_one_target(
if meta is None:
result_data["hotspot_score"] = 0.0
+ result_data["is_hotspot"] = False
result_data["dependents_count"] = dep_count
result_data["co_change_partners"] = []
result_data["primary_owner"] = None
@@ -453,6 +454,12 @@ async def _assess_one_target(
bus_factor = getattr(meta, "bus_factor", 0) or 0
result_data["hotspot_score"] = hotspot_score
+ # Emit the backend's hotspot classification, not a client re-derivation.
+ # ``is_hotspot`` lives on the stored GitMetadata row and already applies
+ # the absolute activity floors (issue #361); a client that thresholds the
+ # score alone can reproduce the churn half but not the floors, so on a
+ # quiet repo it would badge files the backend does not consider hotspots.
+ result_data["is_hotspot"] = bool(getattr(meta, "is_hotspot", False))
result_data["dependents_count"] = dep_count
result_data["co_change_partners"] = co_changes
result_data["primary_owner"] = owner
diff --git a/packages/server/src/repowise/server/mcp_server/tool_risk/get_risk.py b/packages/server/src/repowise/server/mcp_server/tool_risk/get_risk.py
index e75f5abd4..adb9f877f 100644
--- a/packages/server/src/repowise/server/mcp_server/tool_risk/get_risk.py
+++ b/packages/server/src/repowise/server/mcp_server/tool_risk/get_risk.py
@@ -203,6 +203,7 @@ async def get_risk(
entry = {
"file_path": h.file_path,
"hotspot_score": h.churn_percentile,
+ "is_hotspot": True,
"primary_owner": h.primary_owner_name,
}
# Silent on files with no counted fixes, so a repo without fix
diff --git a/packages/ui/__tests__/chat/artifacts.test.tsx b/packages/ui/__tests__/chat/artifacts.test.tsx
index 33a68c7f9..f107cd56d 100644
--- a/packages/ui/__tests__/chat/artifacts.test.tsx
+++ b/packages/ui/__tests__/chat/artifacts.test.tsx
@@ -59,7 +59,7 @@ describe("chat artifact renderers", () => {
data={{
targets: [
// Wire scores are 0–1 fractions (rank / total), not 0–100.
- { file_path: "src/hot.ts", churn_percentile: 0.99 },
+ { file_path: "src/hot.ts", churn_percentile: 0.99, is_hotspot: true },
],
global_hotspots: [{ path: "src/other.ts", churn_percentile: 0.88 }],
}}
@@ -79,8 +79,10 @@ describe("chat artifact renderers", () => {
targets: {
"src/auth.py": {
target: "src/auth.py",
- // No is_hotspot on the MCP row — badge comes from score >= 0.75.
+ // Backend now emits is_hotspot directly; the badge trusts it
+ // rather than re-deriving from the score.
hotspot_score: 0.91,
+ is_hotspot: true,
risk_type: "churn-heavy",
trend: "increasing",
},
diff --git a/packages/ui/src/chat/artifacts.tsx b/packages/ui/src/chat/artifacts.tsx
index 0bba0906f..96964cbc7 100644
--- a/packages/ui/src/chat/artifacts.tsx
+++ b/packages/ui/src/chat/artifacts.tsx
@@ -186,9 +186,6 @@ type NormalizedRiskTarget = {
risk_summary?: string;
};
-/** Same top-quartile cut `git_indexer/enrich.py` uses for `is_hotspot`. */
-const HOTSPOT_SCORE_THRESHOLD = 0.75;
-
function formatHotspotPct(score: number): string {
return `${Math.round(score * 100)}th`;
}
@@ -227,10 +224,10 @@ function normalizeRiskTargets(data: RiskReportArtifactData): NormalizedRiskTarge
const out: NormalizedRiskTarget = {
file_path: t.file_path,
score,
- // MCP target rows omit `is_hotspot`; derive from the enrich.py cut.
- is_hotspot:
- Boolean(t.is_hotspot) ||
- (typeof score === "number" && score >= HOTSPOT_SCORE_THRESHOLD),
+ // The backend now emits `is_hotspot` (which already applies the
+ // absolute activity floors); trust it instead of re-deriving from the
+ // score, which can't reproduce the floors and misbadges quiet repos.
+ is_hotspot: Boolean(t.is_hotspot),
};
if (typeof t.risk_type === "string") out.risk_type = t.risk_type;
if (typeof t.trend === "string") out.trend = t.trend;