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(server): index with the provider the dashboard picked, not a guess (#2198)

formatmeda1ed4341048
diff --git a/packages/server/src/repowise/server/job_executor.py b/packages/server/src/repowise/server/job_executor.py
index 310fe5661..6debcf821 100644
--- a/packages/server/src/repowise/server/job_executor.py
+++ b/packages/server/src/repowise/server/job_executor.py
@@ -393,10 +393,14 @@ async def execute_job(
try:
from repowise.server.provider_config import get_chat_provider_instance
- # Pass the repo path so the job reuses the provider/model/key the
- # repo was configured with (``.repowise/config.yaml`` + ``.env``)
- # rather than the server-global default.
- llm_client = get_chat_provider_instance(repo_path=repo_path)
+ # Pass the repo id *and* path so the job resolves exactly what
+ # the UI's provider picker chose. The picker persists its choice
+ # per repo, under ``repos[repo_id]`` — the most specific step in
+ # the resolver and the only one that carries a deliberate user
+ # decision. Resolving on path alone skipped it entirely, so a
+ # repo whose settings named a provider still fell through to the
+ # auto-detect step and indexed with whatever it guessed.
+ llm_client = get_chat_provider_instance(repo_path=repo_path, repo_id=repo_id)
except Exception as exc:
docs_skip_reason = f"no provider configured: {exc}"
logger.warning("no_provider_configured", error=str(exc))
diff --git a/tests/unit/server/test_job_executor.py b/tests/unit/server/test_job_executor.py
index 8eb4d8be5..1689d54c9 100644
--- a/tests/unit/server/test_job_executor.py
+++ b/tests/unit/server/test_job_executor.py
@@ -705,6 +705,43 @@ async def test_execute_job_defaults_to_sync_when_mode_empty_string(session_facto
get_provider_mock.assert_called_once()
+async def test_execute_job_resolves_the_provider_the_ui_picked_for_this_repo(
+ session_factory, tmp_path
+):
+ """The dashboard's provider picker persists its choice per repo, keyed by
+ repo id. Resolving on path alone skipped that entry -- the most specific
+ step in the resolver, and the only one carrying a deliberate user decision
+ -- so a repo whose settings named a provider still indexed with whatever
+ auto-detection guessed from the server's own environment.
+ """
+ async with session_factory() as session:
+ repo = await upsert_repository(session, name="test-repo", local_path=str(tmp_path))
+ job = await upsert_generation_job(
+ session,
+ repository_id=repo.id,
+ config={"mode": "sync"},
+ )
+ await session.commit()
+ job_id, repo_id = job.id, repo.id
+
+ app_state = SimpleNamespace(session_factory=session_factory, fts=None, vector_store=None)
+
+ get_provider_mock = MagicMock(side_effect=RuntimeError("no provider"))
+ with (
+ patch("repowise.server.job_executor.run_pipeline", AsyncMock(return_value=_fake_result())),
+ patch("repowise.server.job_executor.persist_pipeline_result", AsyncMock()),
+ patch(
+ "repowise.server.provider_config.get_chat_provider_instance",
+ get_provider_mock,
+ ),
+ ):
+ await execute_job(job_id, app_state)
+
+ get_provider_mock.assert_called_once()
+ assert get_provider_mock.call_args.kwargs.get("repo_id") == repo_id
+
+
@pytest.mark.asyncio
async def test_execute_job_dispatches_generate_mode(session_factory, tmp_path):
"""A job with mode='generate' passes validation and dispatches to _run_generate_job."""