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): invalidate config-dependent index layers (#2235)

Raghav Chamadiyaa3e49b7692be
diff --git a/packages/cli/src/repowise/cli/commands/init_cmd/command.py b/packages/cli/src/repowise/cli/commands/init_cmd/command.py
index b45730304..ee29d15e2 100644
--- a/packages/cli/src/repowise/cli/commands/init_cmd/command.py
+++ b/packages/cli/src/repowise/cli/commands/init_cmd/command.py
@@ -80,6 +80,7 @@ from repowise.core.docs_mode import docs_mode_state_fields, resolve_docs_mode
from repowise.core.generation.languages import SUPPORTED_LANGUAGES
from repowise.core.generation.styles import DEFAULT_STYLE, list_styles, resolve_style
from repowise.core.reasoning import REASONING_MODES
+from repowise.core.repo_config import config_dependency_fingerprints
from ._interactive import offer_distill_rewrite_hook, offer_hook_install
from .generation import (
@@ -1794,6 +1795,7 @@ def init_command(
)
# Fingerprint after config writes so the first update doesn't false-positive.
base_state["config_fingerprint"] = config_fingerprint(repo_path)
+ base_state["config_dependency_fingerprints"] = config_dependency_fingerprints(repo_path)
# Index-only is the keyless default, so this is where most installs get
# their stamp. Without it `health_analyzer_changed` reads absent-as-
# unchanged and the version trigger never fires for them.
diff --git a/packages/cli/src/repowise/cli/commands/init_cmd/persistence.py b/packages/cli/src/repowise/cli/commands/init_cmd/persistence.py
index c41ddd9ea..33aa06463 100644
--- a/packages/cli/src/repowise/cli/commands/init_cmd/persistence.py
+++ b/packages/cli/src/repowise/cli/commands/init_cmd/persistence.py
@@ -29,6 +29,7 @@ from repowise.cli.state_persistence import build_kg_state, save_knowledge_graph_
from repowise.core.analysis.health import HEALTH_ANALYZER_VERSION
from repowise.core.docs_mode import docs_mode_state_fields
from repowise.core.generation.models import count_stub_fallbacks
+from repowise.core.repo_config import config_dependency_fingerprints
logger = structlog.get_logger(__name__)
@@ -423,6 +424,7 @@ def save_full_state_and_config(
# Re-save state with the fingerprint now that config.yaml is written.
state["config_fingerprint"] = config_fingerprint(repo_path)
+ state["config_dependency_fingerprints"] = config_dependency_fingerprints(repo_path)
# This index's health rows were written by the current analyzer, so start
# tracking it here — otherwise a fresh install carries no stamp and the
# first analyzer change after it cannot tell it needs a re-score.
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 56577cf53..3f607d2d1 100644
--- a/packages/cli/src/repowise/cli/commands/update_cmd/command.py
+++ b/packages/cli/src/repowise/cli/commands/update_cmd/command.py
@@ -11,6 +11,7 @@ from __future__ import annotations
import sys
import time
+from collections.abc import Callable
from enum import StrEnum
from pathlib import Path
from typing import Any
@@ -80,6 +81,22 @@ log = structlog.get_logger(__name__)
_EFFICACY_LOOKBACK_SECONDS = 7 * 86400.0
+def _generation_warning_handler(
+ degraded: list[str], *, require_embedding_success: bool
+) -> Callable[[str], None]:
+ """Record generation warnings and make required embedding writes fatal."""
+
+ def _handle(message: str) -> None:
+ degraded.append(message)
+ if require_embedding_success:
+ raise RuntimeError(
+ "Configuration-triggered page embedding failed; the previous "
+ "fingerprint was retained so the next update retries."
+ )
+
+ return _handle
+
+
def _docs_provider_prompt_allowed(emitter: Any) -> bool:
"""Whether a docs run may block on an interactive provider prompt.
@@ -429,12 +446,8 @@ def _render_full_upgrade_dry_run(
page_label = f"{recorded_pages:,}" if isinstance(recorded_pages, int) else "unknown"
console.print("[yellow]Dry run — full upgrade plan:[/yellow]")
- console.print(
- f" Provider: [cyan]{planned_provider}[/cyan] / [cyan]{planned_model}[/cyan]"
- )
- console.print(
- f" Git tier: [cyan]{current_git_tier}[/cyan] -> [cyan]FULL[/cyan]"
- )
+ console.print(f" Provider: [cyan]{planned_provider}[/cyan] / [cyan]{planned_model}[/cyan]")
+ console.print(f" Git tier: [cyan]{current_git_tier}[/cyan] -> [cyan]FULL[/cyan]")
console.print(f" Pages currently recorded: [cyan]{page_label}[/cyan]")
console.print(" The whole-repository wiki would be generated. No changes made.")
@@ -586,12 +599,10 @@ def run_update(
a no-op until you committed.
"""
start = time.monotonic()
- # Per-stage wall clock for this run, written to ``state.json`` as
- # ``phase_timings`` by the paths that rebuild the index. ``run`` is the
- # denominator; stages nest and overlap, so compare each against it and
- # never against their sum. The fast paths (already up to date, no changed
- # files, config-only re-score) do not record: they do no stage work and
- # would overwrite the last real run's numbers with nothing.
+ # Per-stage wall clock for this run, written to ``state.json`` by every path
+ # that mutates state. ``run`` is the denominator; stages nest and overlap,
+ # so compare each against it and never against their sum. Retaining an older
+ # run's table makes a cheap config/no-op update claim work it did not do.
timings = PhaseTimings()
timings.start("run")
@@ -825,10 +836,53 @@ def run_update(
# even when git is unchanged. A missing prior fingerprint is backfilled, not
# treated as a change. ``config_changed`` gates every "nothing to do" path.
from repowise.cli.helpers import config_fingerprint
+ from repowise.core.repo_config import (
+ changed_config_dependencies,
+ config_dependency_fingerprints,
+ )
prev_config_fp = state.get("config_fingerprint")
curr_config_fp = config_fingerprint(repo_path)
config_changed = prev_config_fp is not None and prev_config_fp != curr_config_fp
+ # Use the CLI's tolerant loader once. A malformed file has historically
+ # warned and fallen back to defaults; semantic invalidation must not turn
+ # that established recovery path into an early hard crash.
+ cfg = load_config(repo_path)
+ curr_dependency_fps = config_dependency_fingerprints(repo_path, config=cfg)
+ changed_dependencies = (
+ changed_config_dependencies(
+ state.get("config_dependency_fingerprints"), curr_dependency_fps
+ )
+ if config_changed
+ else set()
+ )
+ legacy_config_change = config_changed and changed_dependencies is None
+ dependency_changes = changed_dependencies or set()
+ traversal_config_changed = (
+ legacy_config_change
+ or "traversal" in dependency_changes
+ or "other" in dependency_changes
+ )
+ git_config_changed = (
+ legacy_config_change or traversal_config_changed or "git_history" in dependency_changes
+ )
+ health_config_changed = (
+ legacy_config_change
+ or traversal_config_changed
+ or git_config_changed
+ or "health" in dependency_changes
+ or "other" in dependency_changes
+ )
+ generation_config_changed = (
+ legacy_config_change
+ or traversal_config_changed
+ or git_config_changed
+ or "generation" in dependency_changes
+ )
+ config_rebuild_required = config_changed and bool(
+ legacy_config_change
+ or dependency_changes - {"state_only"}
+ )
# A structural renderer upgrade is not a code change and not a config
# change, but it still leaves every file page a release behind, because
@@ -909,7 +963,11 @@ def run_update(
# would make the very next renderer upgrade look like the first stamp
# rather than a change, silently skipping the regeneration it should
# trigger.
- needs_backfill = prev_config_fp is None or prev_renderer_fp is None
+ needs_backfill = (
+ prev_config_fp is None
+ or prev_renderer_fp is None
+ or not isinstance(state.get("config_dependency_fingerprints"), dict)
+ )
# Self-heal a row a pre-fix run left behind: state.json can already be
# current here while the DB head_commit is still the last full index.
#
@@ -926,12 +984,15 @@ def run_update(
else:
try:
if needs_backfill:
+ timings.stop("run")
save_state(
repo_path,
{
**state,
"config_fingerprint": curr_config_fp,
+ "config_dependency_fingerprints": curr_dependency_fps,
"renderer_fingerprint": curr_renderer_fp,
+ "phase_timings": timings.totals,
},
)
stamp_head_commit(repo_path, head)
@@ -1142,6 +1203,7 @@ def run_update(
**state,
"last_sync_commit": head,
"config_fingerprint": curr_config_fp,
+ "config_dependency_fingerprints": curr_dependency_fps,
"renderer_fingerprint": curr_renderer_fp,
}
# base_ref has already been widened to any unrepaired range by this
@@ -1155,6 +1217,8 @@ def run_update(
persisted.pop("pending_repair", None)
if not resolved_index_only and head:
persisted["last_docs_commit"] = head
+ timings.stop("run")
+ persisted["phase_timings"] = timings.totals
save_state(repo_path, persisted)
# Keep the DB freshness stamp in lockstep with state.json: the server's
# /repos endpoint reads head_commit from the row, not the state file.
@@ -1176,7 +1240,7 @@ def run_update(
)
return UpdateOutcome.NOOP
- if config_changed:
+ if health_config_changed:
# Full re-score (not the partial update) so unchanged files pick up the
# new rules/excludes instead of being left stale.
console.print("[yellow]Config files changed — re-running health analysis.[/yellow]")
@@ -1190,9 +1254,17 @@ def run_update(
# changed files present we fall through to the normal incremental path and
# force the full re-score at its existing hook, which reuses the graph that
# path already builds — same re-score, no second traverse.
- if config_changed and not file_diffs:
+ if (
+ config_changed
+ and not file_diffs
+ and not git_config_changed
+ and not generation_config_changed
+ ):
if dry_run:
- console.print("[yellow]Dry run — health would be re-scored. No changes made.[/yellow]")
+ action = (
+ "health would be re-scored" if health_config_changed else "state would be updated"
+ )
+ console.print(f"[yellow]Dry run — {action}. No changes made.[/yellow]")
if emitter is not None:
emitter.done(
ok=True,
@@ -1202,16 +1274,35 @@ def run_update(
outcome=UpdateOutcome.DRY_RUN.value,
)
return UpdateOutcome.DRY_RUN
- cfg = load_config(repo_path)
- exclude_patterns = list(cfg.get("exclude_patterns") or [])
- if emitter is not None:
- emitter.stage("rescore_health")
- try:
- _run_full_health_rescore(repo_path, exclude_patterns, state, head, curr_config_fp)
- except Exception as exc:
+ if health_config_changed:
+ cfg = load_config(repo_path)
+ exclude_patterns = list(cfg.get("exclude_patterns") or [])
if emitter is not None:
- emitter.error(str(exc))
- raise
+ emitter.stage("rescore_health")
+ try:
+ _run_full_health_rescore(
+ repo_path,
+ exclude_patterns,
+ state,
+ head,
+ curr_config_fp,
+ dependency_fingerprints=curr_dependency_fps,
+ timings=timings,
+ )
+ except Exception as exc:
+ if emitter is not None:
+ emitter.error(str(exc))
+ raise
+ else:
+ updated_state = {
+ **state,
+ "last_sync_commit": head,
+ "config_fingerprint": curr_config_fp,
+ "config_dependency_fingerprints": curr_dependency_fps,
+ }
+ timings.stop("run")
+ updated_state["phase_timings"] = timings.totals
+ save_state(repo_path, updated_state)
# No stamp_head_commit here, which is the behaviour this branch has
# always had: the re-score's `upsert_repository` re-reads HEAD from
# disk and advances the row itself. It re-reads rather than being told,
@@ -1237,8 +1328,6 @@ def run_update(
degraded: list[str] = []
# Re-parse changed files and rebuild graph for affected pages
- cfg = load_config(repo_path)
-
# Read exclude patterns from config (set during init or via web UI)
exclude_patterns: list[str] = list(cfg.get("exclude_patterns") or [])
@@ -1251,6 +1340,7 @@ def run_update(
# repo-wide aggregates are unaffected. ``head_ts`` anchors the periodic
# idle-file health re-score gate.
git_decay_map: dict[str, dict] = {}
+ full_git_summaries: list[Any] = []
head_ts = _head_commit_ts(repo_path)
parsed_files, source_map, graph_builder, repo_structure, file_count, git_meta_map = (
_rebuild_graph_and_git(
@@ -1262,6 +1352,8 @@ def run_update(
include_submodules=bool(state.get("include_submodules", False)),
include_nested_repos=bool(state.get("include_nested_repos", False)),
idle_decay_sink=git_decay_map,
+ force_full_git=git_config_changed,
+ git_summary_sink=full_git_summaries,
timings=timings,
)
)
@@ -1310,6 +1402,11 @@ def run_update(
stale_extra = list(dict.fromkeys([*stale_renderer_paths, *stale_db_paths]))
if stale_extra:
affected.regenerate = list(dict.fromkeys([*affected.regenerate, *stale_extra]))
+ if generation_config_changed:
+ # Generation settings affect selection and repo-wide synthesis, not
+ # merely the files touched by this commit. Recreate the same complete
+ # page set a clean init would choose.
+ affected.regenerate = [pf.file_info.path for pf in parsed_files]
if affected.stale_due_to_budget > 0:
console.print(
@@ -1380,6 +1477,20 @@ def run_update(
dead_code_report,
(state.get("knowledge_graph") or {}).get("fingerprint"),
)
+ if generation_config_changed and knowledge_graph_result is not None:
+ # Repo-wide pages (especially onboarding's guided tour) read the
+ # persisted KG context during generation. Publish the freshly rebuilt
+ # structure before rendering so an exclude change cannot regenerate
+ # those pages from the previous traversal's tour.
+ from repowise.cli.state_persistence import save_knowledge_graph_json
+
+ try:
+ save_knowledge_graph_json(repo_path, knowledge_graph_result)
+ except Exception as exc:
+ raise RuntimeError(
+ "Configuration-driven knowledge-graph refresh failed; the previous "
+ "fingerprint was retained so the next update retries."
+ ) from exc
if index_only:
# A repo whose wiki was rendered from templates keeps it current here.
@@ -1406,6 +1517,7 @@ def run_update(
# keep separate: a file page can no longer be model-written, so a
# page that predates the single-renderer change re-renders to its
# structural form here, which is the shape it now has.
+ degraded_before_render = len(degraded)
with timed(timings, "render"):
det_pages = regenerate_deterministic_pages(
repo_path=repo_path,
@@ -1420,6 +1532,12 @@ def run_update(
degraded=degraded,
dead_code_report=dead_code_report,
prior_page_ids=prior_ids,
+ full_scope=generation_config_changed,
+ )
+ if generation_config_changed and len(degraded) > degraded_before_render:
+ raise RuntimeError(
+ "Configuration-driven page generation failed; the previous "
+ "fingerprint was retained so the next update retries."
)
if det_pages:
@@ -1443,6 +1561,46 @@ def run_update(
if emitter is not None:
emitter.stage("persist")
try:
+ persisted_changed_paths = (
+ [pf.file_info.path for pf in parsed_files]
+ if traversal_config_changed
+ else [fd.path for fd in file_diffs]
+ )
+ config_vector_store = (
+ _build_update_vector_store(
+ repo_path,
+ cfg,
+ degraded,
+ required=(config_rebuild_required and docs_mode == "deterministic"),
+ )
+ if traversal_config_changed or generation_config_changed
+ else None
+ )
+ if generation_config_changed and det_pages and config_vector_store is not None:
+ from repowise.core.persistence.vector_store import embed_item
+
+ embed_items = [
+ item
+ for page in det_pages
+ if (
+ item := embed_item(
+ page.page_id,
+ title=page.title,
+ page_type=page.page_type,
+ target_path=page.target_path,
+ summary=page.summary,
+ content=page.content,
+ )
+ )
+ is not None
+ ]
+ try:
+ run_async(config_vector_store.embed_batch(embed_items))
+ except Exception as exc:
+ raise RuntimeError(
+ "Configuration-driven vector refresh failed; the previous "
+ "fingerprint was retained so the next update retries."
+ ) from exc
_persist_index_only_update(
repo_path,
graph_builder,
@@ -1452,7 +1610,7 @@ def run_update(
state,
head,
start,
- [fd.path for fd in file_diffs],
+ persisted_changed_paths,
file_diffs=file_diffs,
knowledge_graph_result=knowledge_graph_result,
parsed_files=parsed_files,
@@ -1465,7 +1623,17 @@ def run_update(
git_decay_map=git_decay_map,
exclude_patterns=exclude_patterns,
head_ts=head_ts,
- force_full_rescore=config_changed,
+ force_full_rescore=health_config_changed,
+ full_git_summary=(full_git_summaries[0] if full_git_summaries else None),
+ reconcile_full_scope=traversal_config_changed,
+ full_generation_page_ids=(
+ {page.page_id for page in det_pages}
+ if generation_config_changed and docs_mode == "deterministic"
+ else None
+ ),
+ dependency_fingerprints=curr_dependency_fps,
+ vector_store=config_vector_store,
+ require_config_rebuild_success=config_rebuild_required,
timings=timings,
)
except Exception as exc:
@@ -1512,6 +1680,7 @@ def run_update(
# Honor the wiki style chosen at init (or via `repowise restyle`) so pages
# regenerated for changed files match the rest of the wiki's voice.
wiki_style=cfg.get("wiki_style", "comprehensive"),
+ cache_enabled=not generation_config_changed,
# An incremental update regenerates only the changed files' pages, and
# it feeds generate_all a parsed_files filtered to those files. Levels 3
# and up describe the whole repository from parsed_files, so without
@@ -1521,7 +1690,7 @@ def run_update(
# leave the repo-wide pages for a full run — the same guard the
# deterministic index-only update already uses. `repowise generate`
# refreshes the repo-wide pages correctly, from the complete view.
- file_pages_only=True,
+ file_pages_only=not generation_config_changed,
)
# Resolve the generation provider. If the repo wants docs but was never
@@ -1561,6 +1730,42 @@ def run_update(
decision_policy = resolve_policy(cfg).policy
new_decision_markers: list = []
+
+ # A wider/different history window changes the evidence available to the
+ # Git archaeology source even when no source file changed. Re-run that
+ # source against the freshly rebuilt full metadata map so update converges
+ # with a clean index. Treat a source failure as a required config-rebuild
+ # failure; otherwise the new fingerprint would suppress the only retry.
+ if git_config_changed and decision_policy.source_enabled("git_archaeology"):
+ try:
+ from repowise.core.analysis.decision_extractor import DecisionExtractor
+
+ history_extractor = DecisionExtractor(
+ repo_path=repo_path,
+ provider=provider,
+ graph=graph_builder.graph(),
+ git_meta_map=git_meta_map,
+ parsed_files=parsed_files,
+ source_map=source_map,
+ policy=decision_policy,
+ )
+ with cost_tracker.record_as("decision_extraction"):
+ history_report = run_async(
+ history_extractor.extract_all(enabled_sources={"git_archaeology"})
+ )
+ if history_report.failures:
+ details = "; ".join(
+ f"{source}: {error}"
+ for source, error in sorted(history_report.failures.items())
+ )
+ raise RuntimeError(details)
+ new_decision_markers.extend(history_report.decisions)
+ except Exception as exc:
+ raise RuntimeError(
+ "Configuration-triggered Git decision extraction failed; the previous "
+ "fingerprint was retained so the next update retries."
+ ) from exc
+
try:
from repowise.core.analysis.decision_extractor import DecisionExtractor
@@ -1578,8 +1783,8 @@ def run_update(
# Label these calls as decision extraction so the Costs page can
# tell them apart from page regeneration (both ride this provider).
with cost_tracker.record_as("decision_extraction"):
- new_decision_markers = run_async(
- extractor.scan_inline_markers(restrict_to_files=changed_paths)
+ new_decision_markers.extend(
+ run_async(extractor.scan_inline_markers(restrict_to_files=changed_paths))
)
if new_decision_markers and verbose:
console.print(
@@ -1712,7 +1917,12 @@ def run_update(
# Build the shared vector store once: reused by the supersession detector
# below and by the decision upsert in _persist (semantic dedup + search).
- decision_vector_store = _build_update_vector_store(repo_path, cfg, degraded)
+ decision_vector_store = _build_update_vector_store(
+ repo_path,
+ cfg,
+ degraded,
+ required=(traversal_config_changed or generation_config_changed),
+ )
# --- Two-pass decision evolution (Phase 3C), BEFORE page regeneration ----
# Cross-reference the diff + new commit bodies against existing decisions
@@ -1907,6 +2117,12 @@ def run_update(
git_meta_map=git_meta_map,
repo_path=repo_path,
on_page_ready=checkpointer.on_page_ready,
+ on_warning=_generation_warning_handler(
+ degraded,
+ require_embedding_success=(
+ traversal_config_changed or generation_config_changed
+ ),
+ ),
)
finally:
await checkpointer.close()
@@ -1998,6 +2214,11 @@ def run_update(
decay_paths=affected.decay_only,
parsed_files=parsed_files,
git_decay_map=git_decay_map,
+ full_git_summary=(full_git_summaries[0] if full_git_summaries else None),
+ reconcile_full_scope=traversal_config_changed,
+ reconcile_full_generation=generation_config_changed,
+ require_config_rebuild_success=config_rebuild_required,
+ require_decision_persist_success=git_config_changed,
timings=timings,
)
except Exception as exc:
@@ -2019,7 +2240,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 config_changed or full_rescore_due(state, head_ts):
+ if health_config_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
@@ -2032,6 +2253,11 @@ def run_update(
if head_ts is not None:
state["last_full_rescore_at"] = head_ts
state["health_analyzer_version"] = HEALTH_ANALYZER_VERSION
+ if health_config_changed and not rescored:
+ raise RuntimeError(
+ "Configuration-triggered health re-score failed; the previous "
+ "fingerprint was retained so the next update retries."
+ )
# ---- Editor project files (best-effort) ----
with timed(timings, "editor_files"):
@@ -2056,6 +2282,7 @@ def run_update(
# so adding len(generated_pages) every run inflated the count forever.
state["total_pages"] = db_total_pages
state["config_fingerprint"] = config_fingerprint(repo_path)
+ state["config_dependency_fingerprints"] = curr_dependency_fps
state["renderer_fingerprint"] = _current_renderer_fingerprint(repo_path)
# Closed at the state write, as the index-only path does, so the two
# paths' ``run`` rows measure the same span.
diff --git a/packages/cli/src/repowise/cli/commands/update_cmd/deterministic.py b/packages/cli/src/repowise/cli/commands/update_cmd/deterministic.py
index 7ac984f4d..0c384558f 100644
--- a/packages/cli/src/repowise/cli/commands/update_cmd/deterministic.py
+++ b/packages/cli/src/repowise/cli/commands/update_cmd/deterministic.py
@@ -91,6 +91,7 @@ def regenerate_deterministic_pages(
degraded: list[str],
dead_code_report: Any = None,
prior_page_ids: dict | None = None,
+ full_scope: bool = False,
) -> list:
"""Re-render the template pages for *regenerate_paths*. Never raises.
@@ -117,6 +118,7 @@ def regenerate_deterministic_pages(
dead_code_report=dead_code_report,
prior_page_ids=prior_page_ids,
degrade_label="Template page refresh",
+ full_scope=full_scope,
)
@@ -135,6 +137,7 @@ def _render_pages(
dead_code_report: Any,
prior_page_ids: dict | None,
degrade_label: str,
+ full_scope: bool = False,
) -> list:
"""Render the changed files' pages from structure (free, no LLM).
@@ -145,8 +148,16 @@ def _render_pages(
from repowise.core.providers.llm.template import TemplateProvider
regen_set = set(regenerate_paths)
- affected_parsed = [pf for pf in parsed_files if pf.file_info.path in regen_set]
- affected_source = {p: s for p, s in source_map.items() if p in regen_set}
+ affected_parsed = (
+ list(parsed_files)
+ if full_scope
+ else [pf for pf in parsed_files if pf.file_info.path in regen_set]
+ )
+ affected_source = (
+ dict(source_map)
+ if full_scope
+ else {p: s for p, s in source_map.items() if p in regen_set}
+ )
if not affected_parsed:
return []
@@ -154,7 +165,7 @@ def _render_pages(
config = GenerationConfig.from_repo_config(
cfg,
deterministic=True,
- file_pages_only=True,
+ file_pages_only=not full_scope,
max_concurrency=concurrency,
language=cfg.get("language", "en"),
enable_onboarding=bool(cfg.get("enable_onboarding", True)),
diff --git a/packages/cli/src/repowise/cli/commands/update_cmd/incremental.py b/packages/cli/src/repowise/cli/commands/update_cmd/incremental.py
index b134474d0..4c50cfc7a 100644
--- a/packages/cli/src/repowise/cli/commands/update_cmd/incremental.py
+++ b/packages/cli/src/repowise/cli/commands/update_cmd/incremental.py
@@ -7,6 +7,7 @@ routing core log output through the CLI ``console``.
from __future__ import annotations
+from pathlib import Path
from typing import Any
from repowise.cli.helpers import console, run_async
@@ -14,7 +15,11 @@ from repowise.core.pipeline import PhaseTimings, timed
def _build_update_vector_store(
- repo_path: Any, cfg: dict, degraded: list[str] | None = None
+ repo_path: Any,
+ cfg: dict,
+ degraded: list[str] | None = None,
+ *,
+ required: bool = False,
) -> Any | None:
"""Build the shared page/decision vector store for the update path.
@@ -33,10 +38,17 @@ def _build_update_vector_store(
from repowise.cli.providers import build_embedder, build_vector_store, resolve_embedder
embedder = build_embedder(resolve_embedder(cfg.get("embedder")), repo_path)
- return build_vector_store(repo_path, embedder)
+ store = build_vector_store(repo_path, embedder)
+ if required and store is None and (Path(repo_path) / ".repowise" / "lancedb").exists():
+ raise RuntimeError(
+ "the configured embedder cannot safely refresh the existing vector index"
+ )
+ return store
except Exception as exc:
if degraded is not None:
degraded.append(f"Decision vector store: {type(exc).__name__}: {exc}")
+ if required:
+ raise
return None
@@ -83,6 +95,8 @@ def _rebuild_graph_and_git(
include_submodules: bool = False,
include_nested_repos: bool = False,
idle_decay_sink: dict[str, dict] | None = None,
+ force_full_git: bool = False,
+ git_summary_sink: list[Any] | None = None,
timings: PhaseTimings | None = None,
) -> tuple[list, dict[str, bytes], Any, Any, int, dict[str, dict]]:
"""Re-traverse + parse the repo, rebuild the graph (+ framework edges), and
@@ -120,6 +134,8 @@ def _rebuild_graph_and_git(
include_submodules=include_submodules,
include_nested_repos=include_nested_repos,
idle_decay_sink=idle_decay_sink,
+ force_full_git=force_full_git,
+ git_summary_sink=git_summary_sink,
log=console.print,
timings=timings,
)
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 4f74add1e..d8cbd845a 100644
--- a/packages/cli/src/repowise/cli/commands/update_cmd/persistence.py
+++ b/packages/cli/src/repowise/cli/commands/update_cmd/persistence.py
@@ -91,14 +91,13 @@ async def _coverage_for_rescore(
repo_id: str,
repo_path: Path,
parsed_files: list[Any],
-) -> tuple[dict[str, dict], list[Any], str | None]:
+) -> tuple[dict[str, dict], list[Any], str | None, bool]:
"""Coverage to feed a health re-score, preserved across updates.
Default: reload the rows already persisted (no re-parse). When
``coverage.reingest_on_update`` is set, re-discover and re-resolve a
- fresh report instead. Returns ``(coverage_map, files_to_persist,
- source_format)`` — ``files_to_persist`` is empty on the reload path
- (rows are unchanged) and populated when re-ingested.
+ fresh report instead. The final return value marks an authoritative
+ reingestion, including an empty result that must clear stored rows.
"""
import json
@@ -125,7 +124,12 @@ async def _coverage_for_rescore(
path_prefix=cfg.path_prefix,
)
if resolved.coverage_map:
- return resolved.coverage_map, resolved.files, resolved.source_format
+ return resolved.coverage_map, resolved.files, resolved.source_format, True
+
+ # Reingestion is authoritative. Falling back to old rows when a report
+ # disappeared (or now maps to nothing) makes this config refresh differ
+ # from a clean index and then incorrectly stamps stale data current.
+ return {}, [], None, True
rows = await load_coverage_for_repo(session, repo_id)
coverage_map: dict[str, dict] = {}
@@ -143,7 +147,7 @@ async def _coverage_for_rescore(
"total_coverable_lines": row.total_coverable_lines or 0,
"source_format": source_format,
}
- return coverage_map, [], source_format
+ return coverage_map, [], source_format, False
async def _persist_partial_health(session: Any, repo_id: str, report: Any) -> None:
@@ -365,6 +369,12 @@ def _persist_index_only_update(
exclude_patterns: list[str] | None = None,
head_ts: float | None = None,
force_full_rescore: bool = False,
+ full_git_summary: Any | None = None,
+ reconcile_full_scope: bool = False,
+ full_generation_page_ids: set[str] | None = None,
+ dependency_fingerprints: dict[str, str] | None = None,
+ vector_store: Any | None = None,
+ require_config_rebuild_success: bool = False,
timings: PhaseTimings | None = None,
) -> None:
"""Persist the index-only update (graph + symbols + git + dead-code + health + KG),
@@ -390,6 +400,7 @@ def _persist_index_only_update(
# (which also collects repo-wide and non-DB failures) because only these
# strand data the advancing sync pointer would otherwise skip forever.
failed_steps: list[str] = []
+ degraded_before_persist = len(degraded)
run_async(
persist_incremental_index(
repo_path,
@@ -402,13 +413,23 @@ def _persist_index_only_update(
knowledge_graph_result=knowledge_graph_result,
parsed_files=parsed_files,
git_decay_map=git_decay_map,
+ full_git_summary=full_git_summary,
+ reconcile_full_scope=reconcile_full_scope,
+ full_generation_page_ids=full_generation_page_ids,
+ vector_store=vector_store,
log=console.print,
degraded=degraded,
failed_steps=failed_steps,
timings=timings,
)
)
+ if require_config_rebuild_success and len(degraded) > degraded_before_persist:
+ raise RuntimeError(
+ "Configuration rebuild did not update every dependent store; "
+ "the previous fingerprint was retained so the next update retries."
+ )
from repowise.cli.helpers import config_fingerprint
+ from repowise.core.repo_config import config_dependency_fingerprints
from .command import _current_renderer_fingerprint
@@ -433,6 +454,11 @@ def _persist_index_only_update(
if head_ts is not None:
last_full_rescore_at = head_ts
health_analyzer_version = HEALTH_ANALYZER_VERSION
+ if force_full_rescore and not rescored:
+ raise RuntimeError(
+ "Configuration-triggered health re-score failed; the previous "
+ "fingerprint was retained so the next update retries."
+ )
new_state = {
**state,
@@ -440,6 +466,11 @@ def _persist_index_only_update(
"last_full_rescore_at": last_full_rescore_at,
"health_analyzer_version": health_analyzer_version,
"config_fingerprint": config_fingerprint(repo_path),
+ "config_dependency_fingerprints": (
+ dependency_fingerprints
+ if dependency_fingerprints is not None
+ else config_dependency_fingerprints(repo_path)
+ ),
# Record the renderer this run rendered with. Without this an index-only
# update that regenerated stale file pages leaves the stored fingerprint
# at its old value, so ``renderer_changed`` stays true and every later
@@ -587,6 +618,11 @@ def _persist_full_update(
decay_paths: list[str] | None = None,
parsed_files: list | None = None,
git_decay_map: dict | None = None,
+ full_git_summary: Any | None = None,
+ reconcile_full_scope: bool = False,
+ reconcile_full_generation: bool = False,
+ require_config_rebuild_success: bool = False,
+ require_decision_persist_success: bool = False,
timings: PhaseTimings | None = None,
) -> int:
"""Persist a full (LLM-regenerating) update in one transaction.
@@ -622,6 +658,11 @@ def _persist_full_update(
decay_paths=decay_paths,
parsed_files=parsed_files,
git_decay_map=git_decay_map,
+ full_git_summary=full_git_summary,
+ reconcile_full_scope=reconcile_full_scope,
+ reconcile_full_generation=reconcile_full_generation,
+ require_config_rebuild_success=require_config_rebuild_success,
+ require_decision_persist_success=require_decision_persist_success,
timings=timings,
)
)
@@ -645,6 +686,11 @@ async def _persist_full_update_async(
decay_paths: list[str] | None = None,
parsed_files: list | None = None,
git_decay_map: dict | None = None,
+ full_git_summary: Any | None = None,
+ reconcile_full_scope: bool = False,
+ reconcile_full_generation: bool = False,
+ require_config_rebuild_success: bool = False,
+ require_decision_persist_success: bool = False,
timings: PhaseTimings | None = None,
) -> int:
from repowise.cli.helpers import get_db_url_for_repo
@@ -664,6 +710,7 @@ async def _persist_full_update_async(
url = get_db_url_for_repo(repo_path)
engine = create_engine(url)
+ degraded_before_persist = len(degraded)
# Filled by the tombstone step; read by the full-text block after the
# session closes, so it has to survive a step that was skipped.
tombstoned_page_ids: list[str] = []
@@ -679,6 +726,33 @@ async def _persist_full_update_async(
repo = await upsert_repository(session, name=repo_name, local_path=str(repo_path))
repo_id = repo.id
+ if reconcile_full_scope:
+ try:
+ from repowise.core.pipeline.persist import (
+ reconcile_full_index_scope,
+ )
+
+ current_graph_paths = set(
+ getattr(
+ graph_builder,
+ "traversed_file_paths",
+ {parsed.file_info.path for parsed in parsed_files or []},
+ )
+ )
+ with timed(timings, "persist.scope_reconcile"):
+ tombstoned_page_ids = await reconcile_full_index_scope(
+ session,
+ repo_id,
+ current_graph_paths,
+ set(git_meta_map),
+ )
+ if tombstoned_page_ids and decision_vector_store is not None:
+ await decision_vector_store.delete_many(tombstoned_page_ids)
+ except Exception as exc:
+ _skip("Config scope reconciliation", exc)
+ if require_config_rebuild_success:
+ raise
+
# Pages first and without a net: everything else is derived
# metadata, but a docs-mode update that can't write pages failed.
# Batched (one SELECT + one flush); the checkpointer sink already
@@ -686,6 +760,24 @@ async def _persist_full_update_async(
with timed(timings, "persist.pages"):
await upsert_pages_from_generated(session, generated_pages, repo_id)
+ if reconcile_full_generation:
+ try:
+ from repowise.core.pipeline.persist import (
+ tombstone_pages_outside_generation,
+ )
+
+ tombstoned_page_ids += await tombstone_pages_outside_generation(
+ session,
+ repo_id,
+ {page.page_id for page in generated_pages},
+ )
+ if tombstoned_page_ids and decision_vector_store is not None:
+ await decision_vector_store.delete_many(tombstoned_page_ids)
+ except Exception as exc:
+ _skip("Generation scope reconciliation", exc)
+ if require_config_rebuild_success:
+ raise
+
# Delete rows of pages that have been retired since this index was
# built. Nothing else on the update path can reach them: an update
# runs with ``file_pages_only``, so the ladder returns before the
@@ -729,7 +821,7 @@ async def _persist_full_update_async(
)
with timed(timings, "persist.tombstones"):
- tombstoned_page_ids = await mark_tombstone_pages(
+ tombstoned_page_ids += await mark_tombstone_pages(
session, repo_id, tombstone_candidates(file_diffs)
)
except Exception as exc:
@@ -825,28 +917,26 @@ async def _persist_full_update_async(
_skip("Knowledge-graph persist", exc)
# Updated git metadata + recomputed percentiles + new commit rows.
- if git_meta_map or git_decay_map:
+ if git_meta_map or git_decay_map or full_git_summary is not None:
try:
- from repowise.core.persistence.crud import (
- recompute_git_percentiles,
- upsert_git_metadata_bulk,
- )
-
- # Changed files' full rows + idle files' decay-only rows
- # (#728), then a repo-wide percentile re-rank over the fresh
- # scores.
with timed(timings, "persist.git"):
- await upsert_git_metadata_bulk(
+ from repowise.core.pipeline.persist import persist_git_refresh
+
+ await persist_git_refresh(
session,
repo_id,
- [*git_meta_map.values(), *(git_decay_map or {}).values()],
+ git_meta_map,
+ git_decay_map,
+ full_git_summary,
)
- await recompute_git_percentiles(session, repo_id)
except Exception as exc:
_skip("Git persist", exc)
+ if require_config_rebuild_success:
+ raise
try:
with timed(timings, "persist.commits"):
- await _persist_incremental_commits(session, repo_id, repo_path)
+ if full_git_summary is None:
+ await _persist_incremental_commits(session, repo_id, repo_path)
except Exception as exc:
_skip("Commit capture", exc)
@@ -883,9 +973,7 @@ async def _persist_full_update_async(
apply_id_migration,
)
- await apply_id_migration(
- session, repo_id, vector_store=decision_vector_store
- )
+ await apply_id_migration(session, repo_id, vector_store=decision_vector_store)
# The entity split is only coherent once legacy rows are
# classified.
@@ -893,6 +981,15 @@ async def _persist_full_update_async(
await apply_migration(session, repo_id)
+ if require_decision_persist_success:
+ from repowise.core.persistence.crud import (
+ purge_proposed_decisions_by_source,
+ )
+
+ await purge_proposed_decisions_by_source(
+ session, repo_id, "git_archaeology"
+ )
+
decision_dicts: list[dict] = []
if new_decision_markers:
import dataclasses as _dc
@@ -930,6 +1027,8 @@ async def _persist_full_update_async(
await recompute_decision_staleness(session, repo_id, git_meta_map)
except Exception as exc:
_skip("Decision persist", exc)
+ if require_decision_persist_success:
+ raise
finally:
if timings is not None:
timings.stop("persist.decisions")
@@ -1012,7 +1111,14 @@ async def _persist_full_update_async(
with timed(timings, "persist.symbols"):
await persist_incremental_symbols(
- session, repo_id, parsed_files, [fd.path for fd in file_diffs]
+ session,
+ repo_id,
+ parsed_files,
+ (
+ [parsed.file_info.path for parsed in parsed_files or []]
+ if reconcile_full_scope
+ else [fd.path for fd in file_diffs]
+ ),
)
except Exception as exc:
_skip("Symbol persist", exc)
@@ -1030,7 +1136,11 @@ async def _persist_full_update_async(
repo_id,
graph_builder,
parsed_files,
- [fd.path for fd in file_diffs],
+ (
+ [parsed.file_info.path for parsed in parsed_files or []]
+ if reconcile_full_scope
+ else [fd.path for fd in file_diffs]
+ ),
)
except Exception as exc:
_skip("Graph edges persist", exc)
@@ -1092,10 +1202,24 @@ async def _persist_full_update_async(
except Exception as exc:
_skip("Page count", exc)
+ if require_config_rebuild_success and len(degraded) > degraded_before_persist:
+ raise RuntimeError(
+ "Configuration rebuild did not update every dependent store; "
+ "the previous fingerprint was retained so the next update retries."
+ )
+
# FTS outside the transaction — rebuildable, and its writer manages
# its own connection state.
if timings is not None:
timings.start("persist.fts")
+ from repowise.core.pipeline.cleanup_debt import (
+ clear_cleanup_debt,
+ load_cleanup_debt,
+ record_cleanup_debt,
+ )
+
+ cleanup_ids = set(tombstoned_page_ids) | set(swept_page_ids)
+ cleanup_ids.update(load_cleanup_debt(Path(repo_path))["fts"])
try:
fts = FullTextSearch(engine)
await fts.ensure_index()
@@ -1111,19 +1235,32 @@ async def _persist_full_update_async(
# retrieval fetches a fixed number of rows before that check runs,
# so every tombstone left in the index costs a real candidate its
# slot.
- if tombstoned_page_ids:
- await fts.delete_many(tombstoned_page_ids)
+ if cleanup_ids:
+ await fts.delete_many(sorted(cleanup_ids))
# A swept page's FTS row outlives the page row unless it is deleted
# here, and search hydrates title and snippet from the FTS copy
# itself — so an orphan keeps answering queries in full, pointing
# at a page that now 404s. Worse than never having swept it.
- if swept_page_ids:
- await fts.delete_many(swept_page_ids)
+ clear_cleanup_debt(Path(repo_path), "fts", cleanup_ids)
except Exception as exc:
+ record_cleanup_debt(Path(repo_path), "fts", cleanup_ids)
_skip("Full-text search indexing", exc)
+ if require_config_rebuild_success:
+ raise
finally:
if timings is not None:
timings.stop("persist.fts")
+
+ vector_cleanup_ids = load_cleanup_debt(Path(repo_path))["vectors"]
+ if vector_cleanup_ids and decision_vector_store is not None:
+ try:
+ await decision_vector_store.delete_many(sorted(vector_cleanup_ids))
+ clear_cleanup_debt(Path(repo_path), "vectors", vector_cleanup_ids)
+ except Exception as exc:
+ record_cleanup_debt(Path(repo_path), "vectors", vector_cleanup_ids)
+ _skip("Deferred vector cleanup", exc)
+ if require_config_rebuild_success:
+ raise
return total_pages
finally:
await engine.dispose()
@@ -1251,9 +1388,12 @@ async def _rescore_health_from_db(
# line/branch coverage even though the coverage_files rows still
# existed. Reload them (and optionally re-discover a fresh report)
# so coverage survives `repowise update`.
- coverage_map, coverage_files, coverage_format = await _coverage_for_rescore(
- session, repo_id, repo_path, parsed_files
- )
+ (
+ coverage_map,
+ coverage_files,
+ coverage_format,
+ coverage_authoritative,
+ ) = await _coverage_for_rescore(session, repo_id, repo_path, parsed_files)
analyzer = HealthAnalyzer(
graph_builder.graph(),
@@ -1284,16 +1424,14 @@ async def _rescore_health_from_db(
await save_full_health_report(
session, repo_id, report, analyzed_commit=get_head_commit(Path(repo_path))
)
- if coverage_files:
+ if coverage_authoritative:
# Stamp the live HEAD from disk, not the stored
# ``repo.head_commit`` column. The column names the last
# *indexed* commit; the coverage just scored describes the
# working tree, and the two diverge when the tree moved after
# the last index (issue #1747). Live HEAD is the provenance
# answer: it is the tree the coverage was measured against.
- live_head = get_head_commit(Path(repo_path)) or getattr(
- repo, "head_commit", None
- )
+ live_head = get_head_commit(Path(repo_path)) or getattr(repo, "head_commit", None)
await save_coverage_files(
session,
repo_id,
@@ -1312,6 +1450,9 @@ def _run_full_health_rescore(
state: dict,
head: str | None,
curr_fingerprint: str,
+ *,
+ dependency_fingerprints: dict[str, str] | None = None,
+ timings: PhaseTimings | None = None,
) -> None:
"""Rebuild graph and re-run full health analysis when config changed.
@@ -1327,12 +1468,13 @@ def _run_full_health_rescore(
# Share the rebuild path with the incremental update so both produce the
# same graph (same parser, same framework-aware synthetic edges).
- parsed_files, _source_map, graph_builder, _repo_structure, _file_count = _build_repo_graph(
- repo_path,
- exclude_patterns,
- include_submodules=bool(state.get("include_submodules", False)),
- include_nested_repos=bool(state.get("include_nested_repos", False)),
- )
+ with timed(timings, "rebuild"):
+ parsed_files, _source_map, graph_builder, _repo_structure, _file_count = _build_repo_graph(
+ repo_path,
+ exclude_patterns,
+ include_submodules=bool(state.get("include_submodules", False)),
+ include_nested_repos=bool(state.get("include_nested_repos", False)),
+ )
# Fan-out metric precompute (mirrors _rebuild_graph_and_git) — the
# rescore persists graph nodes too, which reads every metric. Best-effort:
@@ -1341,11 +1483,14 @@ def _run_full_health_rescore(
run_async(graph_builder.compute_metrics_parallel())
try:
- run_async(_rescore_health_from_db(repo_path, graph_builder, parsed_files, exclude_patterns))
+ with timed(timings, "rescore"):
+ run_async(
+ _rescore_health_from_db(repo_path, graph_builder, parsed_files, exclude_patterns)
+ )
except Exception as exc:
# Return without advancing the fingerprint so the next update retries.
console.print(f"[yellow]Health re-score failed: {exc}[/yellow]")
- return
+ raise
# Same full-replace re-score the periodic gate runs, so it restarts the same
# cadence. Left unstamped when git is unreadable: the gate cannot fire
@@ -1357,9 +1502,14 @@ def _run_full_health_rescore(
# These rows were just rewritten by this analyzer.
"health_analyzer_version": HEALTH_ANALYZER_VERSION,
}
+ if dependency_fingerprints is not None:
+ new_state["config_dependency_fingerprints"] = dependency_fingerprints
rescored_at = head_commit_ts(repo_path)
if rescored_at is not None:
new_state["last_full_rescore_at"] = rescored_at
+ if timings is not None:
+ timings.stop("run")
+ new_state["phase_timings"] = timings.totals
save_state(repo_path, new_state)
elapsed = time.monotonic() - start
console.print(f"[green]Config-triggered health re-score complete[/green] in {elapsed:.1f}s")
diff --git a/packages/cli/src/repowise/cli/commands/update_cmd/workspace.py b/packages/cli/src/repowise/cli/commands/update_cmd/workspace.py
index fc9aa7fb4..463bdc4f6 100644
--- a/packages/cli/src/repowise/cli/commands/update_cmd/workspace.py
+++ b/packages/cli/src/repowise/cli/commands/update_cmd/workspace.py
@@ -78,6 +78,7 @@ def _workspace_update(
"""
from repowise.cli.helpers import load_state
from repowise.core.docs_mode import resolve_docs_mode
+ from repowise.core.repo_config import config_fingerprint
from repowise.core.workspace import (
check_repo_staleness,
reconcile_repo_head_commit,
@@ -115,8 +116,19 @@ def _workspace_update(
stored = entry.last_commit_at_index
is_stale, head, behind = check_repo_staleness(abs_path, stored)
indexed = (abs_path / ".repowise").is_dir()
+ repo_state = load_state(abs_path) if indexed else {}
+ config_stale = bool(
+ indexed
+ and (
+ repo_state.get("config_fingerprint") is None
+ or repo_state.get("config_fingerprint") != config_fingerprint(abs_path)
+ )
+ )
+ is_stale = is_stale or config_stale
if not indexed:
status = "[dim]not indexed[/dim]"
+ elif config_stale and not behind:
+ status = "[yellow]config changed[/yellow]"
elif is_stale:
status = f"[yellow]{behind} new commit(s)[/yellow]"
else:
@@ -126,7 +138,6 @@ def _workspace_update(
if is_stale:
stale_count += 1
if indexed:
- repo_state = load_state(abs_path)
if not _resolve_index_only_mode(
index_only=index_only, docs_flag=docs_flag, state=repo_state
):
diff --git a/packages/core/src/repowise/core/persistence/crud/decisions.py b/packages/core/src/repowise/core/persistence/crud/decisions.py
index ec172617d..9ae85309c 100644
--- a/packages/core/src/repowise/core/persistence/crud/decisions.py
+++ b/packages/core/src/repowise/core/persistence/crud/decisions.py
@@ -1344,6 +1344,7 @@ async def purge_proposed_decisions_by_source(
DecisionRecord.repository_id == repository_id,
DecisionRecord.source == source,
DecisionRecord.status == "proposed",
+ ~accepted_predicate(),
)
)
ids = [row[0] for row in result.all()]
@@ -1366,6 +1367,39 @@ async def purge_proposed_decisions_by_source(
return len(ids)
+async def purge_proposed_decisions_outside_files(
+ session: AsyncSession,
+ repository_id: str,
+ current_file_paths: set[str],
+) -> int:
+ """Delete unreviewed extracted decisions whose evidence file left scope."""
+ result = await session.execute(
+ select(DecisionRecord.id, DecisionRecord.evidence_file).where(
+ DecisionRecord.repository_id == repository_id,
+ DecisionRecord.status == "proposed",
+ DecisionRecord.evidence_file.is_not(None),
+ ~accepted_predicate(),
+ )
+ )
+ ids = [row[0] for row in result.all() if row[1] not in current_file_paths]
+ if not ids:
+ return 0
+
+ await session.execute(delete(DecisionEvidence).where(DecisionEvidence.decision_id.in_(ids)))
+ await session.execute(
+ delete(DecisionEdge).where(
+ or_(
+ DecisionEdge.src_decision_id.in_(ids),
+ DecisionEdge.dst_decision_id.in_(ids),
+ )
+ )
+ )
+ await session.execute(delete(DecisionNodeLink).where(DecisionNodeLink.decision_id.in_(ids)))
+ await session.execute(delete(DecisionRecord).where(DecisionRecord.id.in_(ids)))
+ await session.flush()
+ return len(ids)
+
+
async def _fill_git_meta_gaps(
session: AsyncSession,
repository_id: str,
diff --git a/packages/core/src/repowise/core/pipeline/cleanup_debt.py b/packages/core/src/repowise/core/pipeline/cleanup_debt.py
new file mode 100644
index 000000000..bea3341ef
--- /dev/null
+++ b/packages/core/src/repowise/core/pipeline/cleanup_debt.py
@@ -0,0 +1,49 @@
+"""Durable retry ledger for post-transaction search-index cleanup."""
+
+from __future__ import annotations
+
+import json
+from pathlib import Path
+
+from repowise.core.fsutils import atomic_write_text
+
+_KINDS = ("fts", "vectors")
+
+
+def _path(repo_path: Path) -> Path:
+ return repo_path / ".repowise" / "cleanup-debt.json"
+
+
+def load_cleanup_debt(repo_path: Path) -> dict[str, set[str]]:
+ path = _path(repo_path)
+ try:
+ raw = json.loads(path.read_text(encoding="utf-8")) if path.is_file() else {}
+ except (OSError, ValueError, TypeError):
+ raw = {}
+ return {kind: set(raw.get(kind) or []) for kind in _KINDS}
+
+
+def record_cleanup_debt(repo_path: Path, kind: str, page_ids: set[str]) -> None:
+ if not page_ids:
+ return
+ debt = load_cleanup_debt(repo_path)
+ debt[kind].update(page_ids)
+ path = _path(repo_path)
+ path.parent.mkdir(parents=True, exist_ok=True)
+ atomic_write_text(
+ path,
+ json.dumps({key: sorted(values) for key, values in debt.items()}, indent=2),
+ )
+
+
+def clear_cleanup_debt(repo_path: Path, kind: str, page_ids: set[str]) -> None:
+ if not page_ids:
+ return
+ debt = load_cleanup_debt(repo_path)
+ debt[kind].difference_update(page_ids)
+ path = _path(repo_path)
+ path.parent.mkdir(parents=True, exist_ok=True)
+ atomic_write_text(
+ path,
+ json.dumps({key: sorted(values) for key, values in debt.items()}, indent=2),
+ )
diff --git a/packages/core/src/repowise/core/pipeline/full_index.py b/packages/core/src/repowise/core/pipeline/full_index.py
index e5c8e8de8..eec1aa26c 100644
--- a/packages/core/src/repowise/core/pipeline/full_index.py
+++ b/packages/core/src/repowise/core/pipeline/full_index.py
@@ -20,6 +20,9 @@ async def index_repo_full(
exclude_patterns: list[str] | None = None,
include_submodules: bool = False,
include_nested_repos: bool = False,
+ follow_renames: bool = False,
+ require_git_success: bool = False,
+ require_health_success: bool = False,
progress: Any | None = None,
) -> Any:
"""Run the full pipeline (index-only, no LLM docs) and persist everything.
@@ -45,12 +48,23 @@ async def index_repo_full(
exclude_patterns=exclude_patterns or None,
include_submodules=include_submodules,
include_nested_repos=include_nested_repos,
+ follow_renames=follow_renames,
generate_docs=False,
progress=progress,
)
+ # The ordinary full-index fallback keeps Git and health best-effort for
+ # backward compatibility. A configuration-driven rebuild is different:
+ # advancing the dependency fingerprints after either required phase was
+ # swallowed by the orchestrator would permanently strand stale rows.
+ if require_git_success and getattr(result, "git_summary", None) is None:
+ raise RuntimeError("Git indexing failed during a required configuration rebuild")
+ if require_health_success and getattr(result, "health_report", None) is None:
+ raise RuntimeError("Health analysis failed during a required configuration rebuild")
+
url = resolve_db_url(repo_path)
engine = create_engine(url)
+ stale_page_ids: list[str] = []
try:
await init_db(engine)
sf = create_session_factory(engine)
@@ -60,7 +74,54 @@ async def index_repo_full(
name=result.repo_name,
local_path=str(repo_path),
)
- await persist_pipeline_result(result, session, repo.id)
+ stale_page_ids = (
+ await persist_pipeline_result(
+ result,
+ session,
+ repo.id,
+ replace_full_git_history=require_git_success,
+ )
+ or []
+ )
+
+ from repowise.core.pipeline.cleanup_debt import (
+ clear_cleanup_debt,
+ load_cleanup_debt,
+ record_cleanup_debt,
+ )
+
+ debt = load_cleanup_debt(repo_path)
+ fts_cleanup_ids = set(stale_page_ids) | debt["fts"]
+ if fts_cleanup_ids:
+ from repowise.core.persistence.search import FullTextSearch
+
+ try:
+ fts = FullTextSearch(engine)
+ await fts.ensure_index()
+ await fts.delete_many(sorted(fts_cleanup_ids))
+ clear_cleanup_debt(repo_path, "fts", fts_cleanup_ids)
+ except Exception:
+ record_cleanup_debt(repo_path, "fts", fts_cleanup_ids)
+ raise
+
+ vector_cleanup_ids = set(stale_page_ids) | debt["vectors"]
+ if vector_cleanup_ids:
+ lance_dir = repo_path / ".repowise" / "lancedb"
+ if lance_dir.exists():
+ from repowise.core.persistence.vector_store import LanceDBVectorStore
+ from repowise.core.providers.embedding.base import MockEmbedder
+
+ # Deletion does not embed or validate vector dimensions, so a
+ # mock instance can safely open a real-embedder table here.
+ try:
+ vector_store = LanceDBVectorStore(str(lance_dir), embedder=MockEmbedder())
+ await vector_store.delete_many(sorted(vector_cleanup_ids))
+ clear_cleanup_debt(repo_path, "vectors", vector_cleanup_ids)
+ except Exception:
+ record_cleanup_debt(repo_path, "vectors", vector_cleanup_ids)
+ raise
+ else:
+ clear_cleanup_debt(repo_path, "vectors", vector_cleanup_ids)
finally:
await engine.dispose()
diff --git a/packages/core/src/repowise/core/pipeline/incremental.py b/packages/core/src/repowise/core/pipeline/incremental.py
index 02843a861..2565d78c0 100644
--- a/packages/core/src/repowise/core/pipeline/incremental.py
+++ b/packages/core/src/repowise/core/pipeline/incremental.py
@@ -138,6 +138,12 @@ def build_repo_graph(
# persisted repo-wide, so an update that could not see the skipped source
# files would re-derive and write back the verdicts init had clamped.
graph_builder.traversal_stats = traverser.stats
+ # Reconciliation authority is the successful traversal, not the successful
+ # parse set. A transient read/parser failure must not make an existing
+ # in-scope file look deleted and prune its persisted rows.
+ graph_builder.traversed_file_paths = {
+ file_info.path for file_info in file_infos
+ }
# Parse the misses in process and serially: on the update path they are
# change-sized. (Ceiling: a wiped/stale cache re-parses everything on one
@@ -251,6 +257,8 @@ async def rebuild_graph_and_git(
include_submodules: bool = False,
include_nested_repos: bool = False,
idle_decay_sink: dict[str, dict] | None = None,
+ force_full_git: bool = False,
+ git_summary_sink: list[Any] | None = None,
log: LogFn | None = None,
timings: PhaseTimings | None = None,
) -> tuple[list, dict[str, bytes], Any, Any, int, dict[str, dict]]:
@@ -277,6 +285,12 @@ async def rebuild_graph_and_git(
silently drop its submodule files on every incremental update. Missing
keys fall back to False (legacy behavior).
+ ``force_full_git`` is reserved for changes to Git-history/traversal
+ configuration. Those settings invalidate every per-file row, not merely
+ files in the commit diff. The optional sink carries the resulting summary
+ to persistence so per-commit/fix-event rows can be replaced from the same
+ walk.
+
Returns ``(parsed_files, source_map, graph_builder, repo_structure,
file_count, git_meta_map)``.
"""
@@ -317,39 +331,49 @@ async def rebuild_graph_and_git(
exclude_patterns=exclude_patterns or None,
tier=tier,
)
- changed_paths = build_filtered_changed_paths(file_diffs, exclude_patterns)
- # The full tracked-file set lets the indexer re-run the repo-wide
- # co-change walk so partners aren't wiped to "[]" for changed files.
- # The sink captures that walk's FULL per-file partner map: the graph
- # was just rebuilt from scratch, so co_changes edges must be re-added
- # for every file (not only the changed ones) or the update graph
- # diverges from the init graph and the centrality cache can't hit.
- co_change_full: dict[str, list[dict]] = {}
- updated_meta = await git_indexer.index_changed_files(
- changed_paths,
- all_files=set(source_map.keys()),
- co_change_sink=co_change_full,
- idle_decay_sink=idle_decay_sink,
- on_warning=log,
- timings=timings,
- )
- git_meta_map = {m["file_path"]: m for m in updated_meta}
- label_co_change_structure(graph_builder, git_meta_map)
- if idle_decay_sink:
- # Idle rows carry the same column and are persisted on their own
- # path, having been serialized before the graph existed.
- label_co_change_structure(graph_builder, idle_decay_sink)
- if co_change_full:
- graph_builder.update_co_change_edges(
- {
- fp: {"co_change_partners_json": partners}
- for fp, partners in co_change_full.items()
- }
- )
- else:
+ if force_full_git:
+ summary, updated_meta = await git_indexer.index_repo(repo_path.name, on_warning=log)
+ if git_summary_sink is not None:
+ git_summary_sink.append(summary)
+ git_meta_map = {m["file_path"]: m for m in updated_meta}
+ label_co_change_structure(graph_builder, git_meta_map)
graph_builder.update_co_change_edges(git_meta_map)
+ else:
+ changed_paths = build_filtered_changed_paths(file_diffs, exclude_patterns)
+ # The full tracked-file set lets the indexer re-run the repo-wide
+ # co-change walk so partners aren't wiped to "[]" for changed files.
+ # The sink captures that walk's FULL per-file partner map: the graph
+ # was just rebuilt from scratch, so co_changes edges must be re-added
+ # for every file (not only the changed ones) or the update graph
+ # diverges from the init graph and the centrality cache can't hit.
+ co_change_full: dict[str, list[dict]] = {}
+ updated_meta = await git_indexer.index_changed_files(
+ changed_paths,
+ all_files=set(source_map.keys()),
+ co_change_sink=co_change_full,
+ idle_decay_sink=idle_decay_sink,
+ on_warning=log,
+ timings=timings,
+ )
+ git_meta_map = {m["file_path"]: m for m in updated_meta}
+ label_co_change_structure(graph_builder, git_meta_map)
+ if idle_decay_sink:
+ # Idle rows carry the same column and are persisted on their own
+ # path, having been serialized before the graph existed.
+ label_co_change_structure(graph_builder, idle_decay_sink)
+ if co_change_full:
+ graph_builder.update_co_change_edges(
+ {
+ fp: {"co_change_partners_json": partners}
+ for fp, partners in co_change_full.items()
+ }
+ )
+ else:
+ graph_builder.update_co_change_edges(git_meta_map)
except Exception as exc:
log(f"[yellow]Git re-index skipped: {exc}[/yellow]")
+ if force_full_git:
+ raise
finally:
if timings is not None:
timings.stop("rebuild.git")
@@ -540,9 +564,7 @@ async def load_stored_function_mod_p80(repo_path: Any, *, log: LogFn | None = No
return None
-async def load_stored_coverage_map(
- repo_path: Any, *, log: LogFn | None = None
-) -> dict[str, dict]:
+async def load_stored_coverage_map(repo_path: Any, *, log: LogFn | None = None) -> dict[str, dict]:
"""Load the persisted coverage map for health scoring on an incremental run.
The incremental health pass re-scores changed files only, but if it builds
@@ -587,9 +609,7 @@ async def load_stored_coverage_map(
coverage_map: dict[str, dict] = {}
for row in rows:
try:
- covered = (
- json.loads(row.covered_lines_json) if row.covered_lines_json else []
- )
+ covered = json.loads(row.covered_lines_json) if row.covered_lines_json else []
except (ValueError, TypeError):
covered = []
coverage_map[row.file_path] = {
@@ -1231,9 +1251,7 @@ async def persist_partial_health(
# Repository-wide, like the queue above and for the same reason: an
# opportunity folds a file's plans, and a file this run did not touch
# can still lose one when a cross-file plan elsewhere resolves.
- await finalize_refactoring_opportunities(
- session, repo_id, analyzed_commit=analyzed_commit
- )
+ await finalize_refactoring_opportunities(session, repo_id, analyzed_commit=analyzed_commit)
# Per-function blame rollup for the changed files (keeps git_function_blame
# current between full indexes; FULL git tier only — empty otherwise).
fn_blame_rows = getattr(report, "function_blame_rows", None)
@@ -1664,6 +1682,10 @@ async def persist_incremental_index(
knowledge_graph_result: Any | None = None,
parsed_files: list[Any] | None = None,
git_decay_map: dict | None = None,
+ full_git_summary: Any | None = None,
+ reconcile_full_scope: bool = False,
+ full_generation_page_ids: set[str] | None = None,
+ vector_store: Any | None = None,
log: LogFn | None = None,
degraded: list[str] | None = None,
failed_steps: list[str] | None = None,
@@ -1738,6 +1760,42 @@ async def persist_incremental_index(
)
repo_id = repo.id
+ if reconcile_full_scope:
+ try:
+ from repowise.core.pipeline.persist import (
+ reconcile_full_index_scope,
+ )
+
+ current_graph_paths = set(
+ getattr(
+ graph_builder,
+ "traversed_file_paths",
+ {pf.file_info.path for pf in parsed_files or []},
+ )
+ )
+ current_git_paths = set(git_meta_map)
+ with timed(timings, "persist.scope_reconcile"):
+ tombstoned_page_ids = await reconcile_full_index_scope(
+ session,
+ repo_id,
+ current_graph_paths,
+ current_git_paths,
+ )
+ except Exception as exc:
+ _skip("Config scope reconciliation", exc)
+
+ if full_generation_page_ids is not None:
+ try:
+ from repowise.core.pipeline.persist import (
+ tombstone_pages_outside_generation,
+ )
+
+ tombstoned_page_ids += await tombstone_pages_outside_generation(
+ session, repo_id, full_generation_page_ids
+ )
+ except Exception as exc:
+ _skip("Generation scope reconciliation", exc)
+
# Delete rows of pages retired since this index was built. This
# path never regenerates a repo-wide page, so nothing else here
# would ever visit one to notice it should be gone, and for a user
@@ -1773,7 +1831,7 @@ async def persist_incremental_index(
)
with timed(timings, "persist.tombstones"):
- tombstoned_page_ids = await mark_tombstone_pages(
+ tombstoned_page_ids += await mark_tombstone_pages(
session, repo_id, tombstone_candidates(file_diffs)
)
except Exception as exc:
@@ -1789,31 +1847,27 @@ async def persist_incremental_index(
except Exception as exc:
_skip("Page tree rebuild", exc)
- if git_meta_map or git_decay_map:
+ if git_meta_map or git_decay_map or full_git_summary is not None:
try:
- from repowise.core.persistence.crud import (
- recompute_git_percentiles,
- upsert_git_metadata_bulk,
- )
-
- # Idle files' decay-only rows upsert alongside the changed
- # files' full rows; the percentile re-rank then runs over
- # every row against the freshly decayed scores (#728).
with timed(timings, "persist.git"):
- await upsert_git_metadata_bulk(
+ from repowise.core.pipeline.persist import persist_git_refresh
+
+ await persist_git_refresh(
session,
repo_id,
- [*git_meta_map.values(), *(git_decay_map or {}).values()],
+ git_meta_map,
+ git_decay_map,
+ full_git_summary,
)
- await recompute_git_percentiles(session, repo_id)
except Exception as exc:
_skip("Git persist", exc, range_scoped=True)
try:
with timed(timings, "persist.commits"):
- await persist_incremental_commits(
- session, repo_id, repo_path, timings=timings
- )
+ if full_git_summary is None:
+ await persist_incremental_commits(
+ session, repo_id, repo_path, timings=timings
+ )
except Exception as exc:
_skip("Commit capture", exc)
@@ -1870,9 +1924,7 @@ async def persist_incremental_index(
from repowise.core.pipeline.persist import persist_incremental_symbols
with timed(timings, "persist.symbols"):
- await persist_incremental_symbols(
- session, repo_id, parsed_files, changed_paths
- )
+ await persist_incremental_symbols(session, repo_id, parsed_files, changed_paths)
except Exception as exc:
_skip("Symbol persist", exc, range_scoped=True)
@@ -1942,6 +1994,10 @@ async def persist_incremental_index(
)
await purge_proposed_decisions_by_source(session, repo_id, "code_comment")
+ if full_git_summary is not None:
+ await purge_proposed_decisions_by_source(
+ session, repo_id, "git_archaeology"
+ )
except Exception as exc:
_skip("Decision purge", exc)
@@ -2021,9 +2077,7 @@ async def persist_incremental_index(
session,
repo_id,
analyzed_commit=analyzed_commit,
- plan_policy=getattr(
- partial_health_report, "performance_plan_policy", None
- ),
+ plan_policy=getattr(partial_health_report, "performance_plan_policy", None),
)
await finalize_refactoring_opportunities(
session, repo_id, analyzed_commit=analyzed_commit
@@ -2042,17 +2096,25 @@ async def persist_incremental_index(
# A swept page's FTS row is worse than a tombstone: search hydrates
# title and snippet from the FTS copy itself, so an orphan answers in
# full while the page it names 404s.
- if tombstoned_page_ids or swept_page_ids:
+ from repowise.core.pipeline.cleanup_debt import (
+ clear_cleanup_debt,
+ load_cleanup_debt,
+ record_cleanup_debt,
+ )
+
+ cleanup_debt = load_cleanup_debt(Path(repo_path))
+ fts_cleanup_ids = (
+ set(tombstoned_page_ids) | set(swept_page_ids) | cleanup_debt["fts"]
+ )
+ if fts_cleanup_ids:
try:
from repowise.core.persistence.search import FullTextSearch
fts = FullTextSearch(engine)
with timed(timings, "persist.fts"):
await fts.ensure_index()
- if tombstoned_page_ids:
- await fts.delete_many(tombstoned_page_ids)
- if swept_page_ids:
- await fts.delete_many(swept_page_ids)
+ await fts.delete_many(sorted(fts_cleanup_ids))
+ clear_cleanup_debt(Path(repo_path), "fts", fts_cleanup_ids)
except Exception as exc:
# Range-scoped for the tombstone half: mark_tombstone_pages
# re-marks and re-returns pages that are already tombstones, so
@@ -2060,9 +2122,38 @@ async def persist_incremental_index(
# The swept half is not repairable this way, because the sweeps
# deleted those rows and a later run finds nothing to sweep.
# Tagging still recovers strictly more than not tagging.
+ record_cleanup_debt(Path(repo_path), "fts", fts_cleanup_ids)
_skip("Tombstone full-text removal", exc, range_scoped=True)
- # Ceiling: the swept pages' *vector* embeddings survive this path.
+ vector_cleanup_ids = set(tombstoned_page_ids) | cleanup_debt["vectors"]
+ if vector_cleanup_ids and vector_store is None:
+ lance_dir = Path(repo_path) / ".repowise" / "lancedb"
+ if lance_dir.exists():
+ try:
+ from repowise.core.persistence.vector_store import LanceDBVectorStore
+ from repowise.core.providers.embedding.base import MockEmbedder
+
+ # Delete-only access never embeds or checks dimensions.
+ vector_store = LanceDBVectorStore(str(lance_dir), embedder=MockEmbedder())
+ except Exception as exc:
+ record_cleanup_debt(
+ Path(repo_path), "vectors", vector_cleanup_ids
+ )
+ _skip("Tombstone vector-store open", exc, range_scoped=True)
+ else:
+ # No store means there are no vector rows left to clean.
+ clear_cleanup_debt(Path(repo_path), "vectors", vector_cleanup_ids)
+
+ if vector_cleanup_ids and vector_store is not None:
+ try:
+ with timed(timings, "persist.vectors"):
+ await vector_store.delete_many(sorted(vector_cleanup_ids))
+ clear_cleanup_debt(Path(repo_path), "vectors", vector_cleanup_ids)
+ except Exception as exc:
+ record_cleanup_debt(Path(repo_path), "vectors", vector_cleanup_ids)
+ _skip("Tombstone vector removal", exc)
+
+ # Ceiling: retired non-file pages' *vector* embeddings survive this path.
# There is no store here to delete them from, and building one would
# pull the lancedb import onto the post-commit hook, which
# ``deterministic.py`` avoids on purpose — and with the default mock
diff --git a/packages/core/src/repowise/core/pipeline/persist.py b/packages/core/src/repowise/core/pipeline/persist.py
index d60852343..35c67ff61 100644
--- a/packages/core/src/repowise/core/pipeline/persist.py
+++ b/packages/core/src/repowise/core/pipeline/persist.py
@@ -106,6 +106,108 @@ async def mark_tombstone_pages(
return marked
+async def tombstone_file_pages_outside_scope(
+ session: Any, repo_id: str, current_file_paths: set[str]
+) -> list[str]:
+ """Tombstone active source-backed pages outside a full traversal's scope.
+
+ Files removed by ``exclude_patterns`` still exist on disk, so the ordinary
+ deleted-file tombstone path cannot identify them. A successful full
+ traversal can: any active file page outside its parsed-file set is no longer
+ part of this index.
+ """
+ from sqlalchemy import select
+
+ from repowise.core.persistence.models import Page
+
+ pages = (
+ await session.execute(
+ select(Page).where(
+ Page.repository_id == repo_id,
+ Page.page_type.in_(("file_page", "api_contract", "infra_page", "symbol_spotlight")),
+ Page.freshness_status != "tombstone",
+ )
+ )
+ ).scalars()
+ marked: list[str] = []
+ for page in pages:
+ target = page.target_path or ""
+ source_path = target.split("::", 1)[0] if page.page_type == "symbol_spotlight" else target
+ if source_path in current_file_paths:
+ continue
+ page.freshness_status = "tombstone"
+ try:
+ metadata = json.loads(page.metadata_json or "{}")
+ except (json.JSONDecodeError, TypeError):
+ metadata = {}
+ metadata["successor_paths"] = []
+ page.metadata_json = json.dumps(metadata)
+ marked.append(page.id)
+ return marked
+
+
+async def reconcile_full_index_scope(
+ session: Any,
+ repo_id: str,
+ current_graph_paths: set[str],
+ current_git_paths: set[str],
+) -> list[str]:
+ """Reconcile every source-backed store against one successful traversal."""
+ tombstoned = await tombstone_file_pages_outside_scope(session, repo_id, current_graph_paths)
+ await _prune_stale_file_rows(
+ session,
+ repo_id,
+ current_graph_paths,
+ current_git_paths,
+ authoritative_empty=True,
+ )
+ from repowise.core.persistence.crud.decisions import (
+ purge_proposed_decisions_outside_files,
+ )
+
+ await purge_proposed_decisions_outside_files(session, repo_id, current_graph_paths)
+ return tombstoned
+
+
+async def tombstone_pages_outside_generation(
+ session: Any, repo_id: str, current_page_ids: set[str]
+) -> list[str]:
+ """Retire generated pages absent from an authoritative full generation.
+
+ This is used only when generation configuration changed and the update ran
+ the complete generation ladder. It covers selection changes such as page
+ caps, spotlight ranking, and disabling onboarding, none of which imply that
+ the backing source file disappeared.
+ """
+ from sqlalchemy import select
+
+ from repowise.core.generation.models import GENERATION_LEVELS
+ from repowise.core.persistence.models import Page
+
+ pages = (
+ await session.execute(
+ select(Page).where(
+ Page.repository_id == repo_id,
+ Page.page_type.in_(tuple(GENERATION_LEVELS)),
+ Page.freshness_status != "tombstone",
+ )
+ )
+ ).scalars()
+ marked: list[str] = []
+ for page in pages:
+ if page.id in current_page_ids:
+ continue
+ page.freshness_status = "tombstone"
+ try:
+ metadata = json.loads(page.metadata_json or "{}")
+ except (json.JSONDecodeError, TypeError):
+ metadata = {}
+ metadata["successor_paths"] = []
+ page.metadata_json = json.dumps(metadata)
+ marked.append(page.id)
+ return marked
+
+
async def tombstone_absent_file_pages(
session: Any, repo_id: str, repo_path: Path | str
) -> list[str]:
@@ -680,6 +782,8 @@ async def _prune_stale_file_rows(
repo_id: str,
current_graph_file_paths: set[str],
current_git_file_paths: set[str],
+ *,
+ authoritative_empty: bool = False,
) -> None:
"""Delete file-scoped rows for files absent from the latest full pipeline run.
@@ -689,7 +793,8 @@ async def _prune_stale_file_rows(
*current_graph_file_paths* (from ``parsed_files``) governs graph/analysis
tables; *current_git_file_paths* (from ``git_metadata_list``) governs
``git_metadata`` only. Each set independently no-ops when empty to avoid
- wiping rows on a broken run.
+ wiping rows on a broken run, unless ``authoritative_empty`` confirms that a
+ successful full traversal really produced an empty scope.
Full runs only. The authority here is "absent from this run's output",
which is only safe because a full run rebuilds every table it prunes from
@@ -700,7 +805,9 @@ async def _prune_stale_file_rows(
from sqlalchemy import delete, or_, select
from repowise.core.persistence.models import (
+ CoverageFile,
DeadCodeFinding,
+ GitFunctionBlame,
GitMetadata,
GraphEdge,
GraphMetric,
@@ -711,10 +818,17 @@ async def _prune_stale_file_rows(
WikiSymbol,
)
- async def _delete_stale_by_paths(model: Any, column: Any, current: set[str]) -> None:
+ async def _delete_stale_by_paths(
+ model: Any,
+ column: Any,
+ current: set[str],
+ *,
+ allow_empty: bool | None = None,
+ ) -> None:
# Diff persisted paths against *current* in Python so the IN (...) is
# bounded by the stale set, not the whole repo (SQLite param limit).
- if not current:
+ empty_is_authoritative = authoritative_empty if allow_empty is None else allow_empty
+ if not current and not empty_is_authoritative:
return
existing = set(
(await session.execute(select(column).where(model.repository_id == repo_id).distinct()))
@@ -733,7 +847,7 @@ async def _prune_stale_file_rows(
# ---- Graph nodes + edges -------------------------------------------------
# File nodes key on node_id; symbol nodes on file_path. Delete edges before
# nodes (no FK cascade between the tables).
- if current_graph_file_paths:
+ if current_graph_file_paths or authoritative_empty:
node_rows = (
await session.execute(
select(GraphNode.node_id, GraphNode.node_type, GraphNode.file_path).where(
@@ -782,7 +896,18 @@ async def _prune_stale_file_rows(
HealthFileMetric, HealthFileMetric.file_path, current_graph_file_paths
)
await _delete_stale_by_paths(HealthFinding, HealthFinding.file_path, current_graph_file_paths)
- await _delete_stale_by_paths(GitMetadata, GitMetadata.file_path, current_git_file_paths)
+ await _delete_stale_by_paths(CoverageFile, CoverageFile.file_path, current_graph_file_paths)
+ await _delete_stale_by_paths(
+ GitFunctionBlame, GitFunctionBlame.file_path, current_graph_file_paths
+ )
+ await _delete_stale_by_paths(
+ GitMetadata,
+ GitMetadata.file_path,
+ current_git_file_paths,
+ # An empty Git result is authoritative only when the successful source
+ # traversal is empty too. Otherwise it may be a degraded Git walk.
+ allow_empty=authoritative_empty and not current_graph_file_paths,
+ )
# A prune that would take more than this share of a table is read as a broken
@@ -1090,9 +1215,7 @@ async def sweep_retired_pages(session: Any, repo_id: str) -> list[str]:
stale = (
(
await session.execute(
- select(Page.id).where(
- Page.repository_id == repo_id, or_(*match_clauses)
- )
+ select(Page.id).where(Page.repository_id == repo_id, or_(*match_clauses))
)
)
.scalars()
@@ -1101,9 +1224,7 @@ async def sweep_retired_pages(session: Any, repo_id: str) -> list[str]:
for i in range(0, len(stale), _PRUNE_CHUNK):
batch = stale[i : i + _PRUNE_CHUNK]
await session.execute(delete(PageVersion).where(PageVersion.page_id.in_(batch)))
- await session.execute(
- delete(Page).where(Page.repository_id == repo_id, Page.id.in_(batch))
- )
+ await session.execute(delete(Page).where(Page.repository_id == repo_id, Page.id.in_(batch)))
if stale:
logger.info(
"retired_pages_swept",
@@ -1240,9 +1361,7 @@ async def sweep_absent_cycle_pages(session: Any, repo_id: str, graph_builder: An
existing = (
(
await session.execute(
- select(Page.id).where(
- Page.repository_id == repo_id, Page.page_type == "scc_page"
- )
+ select(Page.id).where(Page.repository_id == repo_id, Page.page_type == "scc_page")
)
)
.scalars()
@@ -1252,9 +1371,7 @@ async def sweep_absent_cycle_pages(session: Any, repo_id: str, graph_builder: An
for i in range(0, len(stale), _PRUNE_CHUNK):
batch = stale[i : i + _PRUNE_CHUNK]
await session.execute(delete(PageVersion).where(PageVersion.page_id.in_(batch)))
- await session.execute(
- delete(Page).where(Page.repository_id == repo_id, Page.id.in_(batch))
- )
+ await session.execute(delete(Page).where(Page.repository_id == repo_id, Page.id.in_(batch)))
if stale:
logger.info("absent_cycle_pages_swept", repo_id=repo_id, count=len(stale))
return stale
@@ -1538,6 +1655,63 @@ async def persist_git(result: Any, session: Any, repo_id: str) -> None:
)
+async def replace_git_history(
+ session: Any,
+ repo_id: str,
+ git_meta_map: dict[str, dict],
+ git_summary: Any,
+) -> None:
+ """Replace every history-derived row from one authoritative Git walk."""
+ from types import SimpleNamespace
+
+ from sqlalchemy import delete
+
+ from repowise.core.persistence.models import (
+ FixEvent,
+ GitCommit,
+ GitMetadata,
+ )
+
+ # Function blame describes the current source tree and is produced by the
+ # health pass, not by persist_git. Preserve it across a history-window
+ # replacement; scope reconciliation prunes entries for excluded files.
+ for model in (FixEvent, GitCommit, GitMetadata):
+ await session.execute(delete(model).where(model.repository_id == repo_id))
+ await persist_git(
+ SimpleNamespace(
+ git_metadata_list=list(git_meta_map.values()),
+ git_summary=git_summary,
+ ),
+ session,
+ repo_id,
+ )
+
+
+async def persist_git_refresh(
+ session: Any,
+ repo_id: str,
+ git_meta_map: dict[str, dict],
+ git_decay_map: dict[str, dict] | None,
+ full_git_summary: Any | None,
+) -> None:
+ """Persist either a full history replacement or an incremental refresh."""
+ if full_git_summary is not None:
+ await replace_git_history(session, repo_id, git_meta_map, full_git_summary)
+ return
+
+ from repowise.core.persistence.crud import (
+ recompute_git_percentiles,
+ upsert_git_metadata_bulk,
+ )
+
+ await upsert_git_metadata_bulk(
+ session,
+ repo_id,
+ [*git_meta_map.values(), *(git_decay_map or {}).values()],
+ )
+ await recompute_git_percentiles(session, repo_id)
+
+
async def _analyzed_commit(session: Any, repo_id: str) -> str | None:
"""Live HEAD of the repo being indexed, for stamping health rows.
@@ -1658,9 +1832,7 @@ async def save_full_health_report(
# open plan a person has triaged, and empty both queues on the strength
# of a parse failure or an exclude pattern that matched everything.
return
- await save_health_metrics(
- session, repo_id, metrics, analyzed_commit=analyzed_commit
- )
+ await save_health_metrics(session, repo_id, metrics, analyzed_commit=analyzed_commit)
# One savepoint over the findings and everything derived from them, so a
# rebuild that failed halfway cannot leave the queue describing findings
# that were never stored. It runs on an empty finding set too: the queue
@@ -1694,9 +1866,7 @@ async def save_full_health_report(
# Fold the plans just written into per-file opportunities. Last in the
# savepoint because it composes over the stored rows, so it has to see
# the reconciliation above rather than the detector output.
- await finalize_refactoring_opportunities(
- session, repo_id, analyzed_commit=analyzed_commit
- )
+ await finalize_refactoring_opportunities(session, repo_id, analyzed_commit=analyzed_commit)
async def persist_analysis(result: Any, session: Any, repo_id: str) -> None:
@@ -1987,6 +2157,8 @@ async def persist_pipeline_result(
result: Any,
session: Any,
repo_id: str,
+ *,
+ replace_full_git_history: bool = False,
) -> list[str]:
"""Persist all outputs from a :class:`PipelineResult` into the database.
@@ -2022,16 +2194,37 @@ async def persist_pipeline_result(
# persisters re-upsert. graph/analysis tables key off parsed_files;
# git_metadata keys off the git indexer's set (a file can be git-tracked
# but unparsed). Runs only here, never in the reusable phase persisters.
- current_graph_file_paths = {pf.file_info.path for pf in result.parsed_files}
+ # ``file_infos`` is the successful traversal set and survives individual
+ # read/parse failures. Using parsed_files here would misclassify a locked
+ # or temporarily unparsable file as excluded and erase its prior rows.
+ current_graph_file_paths = {file_info.path for file_info in result.file_infos}
current_git_file_paths = {
(gm if isinstance(gm, dict) else dataclasses.asdict(gm)).get("file_path", "")
for gm in result.git_metadata_list
}
current_git_file_paths.discard("")
- await _prune_stale_file_rows(session, repo_id, current_graph_file_paths, current_git_file_paths)
+ swept_page_ids = await reconcile_full_index_scope(
+ session, repo_id, current_graph_file_paths, current_git_file_paths
+ )
symbol_count = await persist_ingestion(result, session, repo_id)
- await persist_git(result, session, repo_id)
+ if replace_full_git_history:
+ from repowise.core.persistence.crud import purge_proposed_decisions_by_source
+
+ await purge_proposed_decisions_by_source(session, repo_id, "git_archaeology")
+ await replace_git_history(
+ session,
+ repo_id,
+ {
+ (gm if isinstance(gm, dict) else dataclasses.asdict(gm))["file_path"]: (
+ gm if isinstance(gm, dict) else dataclasses.asdict(gm)
+ )
+ for gm in result.git_metadata_list
+ },
+ result.git_summary,
+ )
+ else:
+ await persist_git(result, session, repo_id)
await persist_analysis(result, session, repo_id)
await persist_generation(result, session, repo_id)
@@ -2039,7 +2232,7 @@ async def persist_pipeline_result(
# run did not reproduce — their ids drift between runs, so without the
# sweep every re-index strands the previous set as duplicates. Full runs
# only, same rule as _prune_stale_file_rows.
- swept_page_ids = await _sweep_stale_generated_pages(
+ swept_page_ids += await _sweep_stale_generated_pages(
session,
repo_id,
result.generated_pages,
diff --git a/packages/core/src/repowise/core/repo_config.py b/packages/core/src/repowise/core/repo_config.py
index 47f28833a..8a9e5cc79 100644
--- a/packages/core/src/repowise/core/repo_config.py
+++ b/packages/core/src/repowise/core/repo_config.py
@@ -3,6 +3,8 @@
from __future__ import annotations
import contextlib
+import hashlib
+import json
from pathlib import Path
from typing import Any
@@ -12,6 +14,32 @@ CONFIG_FILENAME = "config.yaml"
#: and the analysis package; this file is on the cheap config path.
MANIFEST_BASENAME = "decisions.yaml"
+# Persisted config consumers. Keep this matrix here, beside the canonical
+# loader, so CLI and workspace update paths do not grow competing ideas of what
+# a setting invalidates. Unknown keys get their own conservative bucket: they
+# are never silently folded into an unrelated health-only refresh.
+CONFIG_DEPENDENCY_KEYS: dict[str, frozenset[str]] = {
+ "traversal": frozenset({"exclude_patterns"}),
+ "git_history": frozenset({"commit_limit", "follow_renames"}),
+ "health": frozenset({"coverage", "refactoring"}),
+ "generation": frozenset(
+ {
+ "provider",
+ "model",
+ "embedder",
+ "embedding_model",
+ "reasoning",
+ "max_tokens",
+ "wiki_style",
+ "language",
+ "max_file_pages",
+ "generation_context",
+ "enable_onboarding",
+ }
+ ),
+ "state_only": frozenset({"distill", "mcp"}),
+}
+
class RepoConfigError(ValueError):
"""A repo-local ``.repowise/config.yaml`` or ``.env`` could not be parsed.
@@ -65,9 +93,7 @@ def load_repo_config(repo_path: Path | str) -> dict[str, Any]:
# A broken config must never be silently treated as "no config": the
# user's provider/model/coverage settings would silently vanish and
# every run would use defaults. Name the file and the parse error.
- raise RepoConfigError(
- f"Could not parse {config_path}: {exc}"
- ) from exc
+ raise RepoConfigError(f"Could not parse {config_path}: {exc}") from exc
def save_repo_config(repo_path: Path | str, config: dict[str, Any]) -> None:
@@ -117,8 +143,6 @@ def config_fingerprint(repo_path: Path | str) -> str:
timestamps. Missing files are skipped, so an absent config still yields a
stable hash.
"""
- import hashlib
-
rw_dir = get_repowise_dir(repo_path)
h = hashlib.sha256()
for name in ("config.yaml", "health-rules.json"):
@@ -129,6 +153,59 @@ def config_fingerprint(repo_path: Path | str) -> str:
return h.hexdigest()
+def config_dependency_fingerprints(
+ repo_path: Path | str, *, config: dict[str, Any] | None = None
+) -> dict[str, str]:
+ """Return semantic fingerprints grouped by their persisted consumers.
+
+ ``config_fingerprint`` intentionally hashes raw bytes and remains the cheap
+ broad change detector. These hashes answer the next question: which layer
+ actually became stale? Formatting-only YAML edits therefore advance the
+ broad fingerprint without paying for an analysis rebuild.
+
+ ``health-rules.json`` belongs to the health bucket. Its bytes are retained
+ rather than parsed here because the health loader owns its validation and
+ fallback semantics.
+ """
+ if config is None:
+ config = load_repo_config(repo_path)
+ known = set().union(*CONFIG_DEPENDENCY_KEYS.values())
+ grouped: dict[str, Any] = {
+ name: {key: config[key] for key in sorted(keys) if key in config}
+ for name, keys in CONFIG_DEPENDENCY_KEYS.items()
+ }
+ grouped["other"] = {key: config[key] for key in sorted(config) if key not in known}
+
+ rules_path = get_repowise_dir(repo_path) / "health-rules.json"
+ grouped["health"] = {
+ "config": grouped["health"],
+ "health_rules_sha256": (
+ hashlib.sha256(rules_path.read_bytes()).hexdigest() if rules_path.exists() else None
+ ),
+ }
+
+ return {
+ name: hashlib.sha256(
+ json.dumps(value, sort_keys=True, separators=(",", ":"), default=str).encode("utf-8")
+ ).hexdigest()
+ for name, value in grouped.items()
+ }
+
+
+def changed_config_dependencies(previous: Any, current: dict[str, str]) -> set[str] | None:
+ """Return changed dependency classes, or ``None`` for legacy state.
+
+ A state file without the grouped hashes cannot safely identify which key
+ moved. Callers treat that one-time case conservatively rather than guessing
+ from the new config alone.
+ """
+ if not isinstance(previous, dict):
+ return None
+ return {
+ name for name in set(previous) | set(current) if previous.get(name) != current.get(name)
+ }
+
+
def _read_flat_scalar(text: str, key: str) -> str | None:
"""Read a top-level scalar from config text before YAML bool coercion."""
for line in text.splitlines():
@@ -302,9 +379,7 @@ def ensure_manifest_tracked(repo_path: Path | str) -> bool:
"/.repowise/*",
f"!/.repowise/{MANIFEST_BASENAME}",
]
- atomic_write_text(
- gitignore, newline.join([*lines, *addition]) + newline, newline=""
- )
+ atomic_write_text(gitignore, newline.join([*lines, *addition]) + newline, newline="")
return True
diff --git a/packages/core/src/repowise/core/workspace/update.py b/packages/core/src/repowise/core/workspace/update.py
index 6714c1220..0ab836a3f 100644
--- a/packages/core/src/repowise/core/workspace/update.py
+++ b/packages/core/src/repowise/core/workspace/update.py
@@ -11,6 +11,7 @@ import json as _json
import logging
import sqlite3
import subprocess
+import time
from collections.abc import Awaitable, Callable
from contextlib import suppress
from dataclasses import dataclass
@@ -107,6 +108,7 @@ class RepoUpdateResult:
# tree state has no ``last_sync_commit`` to diff against. None on the
# commit-anchored path, which leaves the stored list alone.
working_tree_paths: list[str] | None = None
+ phase_timings: dict[str, float] | None = None
# ---------------------------------------------------------------------------
@@ -560,12 +562,20 @@ async def update_single_repo_index(
incremental failure run the full ingestion pipeline instead (index-only —
no wiki pages).
"""
- from ..repo_config import config_fingerprint
+ from ..repo_config import (
+ changed_config_dependencies,
+ config_dependency_fingerprints,
+ config_fingerprint,
+ load_repo_config,
+ )
alias = repo_path.name
state = read_repo_state(repo_path)
base_ref = state.get("last_sync_commit")
merged_excludes = _merged_repo_excludes(repo_path, exclude_patterns)
+ repo_config = load_repo_config(repo_path)
+ repo_commit_depth = int(repo_config.get("commit_limit", commit_depth))
+ repo_follow_renames = bool(repo_config.get("follow_renames", False))
# Config drift check, mirroring the single-repo update path: a changed
# config.yaml / health-rules.json invalidates persisted health scores and
@@ -577,7 +587,33 @@ async def update_single_repo_index(
# surprise full re-index.
stored_fp = state.get("config_fingerprint")
config_changed = stored_fp is not None and stored_fp != config_fingerprint(repo_path)
- if config_changed and (repo_path / ".repowise" / "wiki.db").is_file():
+ current_dependency_fps = config_dependency_fingerprints(repo_path, config=repo_config)
+ changed_dependencies = (
+ changed_config_dependencies(
+ state.get("config_dependency_fingerprints"), current_dependency_fps
+ )
+ if config_changed
+ else set()
+ )
+ # Workspace indexing has no generation layer. Only settings that affect
+ # its persisted graph/history/health stores require a full re-index;
+ # formatting, distill/MCP, and generation-only edits are state updates.
+ requires_full_reindex = config_changed and (
+ changed_dependencies is None
+ or bool((changed_dependencies or set()) - {"state_only", "generation"})
+ )
+ require_git_success = requires_full_reindex and (
+ changed_dependencies is None
+ or bool({"traversal", "git_history", "other"} & (changed_dependencies or set()))
+ )
+ require_health_success = requires_full_reindex and (
+ changed_dependencies is None
+ or bool(
+ {"traversal", "git_history", "health", "other"}
+ & (changed_dependencies or set())
+ )
+ )
+ if requires_full_reindex and (repo_path / ".repowise" / "wiki.db").is_file():
_log.info(
"workspace_update: %s config fingerprint drifted — full re-index "
"so health scores reflect the new config",
@@ -585,7 +621,7 @@ async def update_single_repo_index(
)
if (
- not config_changed
+ not requires_full_reindex
and base_ref
and (repo_path / ".repowise" / "wiki.db").is_file()
and commit_exists(repo_path, str(base_ref))
@@ -612,10 +648,13 @@ async def update_single_repo_index(
result = await index_repo_full(
repo_path,
- commit_depth=commit_depth,
+ commit_depth=repo_commit_depth,
exclude_patterns=merged_excludes,
include_submodules=bool(state.get("include_submodules", False)),
include_nested_repos=bool(state.get("include_nested_repos", False)),
+ follow_renames=repo_follow_renames,
+ require_git_success=require_git_success,
+ require_health_success=require_health_success,
progress=progress,
)
@@ -691,6 +730,8 @@ async def update_workspace(
Returns:
List of :class:`RepoUpdateResult` for each repo.
"""
+ from ..repo_config import config_fingerprint
+
results: list[RepoUpdateResult] = []
# (alias, path, new_head, first_time)
stale_repos: list[tuple[str, Path, str, bool]] = []
@@ -730,6 +771,7 @@ async def update_workspace(
state_path = abs_path / ".repowise" / "state.json"
stored_commit = None
+ state: dict[str, Any] = {}
if state_path.is_file():
try:
state = json.loads(state_path.read_text(encoding="utf-8"))
@@ -741,6 +783,19 @@ async def update_workspace(
abs_path,
stored_commit,
)
+ stored_config_fp = state.get("config_fingerprint")
+ config_state_missing = (
+ (abs_path / ".repowise" / "wiki.db").is_file()
+ and stored_config_fp is None
+ )
+ if not is_stale and (
+ config_state_missing
+ or (
+ stored_config_fp is not None
+ and stored_config_fp != config_fingerprint(abs_path)
+ )
+ ):
+ is_stale = True
# A watched repo's changes are uncommitted by definition, so the
# commit-to-commit staleness check above says "up to date" for exactly
@@ -857,12 +912,15 @@ async def update_workspace(
)
try:
+ update_started = time.monotonic()
result = await update_single_repo_index(
path,
commit_depth=commit_depth,
exclude_patterns=exclude_patterns,
include_working_tree=include_working_tree,
)
+ if result.updated and result.phase_timings is None:
+ result.phase_timings = {"run": time.monotonic() - update_started}
finally:
_release_lock(path)
result.alias = alias
@@ -886,13 +944,24 @@ async def update_workspace(
state["knowledge_graph"] = result.kg_state
if result.working_tree_paths is not None:
state["working_tree_paths"] = result.working_tree_paths
+ if result.phase_timings is not None:
+ state["phase_timings"] = result.phase_timings
# Stamp the config fingerprint so the drift check in
# update_single_repo_index stays calibrated (and legacy repos
# without one stop re-triggering the full re-index).
with suppress(Exception):
- from ..repo_config import config_fingerprint
+ from ..repo_config import (
+ config_dependency_fingerprints,
+ config_fingerprint,
+ load_repo_config,
+ )
state["config_fingerprint"] = config_fingerprint(path)
+ state["config_dependency_fingerprints"] = (
+ config_dependency_fingerprints(
+ path, config=load_repo_config(path)
+ )
+ )
# Mark first-time so downstream tooling (status, doctor) can
# distinguish a never-indexed repo from one that's been
# updated at least once.
diff --git a/tests/integration/test_config_invalidation_parity.py b/tests/integration/test_config_invalidation_parity.py
new file mode 100644
index 000000000..1e8603b3b
--- /dev/null
+++ b/tests/integration/test_config_invalidation_parity.py
@@ -0,0 +1,325 @@
+"""Clean/index-update parity for persisted configuration dependencies."""
+
+from __future__ import annotations
+
+import asyncio
+import json
+import os
+import shutil
+import sqlite3
+import subprocess
+from contextlib import closing
+from pathlib import Path
+
+import pytest
+import yaml
+from click.testing import CliRunner
+
+from repowise.cli.helpers import release_update_lock
+from repowise.cli.main import cli
+from repowise.core.persistence.vector_store import LanceDBVectorStore
+from repowise.core.providers.embedding.base import MockEmbedder
+from repowise.core.workspace.update import update_single_repo_index
+
+
+def _git(repo: Path, *args: str) -> None:
+ env = {
+ **os.environ,
+ "GIT_AUTHOR_NAME": "Config Parity",
+ "GIT_AUTHOR_EMAIL": "[email protected]",
+ "GIT_COMMITTER_NAME": "Config Parity",
+ "GIT_COMMITTER_EMAIL": "[email protected]",
+ }
+ subprocess.run(["git", *args], cwd=repo, check=True, capture_output=True, env=env)
+
+
+def _invoke(runner: CliRunner, repo: Path, *args: str) -> str:
+ try:
+ result = runner.invoke(cli, [*args, str(repo)], catch_exceptions=False)
+ assert result.exit_code == 0, result.output
+ return result.output
+ finally:
+ # CliRunner executes multiple commands in one process; production CLI
+ # invocations release this atexit lock when each process exits.
+ release_update_lock(repo)
+
+
+def _write_config(repo: Path, **changes: object) -> None:
+ path = repo / ".repowise" / "config.yaml"
+ config = yaml.safe_load(path.read_text(encoding="utf-8")) or {}
+ config.update(changes)
+ path.write_text(yaml.safe_dump(config, sort_keys=False), encoding="utf-8")
+
+
+def _rows(db: Path, query: str) -> list[tuple]:
+ with closing(sqlite3.connect(db)) as connection:
+ return connection.execute(query).fetchall()
+
+
+def _snapshot(repo: Path) -> dict[str, object]:
+ db = repo / ".repowise" / "wiki.db"
+ store = LanceDBVectorStore(str(repo / ".repowise" / "lancedb"), embedder=MockEmbedder())
+ return {
+ "commits": _rows(db, "SELECT sha FROM git_commits ORDER BY sha"),
+ "git": _rows(
+ db,
+ "SELECT file_path, commit_count_total, co_change_partners_json "
+ "FROM git_metadata ORDER BY file_path",
+ ),
+ "nodes": _rows(
+ db,
+ "SELECT node_id, node_type, file_path FROM graph_nodes "
+ "ORDER BY node_id, node_type, file_path",
+ ),
+ "edges": _rows(
+ db,
+ "SELECT source_node_id, target_node_id, edge_type FROM graph_edges "
+ "ORDER BY source_node_id, target_node_id, edge_type",
+ ),
+ "symbols": _rows(
+ db,
+ "SELECT file_path, name, kind FROM wiki_symbols ORDER BY file_path, name, kind",
+ ),
+ "health": _rows(
+ db,
+ "SELECT file_path FROM health_file_metrics ORDER BY file_path",
+ ),
+ "decisions": _rows(
+ db,
+ "SELECT id, title, source, evidence_file, evidence_commits_json "
+ "FROM decision_records ORDER BY id",
+ ),
+ "active_pages": _rows(
+ db,
+ "SELECT id, page_type, target_path, title FROM wiki_pages "
+ "WHERE freshness_status != 'tombstone' ORDER BY id",
+ ),
+ "fts": _rows(
+ db,
+ "SELECT page_id FROM page_fts ORDER BY page_id",
+ ),
+ "vectors": sorted(asyncio.run(store.list_page_ids())),
+ }
+
+
+ "update_args",
+ [
+ ("--index-only",),
+ ("--docs", "--provider", "mock"),
+ ],
+ ids=("index-only", "docs"),
+)
+def test_config_updates_converge_with_clean_index(
+ tmp_path: Path, monkeypatch, update_args: tuple[str, ...]
+) -> None:
+ incremental = tmp_path / "incremental" / "repo"
+ incremental.parent.mkdir()
+ incremental.mkdir()
+ (incremental / "src").mkdir()
+ (incremental / "src" / "a.py").write_text("def a():\n return 1\n", encoding="utf-8")
+ (incremental / "src" / "b.py").write_text("def b():\n return 2\n", encoding="utf-8")
+ _git(incremental, "init", "-q")
+ for number, name in enumerate(("a", "b", "a", "b", "a"), 1):
+ target = incremental / "src" / f"{name}.py"
+ target.write_text(
+ target.read_text(encoding="utf-8") + f"# history {number}\n",
+ encoding="utf-8",
+ )
+ _git(incremental, "add", "-A")
+ _git(incremental, "commit", "-q", "-m", f"history {number}")
+
+ control = tmp_path / "control" / "repo"
+ control.parent.mkdir()
+ shutil.copytree(incremental, control)
+ runner = CliRunner()
+ common_init = (
+ "init",
+ "--embedder",
+ "mock",
+ "--no-editor-setup",
+ "--no-hook",
+ "--no-agents",
+ "--no-codex",
+ "--no-claude-md",
+ "--no-cost-tracking",
+ "--no-workspace",
+ "-y",
+ )
+ common_init += (
+ ("--provider", "mock") if update_args[0] == "--docs" else ("--no-prose",)
+ )
+
+ incremental_db = incremental / ".repowise" / "wiki.db"
+ monkeypatch.setenv("REPOWISE_DB_URL", f"sqlite+aiosqlite:///{incremental_db}")
+ _invoke(runner, incremental, *common_init, "--commit-limit", "1")
+ timings_before = json.loads(
+ (incremental / ".repowise" / "state.json").read_text(encoding="utf-8")
+ )["phase_timings"]
+
+ _write_config(incremental, commit_limit=5)
+ _invoke(runner, incremental, "update", *update_args, "--no-workspace", "--no-agents")
+ limit_state = json.loads((incremental / ".repowise" / "state.json").read_text(encoding="utf-8"))
+ assert limit_state["phase_timings"] != timings_before
+ assert "rebuild.git" in limit_state["phase_timings"]
+ assert (
+ "render" in limit_state["phase_timings"]
+ if update_args[0] == "--index-only"
+ else "generate" in limit_state["phase_timings"]
+ )
+ if update_args[0] == "--docs":
+ metadata_rows = _rows(
+ incremental_db,
+ "SELECT metadata_json FROM wiki_pages WHERE freshness_status != 'tombstone'",
+ )
+ assert not any(
+ json.loads(metadata or "{}").get("reused_from_prior_run")
+ for (metadata,) in metadata_rows
+ )
+
+ # Unknown settings are deliberately conservative: future consumers must
+ # not inherit a fingerprint already stamped by a health-only fast path.
+ _write_config(incremental, future_setting=True)
+ _invoke(runner, incremental, "update", *update_args, "--no-workspace", "--no-agents")
+ other_timings = json.loads(
+ (incremental / ".repowise" / "state.json").read_text(encoding="utf-8")
+ )["phase_timings"]
+ assert "rebuild.git" in other_timings
+ assert (
+ "render" in other_timings
+ if update_args[0] == "--index-only"
+ else "generate" in other_timings
+ )
+
+ _write_config(incremental, exclude_patterns=["src/a.py"])
+ _invoke(runner, incremental, "update", *update_args, "--no-workspace", "--no-agents")
+ excluded_id = "src/a.py"
+ assert not any(
+ excluded_id in page_id
+ for (page_id,) in _rows(
+ incremental_db,
+ "SELECT id FROM wiki_pages WHERE freshness_status != 'tombstone'",
+ )
+ )
+ stale_content_pages = [
+ page_id
+ for page_id, content in _rows(
+ incremental_db,
+ "SELECT id, content FROM wiki_pages WHERE freshness_status != 'tombstone'",
+ )
+ if excluded_id in content
+ ]
+ assert not stale_content_pages, stale_content_pages
+ incremental_store = LanceDBVectorStore(
+ str(incremental / ".repowise" / "lancedb"), embedder=MockEmbedder()
+ )
+ assert not any(
+ excluded_id in page_id for page_id in asyncio.run(incremental_store.list_page_ids())
+ )
+
+ generation_changes: dict[str, object] = {
+ "enable_onboarding": False,
+ "max_file_pages": 1,
+ }
+ if update_args[0] == "--docs":
+ generation_changes["reasoning"] = "high"
+ _write_config(incremental, **generation_changes)
+ _invoke(runner, incremental, "update", *update_args, "--no-workspace", "--no-agents")
+ assert not _rows(
+ incremental_db,
+ "SELECT id FROM wiki_pages WHERE page_type = 'onboarding' "
+ "AND freshness_status != 'tombstone'",
+ )
+ if update_args[0] == "--docs":
+ metadata_rows = _rows(
+ incremental_db,
+ "SELECT metadata_json FROM wiki_pages WHERE freshness_status != 'tombstone'",
+ )
+ assert not any(
+ json.loads(metadata or "{}").get("reused_from_prior_run")
+ for (metadata,) in metadata_rows
+ )
+
+ control_db = control / ".repowise" / "wiki.db"
+ monkeypatch.setenv("REPOWISE_DB_URL", f"sqlite+aiosqlite:///{control_db}")
+ _invoke(
+ runner,
+ control,
+ *common_init,
+ "--commit-limit",
+ "5",
+ *(("--reasoning", "high") if update_args[0] == "--docs" else ()),
+ "-x",
+ "src/a.py",
+ "--no-onboarding",
+ "--max-file-pages",
+ "1",
+ )
+
+ assert _snapshot(incremental) == _snapshot(control)
+
+
+def test_workspace_full_reindex_reconciles_authoritative_empty_scope(
+ tmp_path: Path, monkeypatch
+) -> None:
+ repo = tmp_path / "workspace" / "repo"
+ (repo / "src").mkdir(parents=True)
+ (repo / "src" / "a.py").write_text("def a():\n return 1\n", encoding="utf-8")
+ _git(repo, "init", "-q")
+ _git(repo, "add", "-A")
+ _git(repo, "commit", "-q", "-m", "initial")
+ for number in range(4):
+ source = repo / "src" / "a.py"
+ source.write_text(
+ source.read_text(encoding="utf-8") + f"# history {number}\n",
+ encoding="utf-8",
+ )
+ _git(repo, "add", "-A")
+ _git(repo, "commit", "-q", "-m", f"history {number}")
+
+ db = repo / ".repowise" / "wiki.db"
+ monkeypatch.setenv("REPOWISE_DB_URL", f"sqlite+aiosqlite:///{db}")
+ runner = CliRunner()
+ _invoke(
+ runner,
+ repo,
+ "init",
+ "--no-prose",
+ "--embedder",
+ "mock",
+ "--no-editor-setup",
+ "--no-hook",
+ "--no-agents",
+ "--no-codex",
+ "--no-claude-md",
+ "--no-cost-tracking",
+ "--no-workspace",
+ "-y",
+ )
+ assert len(_rows(db, "SELECT sha FROM git_commits")) > 1
+ _write_config(repo, commit_limit=1)
+ history_result = asyncio.run(update_single_repo_index(repo))
+ assert history_result.updated is True and history_result.error is None
+ assert len(_rows(db, "SELECT sha FROM git_commits")) == 1
+
+ _write_config(repo, exclude_patterns=["src/**"])
+
+ result = asyncio.run(update_single_repo_index(repo))
+
+ assert result.updated is True and result.error is None
+ assert not _rows(db, "SELECT node_id FROM graph_nodes")
+ assert not _rows(db, "SELECT file_path FROM git_metadata")
+ assert not _rows(
+ db,
+ "SELECT id FROM wiki_pages WHERE page_type IN "
+ "('file_page', 'api_contract', 'infra_page', 'symbol_spotlight') "
+ "AND freshness_status != 'tombstone'",
+ )
+ assert not any(
+ "src/a.py" in page_id
+ for (page_id,) in _rows(db, "SELECT page_id FROM page_fts")
+ )
+ store = LanceDBVectorStore(str(repo / ".repowise" / "lancedb"), embedder=MockEmbedder())
+ assert not any(
+ "src/a.py" in page_id for page_id in asyncio.run(store.list_page_ids())
+ )
diff --git a/tests/unit/cli/test_commands.py b/tests/unit/cli/test_commands.py
index 4cf73042e..fdb893d06 100644
--- a/tests/unit/cli/test_commands.py
+++ b/tests/unit/cli/test_commands.py
@@ -448,15 +448,28 @@ class TestRescoreFailureFingerprint:
monkeypatch.setattr(update_cmd.persistence, "run_async", _boom)
(tmp_path / "f.py").write_text("x = 1\n", encoding="utf-8")
- update_cmd._run_full_health_rescore(
- tmp_path, [], {"last_sync_commit": "base"}, "head1", "NEWFP"
- )
+ with pytest.raises(RuntimeError, match="db down"):
+ update_cmd._run_full_health_rescore(
+ tmp_path, [], {"last_sync_commit": "base"}, "head1", "NEWFP"
+ )
state_file = tmp_path / ".repowise" / "state.json"
if state_file.exists():
assert json.loads(state_file.read_text()).get("config_fingerprint") != "NEWFP"
+def test_config_generation_embedding_warning_is_fatal():
+ from repowise.cli.commands.update_cmd.command import _generation_warning_handler
+
+ degraded: list[str] = []
+ callback = _generation_warning_handler(degraded, require_embedding_success=True)
+
+ with pytest.raises(RuntimeError, match="page embedding failed"):
+ callback("Embedding failed for 2 page(s)")
+
+ assert degraded == ["Embedding failed for 2 page(s)"]
+
+
class TestBuildRepoGraph:
"""The shared traverse/parse/build helper used by both the incremental
rebuild and the config-triggered re-score paths."""
@@ -488,11 +501,14 @@ class TestBuildRepoGraph:
# it looks up console — patch the name there.
monkeypatch.setattr(update_cmd.incremental, "console", _FakeConsole())
- parsed_files, _src, _gb, _struct, _count = update_cmd._build_repo_graph(tmp_path, [])
+ parsed_files, _src, graph_builder, _struct, _count = update_cmd._build_repo_graph(
+ tmp_path, []
+ )
paths = [pf.file_info.path for pf in parsed_files]
assert any(p.endswith("good.py") for p in paths)
assert not any(p.endswith("bad.py") for p in paths)
+ assert "bad.py" in graph_builder.traversed_file_paths
assert any("Skipped" in line for line in printed)
def test_includes_framework_edge_step(self, tmp_path, monkeypatch):
@@ -520,3 +536,21 @@ class TestBuildRepoGraph:
update_cmd._build_repo_graph(tmp_path, [])
assert calls, "framework-edge step must run in the shared rebuild path"
+
+
+def test_required_vector_refresh_rejects_incompatible_existing_store(
+ tmp_path, monkeypatch
+):
+ import repowise.cli.providers as providers
+ from repowise.cli.commands.update_cmd.incremental import _build_update_vector_store
+
+ (tmp_path / ".repowise" / "lancedb").mkdir(parents=True)
+ monkeypatch.setattr(providers, "build_embedder", lambda *_args, **_kwargs: object())
+ monkeypatch.setattr(providers, "resolve_embedder", lambda *_args, **_kwargs: "mock")
+ monkeypatch.setattr(providers, "build_vector_store", lambda *_args, **_kwargs: None)
+ degraded: list[str] = []
+
+ with pytest.raises(RuntimeError, match="cannot safely refresh"):
+ _build_update_vector_store(tmp_path, {"embedder": "mock"}, degraded, required=True)
+
+ assert degraded and "cannot safely refresh" in degraded[0]
diff --git a/tests/unit/cli/test_update_persist_reliability.py b/tests/unit/cli/test_update_persist_reliability.py
index 00c58d36a..d847262fc 100644
--- a/tests/unit/cli/test_update_persist_reliability.py
+++ b/tests/unit/cli/test_update_persist_reliability.py
@@ -124,6 +124,143 @@ def test_full_persist_collects_degraded_steps(tmp_path: Path) -> None:
assert any(entry.startswith("Graph nodes persist:") for entry in degraded)
+def test_required_config_persist_rejects_any_degraded_dependency(tmp_path: Path) -> None:
+ (tmp_path / ".repowise").mkdir()
+
+ with pytest.raises(RuntimeError, match="did not update every dependent store"):
+ asyncio.run(
+ _persist_full_update_async(
+ repo_path=tmp_path,
+ repo_name="repo",
+ generated_pages=[_page("file_page:a.py")],
+ file_diffs=[],
+ git_meta_map={},
+ new_decision_markers=[],
+ decision_vector_store=None,
+ provider=None,
+ partial_health_report=None,
+ dead_code_report=None,
+ graph_builder=None,
+ knowledge_graph_result=None,
+ degraded=[],
+ require_config_rebuild_success=True,
+ )
+ )
+
+ assert asyncio.run(_count_pages(tmp_path)) == 0
+
+
+def test_failed_fts_cleanup_debt_retries_on_next_persist(tmp_path: Path, monkeypatch) -> None:
+ import repowise.core.persistence as persistence
+ from repowise.core.pipeline.cleanup_debt import (
+ load_cleanup_debt,
+ record_cleanup_debt,
+ )
+
+ (tmp_path / ".repowise").mkdir()
+ orphan = "file_page:removed.py"
+ record_cleanup_debt(tmp_path, "fts", {orphan})
+ attempts: list[list[str]] = []
+
+ class _FailOnceFTS:
+ async def ensure_index(self):
+ return None
+
+ async def index(self, *args, **kwargs):
+ return None
+
+ async def delete_many(self, page_ids):
+ attempts.append(list(page_ids))
+ if len(attempts) == 1:
+ raise RuntimeError("fts unavailable")
+
+ monkeypatch.setattr(persistence, "FullTextSearch", lambda _engine: _FailOnceFTS())
+
+ async def _persist_once() -> None:
+ await _persist_full_update_async(
+ repo_path=tmp_path,
+ repo_name="repo",
+ generated_pages=[],
+ file_diffs=[],
+ git_meta_map={},
+ new_decision_markers=[],
+ decision_vector_store=None,
+ provider=None,
+ partial_health_report=None,
+ dead_code_report=None,
+ graph_builder=None,
+ knowledge_graph_result=None,
+ degraded=[],
+ )
+
+ asyncio.run(_persist_once())
+ assert load_cleanup_debt(tmp_path)["fts"] == {orphan}
+ asyncio.run(_persist_once())
+ assert attempts == [[orphan], [orphan]]
+ assert load_cleanup_debt(tmp_path)["fts"] == set()
+
+
+def test_required_git_decision_persist_failure_rolls_back(tmp_path: Path, monkeypatch) -> None:
+ from dataclasses import dataclass
+
+ import repowise.core.persistence.crud as crud
+
+ (tmp_path / ".repowise").mkdir()
+
+ @dataclass
+ class _Decision:
+ title: str = "Use durable retries"
+
+ async def _boom(*args, **kwargs):
+ raise RuntimeError("decision store down")
+
+ monkeypatch.setattr(crud, "bulk_upsert_decisions", _boom)
+
+ with pytest.raises(RuntimeError, match="decision store down"):
+ asyncio.run(
+ _persist_full_update_async(
+ repo_path=tmp_path,
+ repo_name="repo",
+ generated_pages=[_page("file_page:a.py")],
+ file_diffs=[],
+ git_meta_map={},
+ new_decision_markers=[_Decision()],
+ decision_vector_store=None,
+ provider=None,
+ partial_health_report=None,
+ dead_code_report=None,
+ graph_builder=None,
+ knowledge_graph_result=None,
+ degraded=[],
+ require_decision_persist_success=True,
+ )
+ )
+
+ assert asyncio.run(_count_pages(tmp_path)) == 0
+
+
+def test_missing_reingested_coverage_is_authoritative_empty(tmp_path: Path, monkeypatch) -> None:
+ from repowise.cli.commands.update_cmd.persistence import _coverage_for_rescore
+
+ monkeypatch.setattr(
+ "repowise.core.repo_config.load_repo_config",
+ lambda _path: {"coverage": {"reingest_on_update": True}},
+ )
+ monkeypatch.setattr(
+ "repowise.core.analysis.health.coverage.discover_artifacts",
+ lambda *_args, **_kwargs: [],
+ )
+
+ coverage_map, files, source_format, authoritative = asyncio.run(
+ _coverage_for_rescore(object(), "repo", tmp_path, [])
+ )
+
+ assert coverage_map == {}
+ assert files == []
+ assert source_format is None
+ assert authoritative is True
+
+
# ---------------------------------------------------------------------------
# A retirement has to reach an index nobody re-indexes
# ---------------------------------------------------------------------------
diff --git a/tests/unit/persistence/test_decision_sticky_status.py b/tests/unit/persistence/test_decision_sticky_status.py
index a5fda8f34..8e4133ebc 100644
--- a/tests/unit/persistence/test_decision_sticky_status.py
+++ b/tests/unit/persistence/test_decision_sticky_status.py
@@ -19,6 +19,7 @@ from repowise.core.persistence.crud import (
list_decision_evidence,
list_decisions,
purge_proposed_decisions_by_source,
+ purge_proposed_decisions_outside_files,
update_decision_status,
)
from repowise.core.persistence.crud.authority import latest_acceptance
@@ -184,3 +185,24 @@ async def test_purge_drains_proposed_rows_of_source_only(async_session):
.where(DecisionRecord.id.is_(None))
)
assert list(orphan_evidence.scalars().all()) == []
+
+
+async def test_scope_prune_removes_only_unreviewed_decisions(async_session):
+ repo = await insert_repo(async_session)
+ await bulk_upsert_decisions(
+ async_session,
+ repo.id,
+ [_decision("Excluded proposal"), _decision("Accepted history")],
+ )
+ rows = await list_decisions(async_session, repo.id)
+ accepted = next(row for row in rows if row.title == "Accepted history")
+ await update_decision_status(async_session, accepted.id, "active")
+
+ deleted = await purge_proposed_decisions_outside_files(
+ async_session, repo.id, {"kept.py"}
+ )
+
+ assert deleted == 1
+ assert {row.title for row in await list_decisions(async_session, repo.id)} == {
+ "Accepted history"
+ }
diff --git a/tests/unit/pipeline/test_incremental_failure_isolation.py b/tests/unit/pipeline/test_incremental_failure_isolation.py
index 1e6e6b87d..02399f78e 100644
--- a/tests/unit/pipeline/test_incremental_failure_isolation.py
+++ b/tests/unit/pipeline/test_incremental_failure_isolation.py
@@ -144,6 +144,7 @@ def test_the_range_scoped_set_is_exactly_these_steps():
"Graph edges persist",
"External systems refresh",
"Tombstone full-text removal",
+ "Tombstone vector-store open",
}
@@ -162,3 +163,49 @@ async def test_clean_run_marks_nothing(repo):
failed_steps=failed_steps,
)
assert failed_steps == []
+
+
+async def test_vector_cleanup_open_failure_keeps_debt_for_retry(repo, monkeypatch):
+ import repowise.core.persistence.vector_store as vector_store_mod
+ from repowise.core.pipeline.cleanup_debt import (
+ load_cleanup_debt,
+ record_cleanup_debt,
+ )
+
+ orphan = "file_page:removed.py"
+ (repo / ".repowise" / "lancedb").mkdir()
+ record_cleanup_debt(repo, "vectors", {orphan})
+ opened = 0
+ deleted: list[str] = []
+
+ class _Store:
+ async def delete_many(self, page_ids):
+ deleted.extend(page_ids)
+
+ def _open(*args, **kwargs):
+ nonlocal opened
+ opened += 1
+ if opened == 1:
+ raise RuntimeError("lance unavailable")
+ return _Store()
+
+ monkeypatch.setattr(vector_store_mod, "LanceDBVectorStore", _open)
+
+ async def _persist_once() -> None:
+ await persist_incremental_index(
+ repo,
+ object(),
+ {},
+ None,
+ None,
+ [],
+ log=lambda _msg: None,
+ degraded=[],
+ failed_steps=[],
+ )
+
+ await _persist_once()
+ assert load_cleanup_debt(repo)["vectors"] == {orphan}
+ await _persist_once()
+ assert deleted == [orphan]
+ assert load_cleanup_debt(repo)["vectors"] == set()
diff --git a/tests/unit/test_repo_config_invalidation.py b/tests/unit/test_repo_config_invalidation.py
new file mode 100644
index 000000000..d95e8aa55
--- /dev/null
+++ b/tests/unit/test_repo_config_invalidation.py
@@ -0,0 +1,85 @@
+from __future__ import annotations
+
+from pathlib import Path
+
+import yaml
+
+from repowise.core.repo_config import (
+ changed_config_dependencies,
+ config_dependency_fingerprints,
+)
+
+
+def _write_config(repo: Path, **values: object) -> None:
+ config_dir = repo / ".repowise"
+ config_dir.mkdir(exist_ok=True)
+ (config_dir / "config.yaml").write_text(
+ yaml.safe_dump(values, sort_keys=False), encoding="utf-8"
+ )
+
+
+def test_dependency_fingerprints_classify_config_keys(tmp_path: Path) -> None:
+ _write_config(
+ tmp_path,
+ commit_limit=1,
+ follow_renames=False,
+ exclude_patterns=[],
+ provider="mock",
+ enable_onboarding=True,
+ )
+ baseline = config_dependency_fingerprints(tmp_path)
+
+ cases = [
+ ("git_history", {"commit_limit": 5}),
+ ("git_history", {"follow_renames": True}),
+ ("traversal", {"exclude_patterns": ["generated/**"]}),
+ ("generation", {"provider": "openai"}),
+ ("generation", {"enable_onboarding": False}),
+ ("other", {"future_setting": True}),
+ ]
+ for expected, change in cases:
+ values = {
+ "commit_limit": 1,
+ "follow_renames": False,
+ "exclude_patterns": [],
+ "provider": "mock",
+ "enable_onboarding": True,
+ **change,
+ }
+ _write_config(tmp_path, **values)
+ current = config_dependency_fingerprints(tmp_path)
+ assert changed_config_dependencies(baseline, current) == {expected}
+
+
+def test_health_rules_only_invalidate_health(tmp_path: Path) -> None:
+ _write_config(tmp_path, commit_limit=1)
+ baseline = config_dependency_fingerprints(tmp_path)
+ (tmp_path / ".repowise" / "health-rules.json").write_text(
+ '{"disabled_biomarkers": ["ungoverned_hotspot"]}', encoding="utf-8"
+ )
+
+ assert changed_config_dependencies(baseline, config_dependency_fingerprints(tmp_path)) == {
+ "health"
+ }
+
+
+def test_legacy_state_is_reported_as_unknown(tmp_path: Path) -> None:
+ _write_config(tmp_path, commit_limit=1)
+ assert changed_config_dependencies(None, config_dependency_fingerprints(tmp_path)) is None
+
+
+def test_preloaded_config_preserves_tolerant_cli_fallback(tmp_path: Path) -> None:
+ config_dir = tmp_path / ".repowise"
+ config_dir.mkdir()
+ (config_dir / "config.yaml").write_text("not: [valid", encoding="utf-8")
+
+ fingerprints = config_dependency_fingerprints(tmp_path, config={})
+
+ assert set(fingerprints) == {
+ "traversal",
+ "git_history",
+ "health",
+ "generation",
+ "state_only",
+ "other",
+ }
diff --git a/tests/unit/workspace/test_incremental_update.py b/tests/unit/workspace/test_incremental_update.py
index 59de685c3..f4dc7c6ce 100644
--- a/tests/unit/workspace/test_incremental_update.py
+++ b/tests/unit/workspace/test_incremental_update.py
@@ -120,12 +120,14 @@ def stub_full_pipeline(monkeypatch):
repo_name = "stub"
file_count = 7
symbol_count = 9
+ git_summary = object()
+ health_report = object()
async def _fake_pipeline(repo_path, **kwargs):
calls.append({"repo_path": repo_path, **kwargs})
return _FakeResult()
- async def _fake_persist(result, session, repo_id):
+ async def _fake_persist(result, session, repo_id, **kwargs):
return None
monkeypatch.setattr(pipeline_pkg, "run_pipeline", _fake_pipeline)
@@ -340,6 +342,106 @@ def test_full_pipeline_merges_repo_settings_excludes(tmp_path, stub_full_pipelin
assert stub_full_pipeline[0]["exclude_patterns"] == ["tools/"]
+def test_full_pipeline_uses_repo_history_settings(tmp_path, stub_full_pipeline):
+ from repowise.core.repo_config import save_repo_config
+
+ repo = _make_git_repo(tmp_path)
+ _mark_indexed(repo, "deadbeef" * 5)
+ save_repo_config(repo, {"commit_limit": 17, "follow_renames": True})
+
+ result = asyncio.run(update_single_repo_index(repo, commit_depth=3))
+
+ _assert_full_pipeline_fallback(result, stub_full_pipeline)
+ assert stub_full_pipeline[0]["commit_depth"] == 17
+ assert stub_full_pipeline[0]["follow_renames"] is True
+
+
+def test_config_full_pipeline_requires_changed_phases(tmp_path, monkeypatch):
+ from types import SimpleNamespace
+
+ from repowise.core.repo_config import (
+ config_dependency_fingerprints,
+ config_fingerprint,
+ save_repo_config,
+ )
+
+ captured: dict = {}
+
+ async def _fake_full_index(*args, **kwargs):
+ captured.update(kwargs)
+ return SimpleNamespace(file_count=1, symbol_count=1, knowledge_graph_result=None)
+
+ monkeypatch.setattr(
+ "repowise.core.pipeline.full_index.index_repo_full", _fake_full_index
+ )
+
+ repo = _make_git_repo(tmp_path)
+ save_repo_config(repo, {"commit_limit": 3})
+ _mark_indexed(
+ repo,
+ get_head_commit(repo),
+ config_fingerprint=config_fingerprint(repo),
+ config_dependency_fingerprints=config_dependency_fingerprints(repo),
+ )
+ save_repo_config(repo, {"commit_limit": 7})
+
+ result = asyncio.run(update_single_repo_index(repo))
+
+ assert result.updated is True
+ assert captured["require_git_success"] is True
+ assert captured["require_health_success"] is True
+
+
+ ("missing_attr", "required_kw", "message"),
+ [
+ ("git_summary", "require_git_success", "Git indexing failed"),
+ ("health_report", "require_health_success", "Health analysis failed"),
+ ],
+)
+def test_required_config_phase_failure_aborts_before_persist(
+ tmp_path, monkeypatch, missing_attr, required_kw, message
+):
+ from types import SimpleNamespace
+
+ import repowise.core.pipeline as pipeline_pkg
+ from repowise.core.pipeline.full_index import index_repo_full
+
+ async def _fake_pipeline(*args, **kwargs):
+ result = SimpleNamespace(git_summary=object(), health_report=object())
+ setattr(result, missing_attr, None)
+ return result
+
+ monkeypatch.setattr(pipeline_pkg, "run_pipeline", _fake_pipeline)
+
+ with pytest.raises(RuntimeError, match=message):
+ asyncio.run(index_repo_full(tmp_path, **{required_kw: True}))
+
+
+def test_generation_only_config_drift_stays_incremental(tmp_path, forbid_full_pipeline):
+ from repowise.core.repo_config import (
+ config_dependency_fingerprints,
+ config_fingerprint,
+ save_repo_config,
+ )
+
+ repo = _make_git_repo(tmp_path)
+ save_repo_config(repo, {"provider": "mock"})
+ base = get_head_commit(repo)
+ _mark_indexed(
+ repo,
+ base,
+ config_fingerprint=config_fingerprint(repo),
+ config_dependency_fingerprints=config_dependency_fingerprints(repo),
+ )
+ save_repo_config(repo, {"provider": "openai"})
+
+ result = asyncio.run(update_single_repo_index(repo))
+
+ assert result.updated is True
+ assert result.error is None
+
+
# ---------------------------------------------------------------------------
# Helpers under test
# ---------------------------------------------------------------------------
diff --git a/tests/unit/workspace/test_update.py b/tests/unit/workspace/test_update.py
index c75820a4e..2ec70637e 100644
--- a/tests/unit/workspace/test_update.py
+++ b/tests/unit/workspace/test_update.py
@@ -303,6 +303,16 @@ class TestUpdateWorkspace:
async def _run():
await _seed()
+ from repowise.core.repo_config import (
+ config_dependency_fingerprints,
+ config_fingerprint,
+ )
+
+ state_path = repo / ".repowise" / "state.json"
+ state = json.loads(state_path.read_text(encoding="utf-8"))
+ state["config_fingerprint"] = config_fingerprint(repo)
+ state["config_dependency_fingerprints"] = config_dependency_fingerprints(repo)
+ state_path.write_text(json.dumps(state), encoding="utf-8")
return await update_workspace(tmp_path, ws_config)
import asyncio
@@ -345,6 +355,77 @@ class TestUpdateWorkspace:
updated = [r for r in results if r.updated]
assert len(updated) == 1
assert updated[0].alias == "backend"
+ saved_state = json.loads((repo / ".repowise" / "state.json").read_text(encoding="utf-8"))
+ assert saved_state["phase_timings"]["run"] >= 0
+
+ def test_detects_config_only_staleness(self, tmp_path: Path) -> None:
+ """A workspace member with no new commit still runs when its local
+ configuration changed."""
+ from repowise.core.repo_config import config_fingerprint, save_repo_config
+
+ repo = _make_git_repo(tmp_path, "backend")
+ head = get_head_commit(repo)
+ save_repo_config(repo, {"provider": "mock"})
+ _write_state(repo, head)
+ state_path = repo / ".repowise" / "state.json"
+ state = json.loads(state_path.read_text(encoding="utf-8"))
+ state["config_fingerprint"] = config_fingerprint(repo)
+ state_path.write_text(json.dumps(state), encoding="utf-8")
+ save_repo_config(repo, {"provider": "openai"})
+
+ ws_config = WorkspaceConfig(
+ repos=[RepoEntry(path="backend", alias="backend", last_commit_at_index=head)]
+ )
+ mock_result = RepoUpdateResult(alias="backend", updated=True, file_count=1, symbol_count=1)
+
+ async def _run():
+ with patch(
+ "repowise.core.workspace.update.update_single_repo_index",
+ new_callable=AsyncMock,
+ return_value=mock_result,
+ ) as mocked:
+ results = await update_workspace(tmp_path, ws_config)
+ return results, mocked.await_count
+
+ import asyncio
+
+ results, calls = asyncio.run(_run())
+ assert calls == 1
+ assert results[0].updated is True
+ saved_state = json.loads(state_path.read_text(encoding="utf-8"))
+ assert saved_state["phase_timings"]["run"] >= 0
+
+ def test_legacy_config_fingerprints_are_backfilled_then_detect_changes(
+ self, tmp_path: Path
+ ) -> None:
+ from repowise.core.repo_config import save_repo_config
+
+ repo = _make_git_repo(tmp_path, "backend")
+ head = get_head_commit(repo)
+ _write_state(repo, head)
+ (repo / ".repowise" / "wiki.db").touch()
+ ws_config = WorkspaceConfig(
+ repos=[RepoEntry(path="backend", alias="backend", last_commit_at_index=head)]
+ )
+ mock_result = RepoUpdateResult(alias="backend", updated=True, file_count=1)
+
+ async def _run() -> int:
+ with patch(
+ "repowise.core.workspace.update.update_single_repo_index",
+ new_callable=AsyncMock,
+ return_value=mock_result,
+ ) as mocked:
+ await update_workspace(tmp_path, ws_config)
+ save_repo_config(repo, {"future_setting": True})
+ await update_workspace(tmp_path, ws_config)
+ return mocked.await_count
+
+ import asyncio
+
+ assert asyncio.run(_run()) == 2
+ state = json.loads((repo / ".repowise" / "state.json").read_text(encoding="utf-8"))
+ assert state.get("config_fingerprint")
+ assert state.get("config_dependency_fingerprints")
def test_repo_filter(self, tmp_path: Path) -> None:
"""--repo flag should only update the specified repo."""