Skip to content

fix(pipeline): preserve coverage across an incremental health re-score - #1806

Merged
RaghavChamadiya merged 1 commit into
repowise-dev:mainfrom
sloemo01:fix/incremental-coverage-map
Aug 21, 2026
Merged

RaghavChamadiya merged 1 commit into
repowise-dev:mainfrom
sloemo01:fix/incremental-coverage-map

Conversation

@sloemo01

Copy link
Copy Markdown
Contributor

What

Fixes #1739. The incremental pipeline built its HealthAnalyzer without a coverage_map, so every changed file was re-scored as if no coverage had ever been ingested. The partial-health writer then upserted those metrics, overwriting the stored line_coverage_pct with NULL for exactly the files that just changed — eroding coverage one file per update, starting with the files under active development.

Root cause

run_partial_analysis built HealthAnalyzer(...) with no coverage_map (which defaults to {}), so the coverage lookup at engine.py:889 yielded None for every re-analyzed file. persist_partial_health then upserted those metrics, nulling coverage. The sibling re-score path already had the fix pattern (_coverage_for_rescore in the CLI update path) — this extends it to the incremental health pass.

Fix

  • incremental.py: add load_stored_coverage_map(repo_path) — reloads the persisted CoverageFile rows into the {path: coverage-dict} shape HealthAnalyzer expects, mirroring load_stored_function_mod_p80 and the CLI's _coverage_for_rescore.
  • run_partial_analysis: accept and pass coverage_map to HealthAnalyzer.
  • Both callers now load and supply it: the workspace updater (workspace/update.py, async) and the CLI incremental path (update_cmd/incremental.py).
  • Returns empty map (safe no-coverage default) when nothing is stored or the store is unreadable.

Tests

  • New tests/unit/pipeline/test_load_stored_coverage_map.py — persists coverage rows then reloads them as the health-coverage map (2 tests: reload round-trip + absent-store returns empty).
  • tests/unit/pipeline/ + tests/unit/cli/test_coverage_cmd.py — 127 passed, no regressions.
  • Ruff clean.

