feat(core): add a rightSizing finding that recommends a core count from the scaling model #216
All Vouch review confidence checks passed
Residual risk 0.49 = Change Risk (0.57) × (1 − Review Confidence (0.14)).
Review depth and reviewer attention state are adequate.
Model 1 · Change Risk (XGBoost)
Score: 0.57 · 650 lines diff across 8 files
Model 2 · Review Depth (DistilBERT)
Depth Score: 0.02 · 1 substantive comment(s)
Model 3 · Review Timing & Attention
Session adequacy: 3% · Reviewer familiarity: 35%
Bedrock Claude 3 · Risk Narration
(disconnected)
Groq Risk Narration
AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
Model 1 · Change Risk Attribution
SHAP Weights
Diff Size
diff_size
0.388
Shallow Review Depth
shallow_review_depth
0.344
Ai Authored
ai_authored
0.050
Real PR Conversation Timeline
1 comments
"Review active on #216"
general
weight: 0.35
copilot-pull-request-reviewer[bot]
Intent
Add a finding to the Spark event-log analyzer that turns the what-if scaling simulation into a recommendation. Today the scaling simulation and the efficiency model show numbers, and the
utilizationfinding flags idle allocation, but nothing says "this run needs about half the cores". Competing tools score 2 or more on compute-efficiency criteria (a per-SQL idle-core rate, a cost model, and an executor-count sweep and critical-path simulation), while this tool's scaling and efficiency lenses are descriptive, gated only through the user-set--min-efficiency. The new finding builds on the existing scaling simulation inpackages/core/src/scaling-sim.ts(which self-checks its model against the observed makespan) and on the existing idle-allocation work inutilization; it does not need currency or cost output.Requested behavior:
What Changed
rightSizingapp detector (tagUTIL, always low confidence) inpackages/core/src/detectors.ts. It finds the smallest core count whose modeled stage time stays withintolerancePct(10%) of the observed stages-active time. It reports that count when the count is at mostmaxCoreShare(75%) of the peak cores held, on runs with at leastminBaselineCores(8). The finding stays silent when the model error is abovemaxModelErrorPct(20%). The text and evidence carry the observed and modeled times, the observed cores and the model error.--thresholdscan override all four thresholds.scaling-sim.tsmoves the baseline calibration into a shared helper and addssmallestCoresWithinTolerance, a binary search over core counts. The finding type, ID discriminators, presentation row (it shares the shrink-or-enable-dynamic-allocation advice withutilization) and evidence report are wired up in core. A newRightSizingwidget sits in the dashboard's action region.Risk Assessment
✅ Low: The change adds one bounded, always-low-confidence finding behind four frozen thresholds that the corpus gate shows never fire. The model's monotonic binary search is correct. The fix round did what the user asked: it recorded the corpus result in the provenance row, named the peak baseline in the finding text and docs, and added a shared idleCapacityRecommendation helper. It did not change simulateScaling.
Testing
I made five synthetic Spark logs and ran them through the real CLI (JSON and Markdown) and the Vite dashboard in headless Chromium. On the oversized run, the finding says 8 of the 16 cores held at peak, within 10% of the observed 10.0s, at low confidence. It is silent on the 50%-error, busy and small-cluster runs. Raising maxModelErrorPct to 60 makes it fire on the 50%-error run, which proves the error bound causes the suppression. The threshold overrides change or silence it as expected. The corpus gate passes with no changes. The dashboard ranks it as F2 UTIL and renders the Right-sized Cluster widget, with screenshots captured. The targeted unit tests pass. The dev server and the corpus submodule were removed, and the worktree is clean.
| Scenario | Result | Live | Evidence |
| --- | --- | --- | --- |
| CLI user analyzes an over-provisioned run: rightSizing fires with core counts, observed time and low confidence | ✅ pass | live | oversized.json / oversized.md: value 8, observedCores 16, observedActiveMs 10000, modelErrorPct 0, confidence low, recommendation names 8 of 16 cores held at peak |
| Adversarial: model error 50% (> 20% bound) suppresses the finding, and raising maxModelErrorPct to 60 makes it fire | ✅ pass | live | model-miss.json has no rightSizing. With --thresholds maxModelErrorPct 60 it fires with modelErrorPct 50 and a 'Produced with tuned thresholds' note |
| Adversarial: stages that use most cores, or a cluster under 8 cores, get no rightSizing finding | ✅ pass | live | busy.json and small.json findings lists have no rightSizing |
| Dynamic allocation already on: the advice changes to lowering spark.dynamicAllocation.maxExecutors | ✅ pass | live | oversized-dynalloc.json recommendation and remediation key spark.dynamicAllocation.maxExecutors |
| CLI --thresholds overrides change or silence the finding and mark it tuned | ✅ pass | live | maxCoreShare 0.4 gives no finding. tolerancePct 40 gives value 6 with tunedThresholds {tolerancePct: 40 default 10} |
| Detector catalog exposes the rightSizing thresholds (10 / 0.75 / 8 / 20) | ✅ pass | live | oversized.json detectors entry for rightSizing |
| Corpus gate passes with no finding changes, which matches the threshold-table provenance row | ✅ pass | live | corpus-gate.txt: 'No finding changes against dev/corpus-snapshot.json'. The snapshot has no rightSizing entry |
| Dashboard user loads the run: the finding shows as UTIL 'Right-size cluster' and the Right-sized Cluster widget shows 8 of 16 cores. The model-miss run shows neither | ✅ pass | live | ui-oversized-dashboard.png, ui-oversized-right-sizing-card.png, ui-oversized-f2-evidence.png, ui-model-miss-full-report.png. No page or console errors |
!Dashboard with rightSizing finding (F2 UTIL)
!Right-sized Cluster widget card
!F2 row with evidence expanded
!Model-miss run full report (no Right-sized widget)
<details>
<summary>Evidence: CLI JSON for oversized run</summary>
</details>
<details>
<summary>Evidence: CLI Markdown for oversized run</summary>
</details>
<details>
<summary>Evidence: CLI finding text (oversized)</summary>
</details>
<details>
<summary>Evidence: Synthetic log generator</summary>
</details>
Pipeline
Updates from git push no-mistakes
<!-- no-mistakes-pipeline-attestation:v1 {"head_sha":"e7d3ce6c6619b774ef450421fe3a77d199b89c97","steps":[{"step":"intent","status":"completed"},{"step":"rebase","status":"completed"},{"step":"review","status":"completed"},{"step":"test","status":"completed"},{"step":"document","status":"completed"},{"step":"lint","status":"completed"},{"step":"push","status":"completed"},{"step":"pr","status":"running"},{"step":"ci","status":"pending"}]} -->
<details>
<summary>✅ intent - passed</summary>
✅ No issues found.
</details>
<details>
<summary>✅ Rebase - passed</summary>
✅ No issues found.
</details>
<details>
<summary>🔧 Review - 3 issues found → auto-fixed ✅</summary>
docs-site/contributor-guide/architecture/detector-contract/threshold-tables.md:190- The intent requires: "Calibrate its thresholds against the public corpus with the corpus gate". The change does not show that calibration.dev/corpus-snapshot.jsonis unchanged and has norightSizingentry. The provenance row added here says the opposite: "rightSizingtolerancePct,maxCoreShare,minBaselineCoresandmaxModelErrorPct| Our own cuts, unvalidated". Also,detectors.ts:2705ships the defaults 10 / 0.75 / 8 / 20 with no corpus evidence in the commit or docs. Ask the author for one of two things: runnode dev/bench-analyze.mjs --check(and--updateif the finding fires), then record the corpus result in the provenance row; or confirm that the uncalibrated cuts are acceptable.packages/core/src/detectors.ts:2712- The finding calibrates the model atcomputePeakConcurrentCores. The existingsimulateScaling(packages/core/src/scaling-sim.ts:64) calibrates the same model atcomputeTotalCores, the sum of every executor ever added. When a run uses dynamic allocation or replaces executors, the two baselines differ. The dashboard's scaling simulation and the new finding then report different model errors for the same run. Example: a run that adds 4x4-core executors, removes them, and adds 4 more hascomputeTotalCores= 32 but peak = 16. The scaling widget then shows a model error at 32 cores, and the finding reports a different error at 16 cores, which can pass the 20% gate. The two surfaces then disagree about whether the model can be trusted. ChangingsimulateScaling's baseline changes existing user-visible output, so ask before you align them. Another option is to name the different baseline in the finding's text.packages/core/src/finding-presentation.ts:207-rightSizing.genericRecommendationcopiesutilization.genericRecommendation(lines 374-376) character for character. Move it into one shared helper (for exampleidleCapacityRecommendation(f)) that both rows call. Then the twoUTILrows cannot drift apart.🔧 Fix applied.
✅ Re-checked - no issues remain.
</details>
<details>
<summary>✅ Test - passed</summary>
✅ No issues found.
| Scenario | Result | Live | Evidence |
| --- | --- | --- | --- |
| CLI user analyzes an over-provisioned run: rightSizing fires with core counts, observed time and low confidence | ✅ pass | live | oversized.json / oversized.md: value 8, observedCores 16, observedActiveMs 10000, modelErrorPct 0, confidence low, recommendation names 8 of 16 cores held at peak |
| Adversarial: model error 50% (> 20% bound) suppresses the finding, and raising maxModelErrorPct to 60 makes it fire | ✅ pass | live | model-miss.json has no rightSizing. With --thresholds maxModelErrorPct 60 it fires with modelErrorPct 50 and a 'Produced with tuned thresholds' note |
| Adversarial: stages that use most cores, or a cluster under 8 cores, get no rightSizing finding | ✅ pass | live | busy.json and small.json findings lists have no rightSizing |
| Dynamic allocation already on: the advice changes to lowering spark.dynamicAllocation.maxExecutors | ✅ pass | live | oversized-dynalloc.json recommendation and remediation key spark.dynamicAllocation.maxExecutors |
| CLI --thresholds overrides change or silence the finding and mark it tuned | ✅ pass | live | maxCoreShare 0.4 gives no finding. tolerancePct 40 gives value 6 with tunedThresholds {tolerancePct: 40 default 10} |
| Detector catalog exposes the rightSizing thresholds (10 / 0.75 / 8 / 20) | ✅ pass | live | oversized.json detectors entry for rightSizing |
| Corpus gate passes with no finding changes, which matches the threshold-table provenance row | ✅ pass | live | corpus-gate.txt: 'No finding changes against dev/corpus-snapshot.json'. The snapshot has no rightSizing entry |
| Dashboard user loads the run: the finding shows as UTIL 'Right-size cluster' and the Right-sized Cluster widget shows 8 of 16 cores. The model-miss run shows neither | ✅ pass | live | ui-oversized-dashboard.png, ui-oversized-right-sizing-card.png, ui-oversized-f2-evidence.png, ui-model-miss-full-report.png. No page or console errors |
node gen-logs.mjs logs(evidence dir): built five synthetic event logs. They are oversized (16 cores, 8 tasks of 10 s in one 10 s wave), model-miss (same work over a 20 s stage), busy (64 tasks on 16 cores), small (4 cores) and oversized-dynalloc</code>node packages/cli/bin/sparkforensics-analyze.mjs <log> --format jsonon each of the five logs</code>node packages/cli/bin/sparkforensics-analyze.mjs oversized.ndjson --format md--thresholdswith{"rightSizing":{"maxCoreShare":0.4}},{"rightSizing":{"tolerancePct":40}}on oversized and{"rightSizing":{"maxModelErrorPct":60}}on model-miss</code>git submodule update --init dev/log-corpusthennode dev/bench-analyze.mjs --check dev/corpus-snapshot.json. The submodule was deinitialized afterward</code>npx vite --port 5391dev server, driven with Playwright (drive-ui2.mjs): loaded oversized and model-miss through Choose file, opened F2's evidence and the Full app report widget, took screenshots</code>npx vitest run tests/view/right-sizing.test.tsxcd packages/core && npx vitest run test/scaling-sim.test.js test/analyzer.test.js -t 'rightSizing|smallestCores|scaling'</details>
<details>
<summary>✅ Document - passed</summary>
✅ No issues found.
</details>
<details>
<summary>✅ Lint - passed</summary>
✅ No issues found.
</details>
<details>
<summary>✅ Push - passed</summary>
✅ No issues found.
</details>