Skip to content

fix(mcp): surface embedder init failure instead of silent mock fallback - #324

Merged
RaghavChamadiya merged 1 commit into
mainfrom
fix/embedder-silent-mock-fallback
May 30, 2026
Merged

RaghavChamadiya merged 1 commit into
mainfrom
fix/embedder-silent-mock-fallback

Conversation

@RaghavChamadiya

Copy link
Copy Markdown
Member

Summary

Fixes #306. When an embedder is explicitly configured (REPOWISE_EMBEDDER or .repowise/config.yaml) but its initialization fails at runtime — most commonly a missing API key — the MCP server swallowed the exception, fell back to MockEmbedder with a single WARNING, then reported ready and listed every tool. Semantic search (search_codebase, get_answer) then ran on 8-dim mock vectors that can't match a real index, returning empty/irrelevant results with no signal to the caller. The degraded server was indistinguishable from a healthy one.

Changes

1. All embedders now work, not just openai/gemini.
_resolve_embedder() previously hardcoded only the gemini and openai branches, so an explicit embedder: openrouter — or any embedder registered via register_embedder — was silently treated as mock with no warning at all. Resolution now goes through the shared embedder registry (get_embedder), so every backend is honoured: openai, gemini, openrouter, and custom embedders. Env-var mapping (REPOWISE_EMBEDDING_MODEL, REPOWISE_EMBEDDING_DIMS) is preserved.

2. Failure is surfaced instead of hidden.
An explicitly-configured embedder that fails to initialise now:

  • logs at ERROR (not WARNING) with the missing key and concrete remediation,
  • records the degradation in _state._embedder_status,
  • is surfaced in every tool's _meta envelope via build_meta() as embedder: "mock", embedder_degraded: true, and a human-readable embedder_warning — so an agent can detect the misconfiguration programmatically.

MockEmbedder is still returned so non-RAG tools keep working. An unconfigured embedder (or an explicit mock) is the intended default and is never flagged as degraded, so healthy responses stay clean.

Example degraded _meta

{
  "timing_ms": 12.4,
  "embedder": "mock",
  "embedder_degraded": true,
  "embedder_warning": "Configured embedder 'openai' failed to initialise (OpenAI API key required...). Semantic search (search_codebase, get_answer) is running on mock vectors and CANNOT match the real index — results will be empty or irrelevant. To fix: set OPENAI_API_KEY in the MCP server's environment (and `pip install openai`), then restart the MCP server."
}

Tests

Added tests/unit/server/mcp/test_embedder_resolution.py covering: no-config/explicit-mock are not degraded; openai/openrouter without a key degrade and name the right env var; unknown names degrade; custom-registered embedders resolve cleanly; config.yaml is read; and build_meta surfaces the signal only when degraded. Full MCP + server unit suites pass (281 + 51 green); ruff clean.

When an embedder is explicitly configured (REPOWISE_EMBEDDER or
.repowise/config.yaml) but fails to initialise at runtime — most often a
missing API key — the MCP server swallowed the exception, fell back to
MockEmbedder with a single WARNING, then reported ready and listed every
tool. Semantic search (search_codebase, get_answer) silently ran on 8-dim
mock vectors that cannot match a real index, returning empty/irrelevant
results with no signal to the caller (#306).

Two fixes:

- Resolve through the shared embedder registry (get_embedder) so every
  backend is honoured — openai, gemini, openrouter, and any custom embedder
  registered via register_embedder. The old code hardcoded only the gemini
  and openai branches, so an explicit `embedder: openrouter` (or any custom
  name) was silently treated as mock with no warning at all.

- Stop pretending to be healthy on failure. An explicitly-configured
  embedder that fails to initialise now logs at ERROR with the missing key
  and remediation, and records the degradation in _state._embedder_status.
  build_meta() surfaces `embedder: "mock"`, `embedder_degraded: true`, and a
  human-readable `embedder_warning` in every tool's _meta envelope so an
  agent can detect the misconfiguration programmatically. MockEmbedder is
  still returned so non-RAG tools keep working; an unconfigured embedder (or
  an explicit `mock`) is the intended default and is never flagged degraded.
@RaghavChamadiya
RaghavChamadiya requested a review from swati510 as a code owner May 30, 2026 13:15
@RaghavChamadiya
RaghavChamadiya merged commit 910d374 into main May 30, 2026
5 checks passed
@RaghavChamadiya
RaghavChamadiya deleted the fix/embedder-silent-mock-fallback branch May 30, 2026 13:18
RaghavChamadiya added a commit that referenced this pull request May 30, 2026
Bump version to 0.15.1 across pyproject, package __init__ files, web
footer, and uv.lock; add changelog entry.

Patch release shipping two fixes:
- mcp: surface embedder init failure instead of silent mock fallback (#324)
- pipeline: drop transient BlameIndex before serialization (#323)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug] Configured embedder silently falls back to MockEmbedder on init failure — broken semantic search looks healthy

2 participants