The incremental pipeline built its HealthAnalyzer without a coverage_map,
so every changed file was re-scored as if no coverage had ever been
ingested. The partial-health writer then upserted those metrics,
overwriting the stored line_coverage_pct with NULL for exactly the files
that just changed — eroding coverage one file per update, starting with
files under active development (issue repowise-dev#1739).

Add load_stored_coverage_map (mirroring the existing _coverage_for_rescore
in the CLI update path and load_stored_function_mod_p80 in the workspace
updater) and pass it to HealthAnalyzer in run_partial_analysis. Both
callers — the workspace updater and the CLI incremental path — now load and
supply the persisted coverage map, so an incremental update re-scores
changed files against the coverage they already had.

Fixes repowise-dev#1739
@repowise-bot

repowise-bot Bot commented Aug 21, 2026

Copy link
Copy Markdown
Contributor

✅ Health of changed files: 1.7 → 1.9 (+0.2)
⚠️ Change risk: moderate, riskier than 38% of this repo's commits.

📋 At a glance
3 hotspots touched · 3 new findings introduced · 3 co-change pairs left out · 3 files with recent fix history · 1 dead-code finding. Scoped to packages.

✅ Health gate: passed

📌 Before you merge

  • Run .../dead_code/test_partial.py, .../health/test_module_attribution.py, .../health/test_perf_incremental_parity.py, .../cli/test_update_lock.py (+2 more): they import the changed files
  • .../pipeline/persist.py changed together with .../pipeline/incremental.py in 14 past commits and isn't in this PR
  • .../update_cmd/command.py changed together with .../workspace/update.py in 13 past commits and isn't in this PR
  • .../update_cmd/persistence.py changed together with .../pipeline/incremental.py in 13 past commits and isn't in this PR

🎯 Blast radius (symbols whose signature this PR changed, and who calls them)

  • run_partial_analysis in .../pipeline/incremental.py signature changed. Called by 1 symbol outside this PR: .../dead_code/test_partial.py::_run_update_analysis
🔎 More signals (4)

🗺️ Change map

flowchart LR
  subgraph PR ["Changed in this PR (3 with dependents)"]
    f_packages_cli_src_repowise_cli_commands_update_cmd_incremental_py[".../update_cmd/incremental.py 🔥"]:::changed
    f_packages_core_src_repowise_core_pipeline_incremental_py[".../pipeline/incremental.py 🔥"]:::changed
    f_packages_core_src_repowise_core_workspace_update_py[".../workspace/update.py 🔥"]:::changed
  end
  f_packages_cli_src_repowise_cli_commands_update_cmd___init___py[".../update_cmd/__init__.py"]
  f_packages_cli_src_repowise_cli_commands_update_cmd_incremental_py --> f_packages_cli_src_repowise_cli_commands_update_cmd___init___py
  f_packages_cli_src_repowise_cli_commands_update_cmd_command_py[".../update_cmd/command.py"]
  f_packages_cli_src_repowise_cli_commands_update_cmd_incremental_py --> f_packages_cli_src_repowise_cli_commands_update_cmd_command_py
  f_packages_cli_src_repowise_cli_commands_update_cmd_persistence_py[".../update_cmd/persistence.py"]
  f_packages_cli_src_repowise_cli_commands_update_cmd_incremental_py --> f_packages_cli_src_repowise_cli_commands_update_cmd_persistence_py
  f_packages_cli_src_repowise_cli_commands_dead_code_cmd_py[".../commands/dead_code_cmd.py"]
  f_packages_core_src_repowise_core_pipeline_incremental_py --> f_packages_cli_src_repowise_cli_commands_dead_code_cmd_py
  f_packages_core_src_repowise_core_pipeline_incremental_py --> f_packages_cli_src_repowise_cli_commands_update_cmd_command_py
  f_packages_core_src_repowise_core_pipeline_incremental_py --> f_packages_cli_src_repowise_cli_commands_update_cmd_persistence_py
  f_packages_core_src_repowise_core_analysis_dead_code_analyzer_py[".../dead_code/analyzer.py"]
  f_packages_core_src_repowise_core_pipeline_incremental_py --> f_packages_core_src_repowise_core_analysis_dead_code_analyzer_py
  f_packages_cli_src_repowise_cli_commands_doctor_cmd_workspace_checks_py[".../doctor_cmd/workspace_checks.py"]
  f_packages_core_src_repowise_core_workspace_update_py --> f_packages_cli_src_repowise_cli_commands_doctor_cmd_workspace_checks_py
  f_packages_cli_src_repowise_cli_commands_init_cmd_workspace_py[".../init_cmd/workspace.py"]
  f_packages_core_src_repowise_core_workspace_update_py --> f_packages_cli_src_repowise_cli_commands_init_cmd_workspace_py
  f_packages_core_src_repowise_core_workspace_update_py --> f_packages_cli_src_repowise_cli_commands_update_cmd_command_py
  f_packages_core_src_repowise_core_workspace_update_py --> f_packages_cli_src_repowise_cli_commands_update_cmd_persistence_py
  more(["+10 more dependents"])
  PR --> more
  w_packages_core_src_repowise_core_pipeline_persist_py(["⚠️ .../pipeline/persist.py changed together 14×, not in PR"]):::warn
  f_packages_core_src_repowise_core_pipeline_incremental_py -.- w_packages_core_src_repowise_core_pipeline_persist_py
  w_packages_cli_src_repowise_cli_commands_update_cmd_command_py(["⚠️ .../update_cmd/command.py changed together 13×, not in PR"]):::warn
  f_packages_core_src_repowise_core_workspace_update_py -.- w_packages_cli_src_repowise_cli_commands_update_cmd_command_py
  t_tests_unit_dead_code_test_partial_py(["✅ .../dead_code/test_partial.py"]):::guard
  t_tests_unit_dead_code_test_partial_py -.-> f_packages_core_src_repowise_core_pipeline_incremental_py
  t_tests_unit_cli_test_update_lock_py(["✅ .../cli/test_update_lock.py"]):::guard
  t_tests_unit_cli_test_update_lock_py -.-> f_packages_core_src_repowise_core_workspace_update_py
  classDef changed fill:#dbeafe,stroke:#1d4ed8,color:#1e3a5f
  classDef warn fill:#fef3c7,stroke:#b45309,color:#78350f
  classDef guard fill:#dcfce7,stroke:#15803d,color:#14532d
Loading

Solid arrows: code that imports the changed files (17 direct dependents, from the last indexed snapshot). Dashed: history/tests.

🔥 Hotspots touched (3)

  • .../update_cmd/incremental.py: 8 commits/90d, 3 dependents · primary owner: Raghav Chamadiya (89%)
  • .../workspace/update.py: 24 commits/90d, 18 dependents · primary owner: Raghav Chamadiya (94%)
  • .../pipeline/incremental.py: 42 commits/90d, 27 dependents · primary owner: Raghav Chamadiya (93%)

🔗 Hidden coupling (2 files)

  • .../pipeline/incremental.py co-changes with these files (not in this PR):
    • .../pipeline/persist.py (14×, 🟡 notable)
    • .../update_cmd/persistence.py (13×, 🟡 notable)
  • .../workspace/update.py co-changes with .../update_cmd/command.py (13×, 🟡 notable), not in this PR.

💀 Dead code (1 finding)

  • 💀 .../pipeline/incremental.py _noop_log (confidence 0.65)

👀 Suggested reviewers @RaghavChamadiya


📊 See the full report for this PR
Your repo map with this PR's blast radius lit up, every caller of the contracts it changes, and health before and after. No sign-in. · ⭐ Star Repowise · 📥 Install bot · Silence on a single PR with [skip repowise] in the title · Per-repo toggle on repowise.dev/settings?tab=bot · Updated 2026-08-21 11:00 UTC

@RaghavChamadiya RaghavChamadiya left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @sloemo01 for tracing this to the writer instead of stopping at the analyzer. I confirmed the whole chain against main before merging:

  • run_partial_analysis builds its HealthAnalyzer at incremental.py:569 with no coverage_map
  • the analyzer defaults it to {} (engine.py:327)
  • the per-file lookup at engine.py:977 then yields None for both line_coverage_pct and branch_coverage_pct
  • upsert_health_metrics writes that None straight back (crud/analysis/health.py:1018)

So coverage really is erased, and it is erased for exactly the files someone just touched, which is the worst possible subset to lose it on. A repo that ingested coverage once would watch it decay along its own active development front, and nothing in the output says why.

Mirroring load_stored_function_mod_p80 rather than inventing a new loading shape is the right call, and wiring both callers means the workspace updater does not quietly keep the bug.

@RaghavChamadiya
RaghavChamadiya merged commit b0989d9 into repowise-dev:main Aug 21, 2026
9 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug] Incremental health analysis nulls coverage for every changed file

2 participants