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(cli): drop a stale embedding_model pin when init resolves none (#2654)

Aman799d0e21fbe0
diff --git a/packages/cli/src/repowise/cli/commands/upgrade_flow.py b/packages/cli/src/repowise/cli/commands/upgrade_flow.py
index d0087159c..6d069e13f 100644
--- a/packages/cli/src/repowise/cli/commands/upgrade_flow.py
+++ b/packages/cli/src/repowise/cli/commands/upgrade_flow.py
@@ -854,7 +854,12 @@ def upgrade_to_full(
if embedder_name and embedder_name != cfg.get("embedder"):
from repowise.cli.helpers import save_config_partial
- save_config_partial(repo_path, embedder=embedder_name)
+ # Explicit `embedding_model=None`, not a bare `embedder=`: the
+ # embedder just changed, so any model pinned for the old one no
+ # longer describes what this table was built with, and
+ # `save_config_partial` only clears the pin when told the model
+ # changed, not merely because `embedder` was passed (#2627).
+ save_config_partial(repo_path, embedder=embedder_name, embedding_model=None)
elapsed = time.monotonic() - start
console.print(
diff --git a/packages/cli/src/repowise/cli/helpers.py b/packages/cli/src/repowise/cli/helpers.py
index 86e3bf93a..69636a21d 100644
--- a/packages/cli/src/repowise/cli/helpers.py
+++ b/packages/cli/src/repowise/cli/helpers.py
@@ -897,6 +897,11 @@ def save_config(
existing["embedder"] = embedder
if embedding_model:
existing["embedding_model"] = embedding_model
+ else:
+ # No model was resolved this run: dropping the key beats leaving a
+ # stale one that names a different provider's model, or one this
+ # embedder was not actually built with (#2627).
+ existing.pop("embedding_model", None)
if exclude_patterns is not None:
existing["exclude_patterns"] = exclude_patterns
if commit_limit is not None:
@@ -938,8 +943,19 @@ def save_config_partial(
keyword arguments. ``None`` values are skipped so callers can forward
optional flags without clobbering existing keys.
- No scalar-only fallback like :func:`save_config`: it would silently drop
- ``exclude_patterns``, and PyYAML is a hard dependency anyway.
+ ``embedding_model`` is the one exception to "None is skipped": passed
+ explicitly as ``None``, it clears any pinned model instead of leaving it
+ alone, because that is the caller saying the model changed (or is no
+ longer known) for whatever embedder this call names. Merely *omitting*
+ ``embedding_model`` is not the same claim, so it does not clear anything
+ on its own -- ``reindex_cmd`` calls this after every reindex with only
+ ``embedder=``, having never had a model to pass, and a bare ``in extra``
+ check on ``embedder`` used to read that silence as "no model" and wipe a
+ real pin on every routine reindex (#2627, caught in review on the fix
+ itself). Distinguishing "not passed" from "passed as ``None``" needs the
+ raw ``extra`` dict, since a keyword default cannot do it: ``in extra``
+ only reports that once, but ``get`` cannot tell the two shapes apart
+ afterwards.
"""
import yaml # type: ignore[import-untyped]
@@ -949,13 +965,16 @@ def save_config_partial(
if commit_limit is not None:
updates["commit_limit"] = commit_limit
updates.update({k: v for k, v in extra.items() if v is not None})
- if not updates:
+ clear_embedding_model = "embedding_model" in extra and extra["embedding_model"] is None
+ if not updates and not clear_embedding_model:
return
ensure_repowise_dir(repo_path)
config_path = get_repowise_dir(repo_path) / CONFIG_FILENAME
existing = load_config(repo_path)
existing.update(updates)
+ if clear_embedding_model:
+ existing.pop("embedding_model", None)
config_path.write_text(
yaml.dump(existing, default_flow_style=False, sort_keys=False),
diff --git a/tests/unit/cli/test_helpers.py b/tests/unit/cli/test_helpers.py
index 5e26c7aed..23e760a94 100644
--- a/tests/unit/cli/test_helpers.py
+++ b/tests/unit/cli/test_helpers.py
@@ -3,6 +3,7 @@
from __future__ import annotations
import asyncio
+import os
from pathlib import Path
from typing import Any
@@ -297,6 +298,95 @@ class TestSaveConfigPartial:
assert cfg["embedder"] == "minilm"
+class TestStaleEmbeddingModelIsNotCarriedOver:
+ """A re-init that resolves no model must not keep a previous one (#2627)."""
+
+ def test_save_config_drops_a_stale_pin_on_the_new_embedder(self, tmp_path):
+ from repowise.cli.helpers import load_config, save_config
+
+ save_config(
+ tmp_path,
+ "openai",
+ "gpt-5",
+ "openai",
+ embedding_model="text-embedding-3-large",
+ save_key=False,
+ )
+ save_config(
+ tmp_path, "gemini", "gemini-2.5-flash", "gemini", embedding_model=None, save_key=False
+ )
+
+ cfg = load_config(tmp_path)
+ assert cfg["embedder"] == "gemini"
+ assert "embedding_model" not in cfg
+
+ def test_save_config_partial_drops_a_stale_pin_on_the_new_embedder(self, tmp_path):
+ from repowise.cli.helpers import load_config, save_config_partial
+
+ rw_dir = tmp_path / ".repowise"
+ rw_dir.mkdir()
+ (rw_dir / "config.yaml").write_text(
+ "embedder: openai\nembedding_model: text-embedding-3-large\n", encoding="utf-8"
+ )
+
+ save_config_partial(tmp_path, embedder="gemini", embedding_model=None)
+
+ cfg = load_config(tmp_path)
+ assert cfg["embedder"] == "gemini"
+ assert "embedding_model" not in cfg
+
+ def test_serve_does_not_export_the_dropped_pin(self, tmp_path, monkeypatch):
+ from repowise.cli.commands import serve_cmd
+ from repowise.cli.helpers import save_config
+
+ save_config(
+ tmp_path,
+ "openai",
+ "gpt-5",
+ "openai",
+ embedding_model="text-embedding-3-large",
+ save_key=False,
+ )
+ save_config(
+ tmp_path, "gemini", "gemini-2.5-flash", "gemini", embedding_model=None, save_key=False
+ )
+
+ monkeypatch.chdir(tmp_path)
+ # _load_local_provider_config only sets these when unset, and it writes
+ # straight to os.environ, which monkeypatch cannot undo unless it made
+ # the write itself. Pre-set the ones this test does not care about so
+ # the function leaves them alone, and only clear the one under test.
+ monkeypatch.setenv("REPOWISE_PROVIDER", "unrelated")
+ monkeypatch.setenv("REPOWISE_MODEL", "unrelated")
+ monkeypatch.setenv("REPOWISE_EMBEDDER", "unrelated")
+ monkeypatch.delenv("REPOWISE_EMBEDDING_MODEL", raising=False)
+ serve_cmd._load_local_provider_config()
+
+ assert os.environ.get("REPOWISE_EMBEDDING_MODEL") is None
+
+ def test_embedder_alone_does_not_clear_a_pin_it_was_never_told_changed(self, tmp_path):
+ """Regression from review on #2654: reindex passes only ``embedder=`` every run.
+
+ The first cut of the fix cleared the pin whenever ``embedder`` was
+ passed without ``embedding_model``, which reads reindex's silence
+ (it has never had a model to pass) as "the model is gone" and wiped a
+ real pin on every routine reindex. Clearing now needs an explicit
+ ``embedding_model=None``, not merely the absence of the keyword.
+ """
+ from repowise.cli.helpers import load_config, save_config_partial
+
+ rw_dir = tmp_path / ".repowise"
+ rw_dir.mkdir()
+ (rw_dir / "config.yaml").write_text(
+ "embedder: openai\nembedding_model: text-embedding-3-large\n", encoding="utf-8"
+ )
+
+ save_config_partial(tmp_path, embedder="openai")
+
+ cfg = load_config(tmp_path)
+ assert cfg["embedding_model"] == "text-embedding-3-large"
+
+
class TestConfigFingerprint:
def test_config_fingerprint_detects_change(self, tmp_path):
"""config_fingerprint returns a stable hash that changes with config."""