Repository navigation
fix(mcp): surface embedder init failure instead of silent mock fallback - #324
Merged
Merged
Conversation
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.
swati510
approved these changes
May 30, 2026
3 of 5 tasks
This was referenced Aug 21, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes #306. When an embedder is explicitly configured (
REPOWISE_EMBEDDERor.repowise/config.yaml) but its initialization fails at runtime — most commonly a missing API key — the MCP server swallowed the exception, fell back toMockEmbedderwith a singleWARNING, 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 thegeminiandopenaibranches, so an explicitembedder: openrouter— or any embedder registered viaregister_embedder— was silently treated asmockwith 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:
_state._embedder_status,_metaenvelope viabuild_meta()asembedder: "mock",embedder_degraded: true, and a human-readableembedder_warning— so an agent can detect the misconfiguration programmatically.MockEmbedderis still returned so non-RAG tools keep working. An unconfigured embedder (or an explicitmock) 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.pycovering: 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.yamlis read; andbuild_metasurfaces the signal only when degraded. Full MCP + server unit suites pass (281 + 51 green); ruff clean.