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.

feat(health): deduct open performance findings from the performance score (#801)

Swati Ahuja0aeb9c58c767
diff --git a/packages/core/src/repowise/core/analysis/health/scoring.py b/packages/core/src/repowise/core/analysis/health/scoring.py
index 406e037e1..d7355a8b0 100644
--- a/packages/core/src/repowise/core/analysis/health/scoring.py
+++ b/packages/core/src/repowise/core/analysis/health/scoring.py
@@ -313,10 +313,14 @@ _MAINTAINABILITY_HOME: frozenset[str] = frozenset(
# ---------------------------------------------------------------------------
-# Performance dimension (PR3). Shipped at a small, ADVISORY weight - the whole
-# pillar is bounded by a single 1.0 category cap, so even a file riddled with
-# perf hits loses at most one health point on this dimension. Promotion to a
-# co-equal weight waits on PR4's cross-function precision study.
+# Performance dimension (PR3). Originally shipped at a small, ADVISORY weight
+# (a single 1.0 category cap), which left the pillar reading near-perfect even
+# on repos dense with open perf findings. With the cross-function pass landed
+# (PR4) and per-marker precision multipliers in place, the cap is raised to
+# 2.0 so open findings visibly move the score - still a deliberately
+# conservative ceiling for this first release (a file loses at most two
+# points regardless of hit count). Raising it further to a co-equal budget
+# waits on corpus precision data for the remaining advisory markers.
# ---------------------------------------------------------------------------
# Per-biomarker weight on the performance dimension. ``io_in_loop`` is the
@@ -339,7 +343,7 @@ _PERFORMANCE_WEIGHT_MULTIPLIER: dict[str, float] = {
# Phase 6 dialect markers. Both are high-precision syntactic shapes (Go
# `go vet`/`gocritic` ship defer-in-loop; the regex marker gates on a static
# literal pattern in Java/Go/Rust). Ship advisory pending this session's
- # test-repo gate; bounded by the 1.0 perf cap either way.
+ # test-repo gate; bounded by the perf category cap either way.
"regex_compile_in_loop": 0.6,
"defer_in_loop": 0.6,
"resource_construction_in_loop": 0.7,
@@ -400,9 +404,13 @@ _PERFORMANCE_CATEGORY: dict[str, str] = {
"sql_cartesian_join": "performance",
}
-# One bounded performance category cap. ~1.0 keeps performance advisory.
+# One bounded performance category cap. 2.0 is a deliberately conservative
+# first-release ceiling: enough for open findings to register on the pillar,
+# small enough that an all-advisory marker set cannot crater a file. Upgrade
+# path: raise toward the defect-style multi-point budget once the remaining
+# advisory markers clear their corpus precision gates (MARKER_BACKLOG.md).
_PERFORMANCE_CATEGORY_CAPS: dict[str, float] = {
- "performance": 1.0,
+ "performance": 2.0,
}
# Perf biomarkers home to ``performance`` for display / per-pillar filtering.
@@ -565,7 +573,7 @@ def score_file(results: Iterable[BiomarkerResult]) -> tuple[dict[str, float | No
identical to the pre-split ``score_file`` (the load-bearing guarantee).
``scores["performance"]`` is now measured (PR3): a file with no perf
findings scores 10.0; the perf detectors deduct under a single bounded
- ``performance`` cap. It is still capped low (advisory) and never blends
+ ``performance`` cap (2.0, a conservative ceiling). It never blends
into ``defect``.
- ``defect_deductions`` is each finding's contribution to the DEFECT score
after category capping, parallel to *results*. It populates
diff --git a/packages/server/src/repowise/server/routers/code_health/files_routes.py b/packages/server/src/repowise/server/routers/code_health/files_routes.py
index 72c78bbf6..e0e4119d0 100644
--- a/packages/server/src/repowise/server/routers/code_health/files_routes.py
+++ b/packages/server/src/repowise/server/routers/code_health/files_routes.py
@@ -93,7 +93,7 @@ async def list_health_files(
leads = _leads_by_file([f for f in findings if f.file_path in page_paths])
# Per-file performance signal for the map's performance lens: open perf-
# finding counts + whether a perf detector ran on the file's language. Colors
- # the lens by findings/coverage instead of the uniformly-green [9,10] score.
+ # the lens by findings/coverage instead of the narrow-band [8,10] score.
perf_counts: dict[str, int] = {}
for fnd in findings:
if (getattr(fnd, "dimension", None) or "defect") == "performance":
diff --git a/packages/ui/__tests__/health/biomarker-glossary.test.ts b/packages/ui/__tests__/health/biomarker-glossary.test.ts
new file mode 100644
index 000000000..cf29efeea
--- /dev/null
+++ b/packages/ui/__tests__/health/biomarker-glossary.test.ts
@@ -0,0 +1,22 @@
+/**
+ * Parity guard for the glossary's fallback category caps.
+ *
+ * `CATEGORY_CAP` is the TypeScript mirror of the category-cap tables in
+ * `packages/core/src/repowise/core/analysis/health/scoring.py`. The rendered
+ * cap always prefers the server-supplied value (see score-breakdown.tsx), so
+ * this constant only backstops older payloads — but a silent retune of one
+ * side without the other should still fail CI, the same way the band cutoffs
+ * are pinned in `packages/types/__tests__/health.test.ts` +
+ * `tests/unit/health/test_grading.py`. The Python half of this pin is the
+ * cap-bound behavior in `tests/unit/health/test_scoring_dimensions.py`
+ * (`test_perf_category_cap_bounds_dimension`).
+ */
+
+import { describe, expect, it } from "vitest";
+import { CATEGORY_CAP } from "../../src/health/biomarker-glossary.js";
+
+describe("CATEGORY_CAP parity", () => {
+ it("pins the performance cap to scoring.py's _PERFORMANCE_CATEGORY_CAPS", () => {
+ expect(CATEGORY_CAP.performance).toBe(2.0);
+ });
+});
diff --git a/packages/ui/src/health/biomarker-glossary.ts b/packages/ui/src/health/biomarker-glossary.ts
index 856eae6a0..7f6f2afbd 100644
--- a/packages/ui/src/health/biomarker-glossary.ts
+++ b/packages/ui/src/health/biomarker-glossary.ts
@@ -48,9 +48,10 @@ export const CATEGORY_CAP: Record<BiomarkerCategory, number> = {
test_quality: 0.5,
error_handling: 0.5,
// One bounded performance category cap (mirrors `_PERFORMANCE_CATEGORY_CAPS`
- // in scoring.py): the whole performance pillar deducts at most 1.0, keeping it
- // advisory.
- performance: 1.0,
+ // in scoring.py): the whole performance pillar deducts at most 2.0. Fallback
+ // only — a server-supplied cap always wins (see score-breakdown.tsx), so this
+ // constant matters just for payloads that predate the `cap` field.
+ performance: 2.0,
// SQL smells deduct on the maintainability pillar only, bounded by the `sql`
// cap in `_MAINTAINABILITY_CATEGORY_CAPS` (scoring.py).
sql: 2.0,
diff --git a/packages/ui/src/health/code-health-map.tsx b/packages/ui/src/health/code-health-map.tsx
index 14477eaa7..a9f15593b 100644
--- a/packages/ui/src/health/code-health-map.tsx
+++ b/packages/ui/src/health/code-health-map.tsx
@@ -15,7 +15,7 @@ export interface CodeHealthMapFile {
/** Maintainability pillar score (1–10) — drives the maintainability overlay. */
maintainability_score?: number | null;
/** Performance-risk pillar score (1–10) — computed but NOT used to color the
- * performance overlay (it is compressed to [9,10] and reads uniformly green).
+ * performance overlay (it is compressed to [8,10] and reads uniformly green).
* The performance lens colors by {@link performance_findings} + coverage. */
performance_score?: number | null;
/** Open performance-risk findings on this file — drives the performance heat. */
diff --git a/packages/ui/src/health/score-breakdown.tsx b/packages/ui/src/health/score-breakdown.tsx
index 953ee0071..b2d3e1771 100644
--- a/packages/ui/src/health/score-breakdown.tsx
+++ b/packages/ui/src/health/score-breakdown.tsx
@@ -18,7 +18,10 @@ export interface ScoreBreakdownCategoryFinding {
export interface ScoreBreakdownCategory {
category: BiomarkerCategory | string;
- cap: number;
+ /** Cap the scorer actually enforced. Optional only because payloads from
+ * older servers predate the field; when present it always wins over the
+ * glossary's `CATEGORY_CAP` fallback. */
+ cap?: number | null;
raw_deduction: number;
applied_deduction: number;
capped: boolean;
@@ -58,23 +61,24 @@ export function ScoreBreakdown({
return b.applied_deduction - a.applied_deduction;
}
const capA =
- CATEGORY_CAP[a.category as BiomarkerCategory] ?? a.cap;
+ a.cap ?? CATEGORY_CAP[a.category as BiomarkerCategory] ?? 0;
const capB =
- CATEGORY_CAP[b.category as BiomarkerCategory] ?? b.cap;
+ b.cap ?? CATEGORY_CAP[b.category as BiomarkerCategory] ?? 0;
return capB - capA;
})
.map((c) => {
const label =
CATEGORY_LABEL[c.category as BiomarkerCategory] ?? c.category;
- // Only trust the glossary's caps for scaling the bar. A
- // payload-supplied cap for an unknown category is often just the
- // deduction echoed back at itself, which would render a
- // meaningless always-full bar.
- const knownCap = CATEGORY_CAP[c.category as BiomarkerCategory];
- const cap = knownCap ?? c.cap;
+ // Prefer the server-supplied cap: it is the value the scorer
+ // actually enforced, so a cap retune in scoring.py renders
+ // correctly without a UI release. The glossary constant is only a
+ // fallback for older-server payloads that predate the `cap` field.
+ const cap = c.cap ?? CATEGORY_CAP[c.category as BiomarkerCategory];
const pct = Math.min(
100,
- (Math.abs(c.applied_deduction) / Math.max(Math.abs(cap), 0.01)) * 100,
+ (Math.abs(c.applied_deduction) /
+ Math.max(Math.abs(cap ?? c.applied_deduction), 0.01)) *
+ 100,
);
return (
<div
@@ -89,19 +93,20 @@ export function ScoreBreakdown({
className="cursor-help tabular-nums text-[var(--color-text-tertiary)]"
title="The cap is the most this category is allowed to subtract from the 10-point score, no matter how many findings it has."
>
- −{c.applied_deduction.toFixed(2)} / cap −{cap.toFixed(1)}
+ −{c.applied_deduction.toFixed(2)}
+ {cap != null ? <> / cap −{cap.toFixed(1)}</> : null}
{c.capped ? <span className="ml-1 text-[var(--color-warning)]" title="Raw deductions exceeded the cap; only the cap was subtracted.">(capped)</span> : null}
</span>
</div>
<div className="mt-1.5 h-1.5 w-full overflow-hidden rounded-full bg-[var(--color-bg-muted)]">
<div
className={
- knownCap != null
+ cap != null
? "h-full bg-[var(--color-error)]/70"
: "h-full bg-[var(--color-text-tertiary)]/40"
}
title={
- knownCap == null
+ cap == null
? "No defined cap for this category — bar scale is approximate."
: undefined
}
diff --git a/tests/unit/health/test_scoring_dimensions.py b/tests/unit/health/test_scoring_dimensions.py
index 8a9faf332..93234f01e 100644
--- a/tests/unit/health/test_scoring_dimensions.py
+++ b/tests/unit/health/test_scoring_dimensions.py
@@ -239,12 +239,25 @@ def test_perf_io_in_loop_deduction():
assert scores["performance"] == 9.3
+def test_perf_two_medium_findings_deduct_uncapped():
+ """Two MEDIUM io_in_loop hits deduct in full (2 x 0.7 = 1.4, under the cap)."""
+ scores, _ = score_file([_r("io_in_loop", Severity.MEDIUM) for _ in range(2)])
+ assert scores["performance"] == 8.6
+
+
def test_perf_category_cap_bounds_dimension():
- """The single 1.0 performance cap bounds the whole pillar."""
+ """The single 2.0 performance cap bounds the whole pillar."""
findings = [_r("io_in_loop", Severity.MEDIUM) for _ in range(10)]
scores, _ = score_file(findings)
- # 10 * 0.7 = 7.0 raw -> capped at 1.0 -> 9.0, never lower.
- assert scores["performance"] == 9.0
+ # 10 * 0.7 = 7.0 raw -> capped at 2.0 -> 8.0, never lower.
+ assert scores["performance"] == 8.0
+
+
+def test_perf_cap_bounds_high_severity_pileup():
+ """Six HIGH hits (6 x 1.2 = 7.2 raw) still bottom out at the 2.0 cap."""
+ findings = [_r("io_in_loop", Severity.HIGH) for _ in range(6)]
+ scores, _ = score_file(findings)
+ assert scores["performance"] == 8.0
def test_perf_bonus_markers_advisory_weight():