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): write the repair marker after a docs-mode update (#4026)

Raghav Chamadiya9eec89f35af6
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 3a6df9ed0..b02d0d2b4 100644
--- a/packages/cli/src/repowise/cli/commands/update_cmd/command.py
+++ b/packages/cli/src/repowise/cli/commands/update_cmd/command.py
@@ -1835,6 +1835,7 @@ def _persist_docs(run: UpdateRun, docs: DocsPass) -> None:
require_config_rebuild_success=config.rebuild_required,
require_decision_persist_success=config.git_changed,
history_window_changed=config.git_changed,
+ failed_steps=docs.failed_steps,
timings=run.timings,
)
@@ -1872,6 +1873,17 @@ def _save_docs_state(run: UpdateRun, docs: DocsPass) -> None:
if run.knowledge_graph_result is not None:
_export_knowledge_graph(run)
+ # Before the pointer moves: the marker keeps the old one. A clean run leaves
+ # an earlier marker for the index-only update that widens to it.
+ if docs.failed_steps:
+ from .persistence import record_repair_marker
+
+ record_repair_marker(state, dict(state), docs.failed_steps)
+ console.print(
+ "[yellow]Some data for this commit range was not persisted; "
+ "the next update will re-cover it.[/yellow]"
+ )
+
# Never write a null pointer: the next update would refuse to run.
if head:
state["last_sync_commit"] = head
@@ -1890,8 +1902,10 @@ def _save_docs_state(run: UpdateRun, docs: DocsPass) -> None:
state["git_history_coverage"] = coverage.to_dict()
else:
state.pop("git_history_coverage", None)
- # Every row was rewritten under the current rules.
- state[GIT_HISTORY_VERSION_KEY] = GIT_HISTORY_VERSION
+ # Every row was rewritten under the current rules, unless they never
+ # reached the store; then the next update walks again.
+ if "Git persist" not in docs.failed_steps:
+ state[GIT_HISTORY_VERSION_KEY] = GIT_HISTORY_VERSION
save_state(repo_path, state)
diff --git a/packages/cli/src/repowise/cli/commands/update_cmd/options.py b/packages/cli/src/repowise/cli/commands/update_cmd/options.py
index a6dc2a4a9..721c73b3b 100644
--- a/packages/cli/src/repowise/cli/commands/update_cmd/options.py
+++ b/packages/cli/src/repowise/cli/commands/update_cmd/options.py
@@ -109,3 +109,5 @@ class DocsPass:
generated_pages: list = field(default_factory=list)
full_stats: dict = field(default_factory=dict)
db_total_pages: int = 0
+ # Range-scoped persist steps that failed; they become the repair marker.
+ failed_steps: list[str] = field(default_factory=list)
diff --git a/tests/unit/cli/test_update_degraded_persist_marker.py b/tests/unit/cli/test_update_degraded_persist_marker.py
index ea0580a4a..5e2bf3137 100644
--- a/tests/unit/cli/test_update_degraded_persist_marker.py
+++ b/tests/unit/cli/test_update_degraded_persist_marker.py
@@ -57,3 +57,61 @@ def test_degraded_git_persist_records_the_range_it_missed(tmp_path: Path, monkey
assert state["last_sync_commit"] == c1
assert state["pending_repair"]["from_commit"] == c0
assert "Git persist" in state["pending_repair"]["steps"]
+
+
+def test_degraded_docs_update_leaves_a_marker_the_next_update_re_covers(
+ tmp_path: Path, monkeypatch
+) -> None:
+ import asyncio
+
+ from click.testing import CliRunner
+
+ import repowise.core.pipeline.persist as persist
+ from repowise.cli.commands.update_cmd.command import release_update_lock
+ from repowise.cli.helpers import save_state
+ from repowise.cli.main import cli
+ from repowise.core.pipeline.full_index import index_repo_full
+
+ 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")
+ asyncio.run(index_repo_full(repo))
+ save_state(repo, {"last_sync_commit": c0, "last_docs_commit": c0, "docs_enabled": True})
+
+ (repo / "b.py").write_text("def b():\n return 2\n", encoding="utf-8")
+ _git(repo, "add", ".")
+ _git(repo, "commit", "-q", "-m", "c1")
+ c1 = _git(repo, "rev-parse", "HEAD")
+
+ real_symbols = persist.persist_incremental_symbols
+
+ async def _boom(*_args, **_kwargs):
+ raise RuntimeError("disk full")
+
+ monkeypatch.setattr(persist, "persist_incremental_symbols", _boom)
+ result = CliRunner().invoke(
+ cli, ["update", str(repo), "--docs", "--provider", "mock", "--no-workspace"]
+ )
+ assert result.exit_code == 0, result.output
+ assert "next update will re-cover it" in result.output
+
+ state = json.loads((repo / ".repowise" / "state.json").read_text(encoding="utf-8"))
+ assert state["last_sync_commit"] == c1
+ assert state["pending_repair"] == {"from_commit": c0, "steps": ["Symbol persist"]}
+
+ monkeypatch.setattr(persist, "persist_incremental_symbols", real_symbols)
+ # The first run's lock is released at exit, which never comes in-process.
+ release_update_lock(repo)
+ result = CliRunner().invoke(cli, ["update", str(repo), "--index-only", "--no-workspace"])
+ assert result.exit_code == 0, result.output
+ assert f"(from {c0[:8]})" in result.output
+
+ state = json.loads((repo / ".repowise" / "state.json").read_text(encoding="utf-8"))
+ assert "pending_repair" not in state