Codebase intelligence for AI and humans: code health scores, auto-generated docs, git analytics, dead code detection, and architectural decisions via MCP.
Python aicode-complexitycode-healthcode-intelligencecode-qualitydead-codedeveloper-toolsdocumentationgit-analyticsmcpopen-sourcepythonrefactoringstatic-analysistechnical-debt
fix(cli): prune legacy init notices from state degraded (#4224) (#4285)
Rishabh Mishrabe280050f2d1
diff --git a/packages/cli/src/repowise/cli/_helpers/state.py b/packages/cli/src/repowise/cli/_helpers/state.pyindex 0a501aaed..7a7716a53 100644--- a/packages/cli/src/repowise/cli/_helpers/state.py+++ b/packages/cli/src/repowise/cli/_helpers/state.py@@ -79,8 +79,10 @@ def save_state(repo_path: Path, state: dict[str, Any], *, full_index: bool = Falprevious = read_state_commit(Path(repo_path))try:from repowise.cli import __version__ as _pkg_version+ from repowise.core.index_scope import clean_legacy_degraded_statefrom repowise.core.upgrade import stamp as _stamp_store_version+ clean_legacy_degraded_state(state)_stamp_store_version(state, package_version=_pkg_version, full_index=full_index)except Exception: # never let stamping block a persistpassdiff --git a/packages/cli/src/repowise/cli/commands/update_cmd/command.py b/packages/cli/src/repowise/cli/commands/update_cmd/command.pyindex 0e077dbf5..3782ed575 100644--- a/packages/cli/src/repowise/cli/commands/update_cmd/command.py+++ b/packages/cli/src/repowise/cli/commands/update_cmd/command.py@@ -788,6 +788,11 @@ def _load_sync_base(opts: UpdateOptions, run: UpdateRun) -> None:load_dotenv(repo_path)run.state = state = load_state(repo_path)+ # One-time migration: drop informational notices saved into state["degraded"]+ # by pre-v0.56.0 init runs (#4224, #3272).+ from repowise.core.index_scope import clean_legacy_degraded_state++ clean_legacy_degraded_state(state)run.index_only = _resolve_index_only_mode(index_only=opts.index_only, docs_flag=opts.docs_flag, state=state)diff --git a/packages/core/src/repowise/core/index_scope.py b/packages/core/src/repowise/core/index_scope.pyindex c16018be5..b39335f77 100644--- a/packages/core/src/repowise/core/index_scope.py+++ b/packages/core/src/repowise/core/index_scope.py@@ -152,6 +152,41 @@ def _dropped_files(value: Any) -> dict[str, Any] | None:}+def is_legacy_init_notice(message: str) -> bool:+ """Return True if *message* is an informational notice from an older init run.++ Before v0.56.0 (#3272), progress tips and file size-skips were emitted with+ warning weight and persisted into ``state["degraded"]``. #3272 reclassified+ them as notices so new init runs never persist them, but legacy indexes+ and subsequent updates carried them forward (#4224).+ """+ stripped = message.strip()+ return (+ stripped.startswith("Graph build can take several minutes")+ or stripped.startswith("Not indexed: ")+ or stripped == "...and more source files skipped on size"+ )+++def prune_legacy_degraded_notices(messages: list[str]) -> list[str]:+ """Filter out legacy informational notices from a degraded messages list."""+ return [msg for msg in messages if not is_legacy_init_notice(str(msg))]+++def clean_legacy_degraded_state(state: dict[str, Any]) -> None:+ """Prune legacy informational init notices from ``state`` in place (#4224)."""+ if "degraded" in state and isinstance(state["degraded"], list):+ pruned = prune_legacy_degraded_notices(state["degraded"])+ if pruned:+ state["degraded"] = pruned+ else:+ state.pop("degraded", None)+ if "index_scope" in state and isinstance(state["index_scope"], dict):+ analysis = state["index_scope"].get("analysis")+ if isinstance(analysis, dict) and isinstance(analysis.get("unavailable"), list):+ analysis["unavailable"] = prune_legacy_degraded_notices(analysis["unavailable"])++def resolve_index_scope(state: Mapping[str, Any] | None,config: Mapping[str, Any] | None = None,@@ -192,6 +227,8 @@ def resolve_index_scope(degraded = state.get("degraded", [])if isinstance(unavailable, list) and isinstance(degraded, list):unavailable = [*unavailable, *degraded]+ if isinstance(unavailable, list):+ unavailable = prune_legacy_degraded_notices(unavailable)skipped = analysis.get("skipped", [])return {"version": INDEX_SCOPE_VERSION,diff --git a/tests/unit/cli/test_update_degraded_persist_marker.py b/tests/unit/cli/test_update_degraded_persist_marker.pyindex 5e2bf3137..dd8dd1983 100644--- a/tests/unit/cli/test_update_degraded_persist_marker.py+++ b/tests/unit/cli/test_update_degraded_persist_marker.py@@ -115,3 +115,71 @@ def test_degraded_docs_update_leaves_a_marker_the_next_update_re_covers(state = json.loads((repo / ".repowise" / "state.json").read_text(encoding="utf-8"))assert "pending_repair" not in state+++def test_update_prunes_legacy_degraded_notices_from_state(tmp_path: Path, monkeypatch) -> None:+ from click.testing import CliRunner++ from repowise.cli.main import cli++ monkeypatch.setenv("REPOWISE_SKIP_EDITOR_SETUP", "1")+ repo = tmp_path / "repo"+ repo.mkdir()+ _git(repo, "init", "-q")+ _git(repo, "config", "user.email", "[email protected]")+ _git(repo, "config", "user.name", "T")+ (repo / "a.py").write_text("def a():\n return 1\n", encoding="utf-8")+ _git(repo, "add", ".")+ _git(repo, "commit", "-q", "-m", "c0")+ c0 = _git(repo, "rev-parse", "HEAD")+ (repo / ".repowise").mkdir()++ # Seed state with legacy init notices plus a real warning directly in state.json+ state_file = repo / ".repowise" / "state.json"+ state_file.write_text(+ json.dumps(+ {+ "last_sync_commit": c0,+ "last_docs_commit": c0,+ "docs_mode": "none",+ "degraded": [+ "Graph build can take several minutes on a first run. Safe to Ctrl-C — "+ "re-run 'repowise init --resume' to continue where it stopped.",+ " Not indexed: big.cs (9,745 KB, over the 2,048 KB limit)",+ " ...and more source files skipped on size",+ "Git indexing skipped: boom",+ ],+ }+ ),+ encoding="utf-8",+ )++ (repo / "a.py").write_text("def a():\n return 2\n", encoding="utf-8")+ _git(repo, "commit", "-q", "-am", "c1")++ result = CliRunner().invoke(cli, ["update", str(repo), "--index-only", "--no-workspace"])+ assert result.exit_code == 0, result.output++ state = json.loads(state_file.read_text(encoding="utf-8"))+ assert state.get("degraded") == ["Git indexing skipped: boom"]++ # When update runs on a state with only legacy notices, "degraded" is dropped entirely.+ (repo / "a.py").write_text("def a():\n return 3\n", encoding="utf-8")+ _git(repo, "commit", "-q", "-am", "c2")++ disk_state = json.loads(state_file.read_text(encoding="utf-8"))+ disk_state["degraded"] = [+ "Graph build can take several minutes on a first run. Safe to Ctrl-C — "+ "re-run 'repowise init --resume' to continue where it stopped."+ ]+ state_file.write_text(json.dumps(disk_state), encoding="utf-8")++ from repowise.cli.commands.update_cmd.command import release_update_lock++ release_update_lock(repo)+ result = CliRunner().invoke(cli, ["update", str(repo), "--index-only", "--no-workspace"])+ assert result.exit_code == 0, result.output++ state = json.loads(state_file.read_text(encoding="utf-8"))+ assert "degraded" not in state+diff --git a/tests/unit/core/test_index_scope.py b/tests/unit/core/test_index_scope.pyindex dbb19fda1..a388f8950 100644--- a/tests/unit/core/test_index_scope.py+++ b/tests/unit/core/test_index_scope.py@@ -76,3 +76,49 @@ def test_scope_without_traversal_does_not_claim_nothing_dropped() -> None:assert dropped_files_scope(None) is Noneassert resolve_index_scope({})["dropped_files"] is None+++def test_scope_drops_legacy_init_tips_and_size_skips() -> None:+ scope = resolve_index_scope(+ {+ "index_scope": {"analysis": {"unavailable": [], "skipped": []}},+ "degraded": [+ "Graph build can take several minutes on a first run. Safe to Ctrl-C — "+ "re-run 'repowise init --resume' to continue where it stopped.",+ " Not indexed: src/TestData.g.cs (9,745 KB, over the 2,048 KB limit)",+ " ...and more source files skipped on size",+ "Git indexing skipped: boom",+ ],+ }+ )+ assert scope["analysis"]["unavailable"] == ["Git indexing skipped: boom"]+++def test_scope_with_only_legacy_tips_reports_complete() -> None:+ from repowise.core.index_scope import compact_index_scope++ state = {+ "run_mode": "standard",+ "git_tier": "full",+ "docs_mode": "llm",+ "index_scope": {+ "git_commit_cap": 500,+ "file_pages": {"eligible": 10, "generated": 10, "omitted": 0},+ "provider": {"name": "openai", "model": "a-model", "embedder": "openai"},+ "search": {"full_text": "available", "semantic": "available"},+ },+ "git_history_coverage": {"eligible_files": 10, "retained_commits": 50},+ "full_upgrade": {"status": "complete", "completed_stages": ["generation"]},+ "degraded": [+ "Graph build can take several minutes on a first run. Safe to Ctrl-C — "+ "re-run 'repowise init --resume' to continue where it stopped.",+ " Not indexed: big.cs (9,745 KB, over the 2,048 KB limit)",+ " ...and more source files skipped on size",+ ],+ }+ scope = resolve_index_scope(state)+ compact = compact_index_scope(scope)+ assert compact is not None+ assert compact["status"] == "complete"+ assert "degraded_analyses" not in compact+diff --git a/tests/unit/server/mcp/test_index_scope_projection.py b/tests/unit/server/mcp/test_index_scope_projection.pyindex 58e19ac3d..59418a7c8 100644--- a/tests/unit/server/mcp/test_index_scope_projection.py+++ b/tests/unit/server/mcp/test_index_scope_projection.py@@ -331,7 +331,7 @@ def test_a_long_degraded_list_is_sampled_with_its_count() -> None:def test_a_real_analysis_id_survives_a_flood_of_run_warnings() -> None:"""Warnings with a leading space sort first alphabetically; the id still shows."""- warnings = [f" Not indexed: big/file_{i}.cs (3,000 KB, over the limit)" for i in range(16)]+ warnings = [f" Warning: failed to trace step {i}" for i in range(16)]scope = resolve_index_scope({**_FULL_STATE, "degraded": [*warnings, "dead_code"]})compact = compact_index_scope(scope)