Codebase intelligence for AI and humans: code health scores, auto-generated docs, git analytics, dead code detection, and architectural decisions via MCP.
Python aicode-complexitycode-healthcode-intelligencecode-qualitydead-codedeveloper-toolsdocumentationgit-analyticsmcpopen-sourcepythonrefactoringstatic-analysistechnical-debt
fix(index-scope): stop reporting a keyless index as upgrading (#3634)
Swati Ahuja2e212d2f0fbb
diff --git a/packages/core/src/repowise/core/index_scope.py b/packages/core/src/repowise/core/index_scope.pyindex 696eec9b4..899b09847 100644--- a/packages/core/src/repowise/core/index_scope.py+++ b/packages/core/src/repowise/core/index_scope.py@@ -245,7 +245,9 @@ INDEX_SCOPE_ENV = "REPOWISE_MCP_INDEX_SCOPE"#: Upgrade states that mean the index is still being built. Reported ahead of#: everything else: they explain the rest and they resolve on their own.-_UPGRADE_IN_FLIGHT = frozenset({"pending", "running", "resumable"})+#: ``pending`` joins them only when the run had a provider (see+#: :func:`_upgrade_in_flight`).+_UPGRADE_IN_FLIGHT = frozenset({"running", "resumable"})#: Search legs. A leg that is "pending" is not usable yet, which is a smaller#: problem than one that failed but is not nothing.@@ -258,13 +260,48 @@ def _section(scope: Mapping[str, Any], name: str) -> Mapping[str, Any]:return section if isinstance(section, Mapping) else {}+def _upgrade_in_flight(upgrade: Mapping[str, Any], scope: Mapping[str, Any]) -> bool:+ """Whether the model upgrade is under way or waiting on a provider it has.++ Every run without a model stores ``pending`` (``update --full`` reads it),+ but with no provider nothing will ever take it up, so a keyless index is+ finished and reads by its evidence like any other.+ """+ status = upgrade.get("status")+ if status in _UPGRADE_IN_FLIGHT:+ return True+ return status == "pending" and bool(_section(scope, "provider").get("name"))+++def _never_meant_to_exist(leg: str, scope: Mapping[str, Any]) -> bool:+ """Whether an unavailable search leg is the run's design, not a failure.++ A run that skipped generation has no pages to search. A keyless run (no+ provider, keyless or no embedder) never writes semantic vectors. A real+ embedder whose writes failed is neither, and stays degraded.+ """+ from repowise.core.providers.embedding.registry import KEYLESS_EMBEDDERS++ if "generation" in (_section(scope, "analysis").get("skipped") or ()):+ return True+ provider = _section(scope, "provider")+ return (+ leg == "semantic"+ and not provider.get("name")+ and (not provider.get("embedder") or provider.get("embedder") in KEYLESS_EMBEDDERS)+ )++def _is_degraded(upgrade: Mapping[str, Any], scope: Mapping[str, Any]) -> bool:"""Whether some part of the index was meant to exist and does not."""search = _section(scope, "search")return (upgrade.get("status") == "failed"or bool(_section(scope, "analysis").get("unavailable"))- or any(search.get(leg) == "unavailable" for leg in _SEARCH_LEGS)+ or any(+ search.get(leg) == "unavailable" and not _never_meant_to_exist(leg, scope)+ for leg in _SEARCH_LEGS+ ))@@ -303,7 +340,7 @@ def _scope_status(scope: Mapping[str, Any]) -> str:``unknown``, which is a different answer and says so."""upgrade = _section(scope, "upgrade")- if upgrade.get("status") in _UPGRADE_IN_FLIGHT:+ if _upgrade_in_flight(upgrade, scope):return "upgrading"if _is_degraded(upgrade, scope):return "degraded"diff --git a/tests/unit/server/mcp/test_index_scope_projection.py b/tests/unit/server/mcp/test_index_scope_projection.pyindex 5efb99c8e..626228bf1 100644--- a/tests/unit/server/mcp/test_index_scope_projection.py+++ b/tests/unit/server/mcp/test_index_scope_projection.py@@ -118,6 +118,55 @@ def test_status_names_the_condition_that_explains_the_rest(assert compact_index_scope(resolve_index_scope(state))["status"] == expected+def test_a_pending_upgrade_with_a_provider_is_upgrading() -> None:+ state = {**_FULL_STATE, "full_upgrade": {"status": "pending"}}+ assert compact_index_scope(resolve_index_scope(state))["status"] == "upgrading"+++def _keyless_state(embedder: str | None, **scope: Any) -> dict[str, Any]:+ """The scope a default keyless init stamps: no provider, no semantic vectors."""+ return {+ **_FULL_STATE,+ "docs_mode": "deterministic",+ "index_scope": {+ "git_commit_cap": 500,+ "file_pages": _WHOLE_PAGES,+ "provider": {"name": None, "embedder": embedder},+ "search": {"full_text": "available", "semantic": "unavailable"},+ **scope,+ },+ "full_upgrade": {"status": "pending"},+ }++[email protected]("embedder", ["mock", None])+def test_a_finished_keyless_index_reads_complete(embedder: str | None) -> None:+ """Nothing takes a keyless pending upgrade up, and no semantic leg was meant."""+ state = _keyless_state(embedder)+ assert compact_index_scope(resolve_index_scope(state))["status"] == "complete"++[email protected]("embedder", ["mock", None])+def test_a_keyless_index_with_omitted_pages_reads_partial(embedder: str | None) -> None:+ state = _keyless_state(embedder, file_pages={"eligible": 10, "generated": 8, "omitted": 2})+ assert compact_index_scope(resolve_index_scope(state))["status"] == "partial"+++def test_a_fast_keyless_index_with_no_pages_reads_partial() -> None:+ state = _keyless_state(+ "mock",+ file_pages={"eligible": 10, "generated": 0, "omitted": 10},+ analysis={"skipped": ["generation"]},+ search={"full_text": "unavailable", "semantic": "unavailable"},+ )+ assert compact_index_scope(resolve_index_scope(state))["status"] == "partial"+++def test_a_keyless_index_whose_real_embedder_failed_is_degraded() -> None:+ state = _keyless_state("openai")+ assert compact_index_scope(resolve_index_scope(state))["status"] == "degraded"++def test_omitted_pages_are_never_reported_as_complete() -> None:"""A partial index must not read as a whole one to save a word."""scope = resolve_index_scope(_FULL_STATE)