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(update): re-score and re-parse an unchanged checkout when the analyzer or parser changed (#3035)

Raghav Chamadiya72ee7cd324e1
diff --git a/packages/cli/src/repowise/cli/commands/update_cmd/command.py b/packages/cli/src/repowise/cli/commands/update_cmd/command.py
index af92a3bb1..894502a8b 100644
--- a/packages/cli/src/repowise/cli/commands/update_cmd/command.py
+++ b/packages/cli/src/repowise/cli/commands/update_cmd/command.py
@@ -60,6 +60,8 @@ from .persistence import (
_repair_module_attribution,
_run_full_health_rescore,
heal_commit_offsets,
+ health_analyzer_changed,
+ parser_changed,
stamp_head_commit,
)
from .reporting import (
@@ -976,13 +978,29 @@ def run_update(
if not dry_run:
_repair_module_attribution(repo_path)
+ analyzer_changed = health_analyzer_changed(state)
git_is_current = bool(
head
and head == base_ref
and not config_changed
and not renderer_changed
and not working_tree_diffs
+ and not analyzer_changed
)
+ # The parse is read from the store, so it is asked only when git and the
+ # analyzer would otherwise let the run exit.
+ extraction_changed = git_is_current and parser_changed(repo_path)
+ if extraction_changed:
+ git_is_current = False
+ if analyzer_changed or extraction_changed:
+ # Not a code change, but every stored score or edge is a release behind.
+ # Falls through to the re-parse below, which re-scores from the graph it
+ # builds and writes no pages, so no model is called.
+ console.print(
+ "[yellow]Health analyzer changed since this index was scored; re-scoring.[/yellow]"
+ if analyzer_changed
+ else "[yellow]Parser changed since this index was built; re-parsing.[/yellow]"
+ )
# A page can be stale for a reason no commit explains: a cascade that ran
# out of budget, an interrupted run, an expiry. Git says nothing changed,
# so the shortcut below is the only place such a page could be skipped
@@ -1255,6 +1273,8 @@ def run_update(
not file_diffs
and not config_changed
and not renderer_changed
+ and not analyzer_changed
+ and not extraction_changed
and not stale_db_paths
and not stale_deterministic_ids
):
@@ -2403,7 +2423,7 @@ def run_update(
# update only reaches the changed files. Reusing this hook is what makes
# falling through cost nothing extra — the graph is already built.
rescored = False
- if health_config_changed or full_rescore_due(state, head_ts):
+ if health_config_changed or extraction_changed or full_rescore_due(state, head_ts):
with timed(timings, "rescore"):
rescored = run_decay_health_rescore(
repo_path, graph_builder, parsed_files, exclude_patterns
diff --git a/packages/cli/src/repowise/cli/commands/update_cmd/persistence.py b/packages/cli/src/repowise/cli/commands/update_cmd/persistence.py
index deb4a5f7f..49be1ba4d 100644
--- a/packages/cli/src/repowise/cli/commands/update_cmd/persistence.py
+++ b/packages/cli/src/repowise/cli/commands/update_cmd/persistence.py
@@ -1648,6 +1648,41 @@ def _full_rescore_interval_days() -> float:
return _FULL_RESCORE_INTERVAL_DAYS
+def parser_changed(repo_path: Path) -> bool:
+ """Whether the stored graph edges were written by a different parser.
+
+ Compares the fingerprint ``persist_incremental_edges`` stamped on the repo
+ row with the running ``parser_fingerprint()``. An unstamped row, or a store
+ that cannot be read, is **not** a change, for the reason
+ :func:`health_analyzer_changed` gives: the next commit's widen stamps it.
+ """
+ from repowise.cli.helpers import get_db_url_for_repo
+ from repowise.core.ingestion.parse_cache import parser_fingerprint
+ from repowise.core.persistence import (
+ create_engine,
+ create_session_factory,
+ get_repository_by_path,
+ get_session,
+ )
+
+ async def _stored() -> str | None:
+ engine = create_engine(get_db_url_for_repo(repo_path))
+ try:
+ sf = create_session_factory(engine)
+ async with get_session(sf) as session:
+ repo = await get_repository_by_path(session, str(repo_path))
+ return repo.graph_edges_parser_fingerprint if repo is not None else None
+ finally:
+ await engine.dispose()
+
+ try:
+ stored = run_async(_stored())
+ except Exception as exc:
+ log.debug("parser_change_check_failed", error=str(exc))
+ return False
+ return stored is not None and stored != parser_fingerprint()
+
+
def health_analyzer_changed(state: dict) -> bool:
"""Whether the stored health rows were written by a different analyzer.
diff --git a/packages/core/src/repowise/core/analysis/health/engine.py b/packages/core/src/repowise/core/analysis/health/engine.py
index f6f9adb2c..8d0fdac6c 100644
--- a/packages/core/src/repowise/core/analysis/health/engine.py
+++ b/packages/core/src/repowise/core/analysis/health/engine.py
@@ -97,12 +97,10 @@ log = structlog.get_logger(__name__)
# and re-scores on mismatch (see ``update_cmd.persistence.full_rescore_due``),
# instead of waiting out the 7-day decay timer.
#
-# Reach, stated honestly: the gate is only consulted once an update reaches the
-# incremental path, so this lands on the next update that has changed files. A
-# repo with no new commits returns at the "already up to date" branch and picks
-# the correction up on its next commit; workspace members and the hosted
-# indexer do not run this path at all. That is the same reach the decay timer
-# already has — this extends that trigger rather than adding a wider one.
+# Reach: a single-repo ``repowise update`` checks it before the "already up to
+# date" return, so a checkout with no new commits re-scores on its next update
+# too, from the graph it re-parses, with no model call. Workspace members and
+# the hosted indexer do not run this path at all.
#
# Deliberately *not* folded into ``config_fingerprint``: that fingerprint means
# "this repo's config content changed", and a workspace update answers drift in
diff --git a/tests/unit/cli/test_update_version_change_gate.py b/tests/unit/cli/test_update_version_change_gate.py
new file mode 100644
index 000000000..f65c2c47d
--- /dev/null
+++ b/tests/unit/cli/test_update_version_change_gate.py
@@ -0,0 +1,71 @@
+"""An analyzer or parser change must get past the "already up to date" return.
+
+With no new commit, ``head == base_ref`` is the normal state of a checkout, so
+the version stamps are the only thing that can tell ``update`` that every stored
+score or graph edge was written by an older build.
+"""
+
+from __future__ import annotations
+
+import pytest
+
+from repowise.cli.commands.update_cmd import command as upd_cmd
+from repowise.cli.helpers import load_state, save_state
+from repowise.core.analysis.health import HEALTH_ANALYZER_VERSION
+
+from .test_update_up_to_date_lock import _indexed_repo, _invoke_update
+
+UP_TO_DATE = "Already up to date"
+
+
+def test_current_versions_stay_up_to_date(tmp_path, monkeypatch: pytest.MonkeyPatch) -> None:
+ repo, _ = _indexed_repo(tmp_path)
+ state = load_state(repo)
+ save_state(repo, {**state, "health_analyzer_version": HEALTH_ANALYZER_VERSION})
+ rescored: list[int] = []
+ monkeypatch.setattr(upd_cmd, "parser_changed", lambda _p: False)
+ monkeypatch.setattr(
+ "repowise.cli.commands.update_cmd.persistence.run_decay_health_rescore",
+ lambda *a, **k: rescored.append(1) or True,
+ )
+
+ out = _invoke_update(repo)
+
+ assert UP_TO_DATE in out
+ assert not rescored
+
+
+def test_stale_analyzer_version_rescores_an_unchanged_checkout(tmp_path) -> None:
+ repo, c2 = _indexed_repo(tmp_path)
+ save_state(
+ repo, {**load_state(repo), "health_analyzer_version": HEALTH_ANALYZER_VERSION - 1}
+ )
+
+ out = _invoke_update(repo)
+
+ assert UP_TO_DATE not in out
+ assert "Health analyzer changed" in out
+ state = load_state(repo)
+ assert state["health_analyzer_version"] == HEALTH_ANALYZER_VERSION
+ assert state["last_sync_commit"] == c2
+ # Stamped, so the next run is quiet again.
+ assert UP_TO_DATE in _invoke_update(repo)
+
+
+def test_parser_change_reparses_an_unchanged_checkout(
+ tmp_path, monkeypatch: pytest.MonkeyPatch
+) -> None:
+ repo, _ = _indexed_repo(tmp_path)
+ save_state(repo, {**load_state(repo), "health_analyzer_version": HEALTH_ANALYZER_VERSION})
+ monkeypatch.setattr(upd_cmd, "parser_changed", lambda _p: True)
+ rescored: list[int] = []
+ monkeypatch.setattr(
+ "repowise.cli.commands.update_cmd.persistence.run_decay_health_rescore",
+ lambda *a, **k: rescored.append(1) or True,
+ )
+
+ out = _invoke_update(repo)
+
+ assert UP_TO_DATE not in out
+ assert "Parser changed" in out
+ assert rescored