fix(rag): surface embedding provider init failure as 'error' status
The bug: when the local embedding provider fails to initialize (e.g. sentence-transformers not installed), RAGEngine.__init__ leaves self.embedding_provider = None (initialized at line 93 but never overwritten by the failing LocalEmbeddingProvider ctor). The constructor returns. _sync_rag_engine's else branch then sets status to 'ready' - a lie. The RAG panel shows 'ready'. The user triggers a retrieval. The engine either has a broken embedding provider (None) or the retrieval fails silently. The RAG context never appears in the AI's history. The fix: in _sync_rag_engine's _task, after RAGEngine(...) returns, check if engine.embedding_provider is None. If so, set status to 'error: RAG embedding provider failed to initialize' and return early. This prevents: - The engine from being assigned to self.rag_engine - The rebuild being triggered - The status being set to 'ready' / 'indexing' Note: this does NOT make the RAG test pass. The test requires the sentence-transformers package which isn't installed in this env. The fix makes the failure reliable (not flaky) and surfaces the right error message. TDD: 3 tests added in tests/test_rag_engine_ready_status_bug.py: - RAGEngine ctor raises ImportError on missing sentence-transformers - _sync_rag_engine sets status to 'error' (not 'ready') on init failure - RAGEngine ctor leaves embedding_provider=None when init fails All 3 pass. The RAG batch test now fails reliably at line 46 with the clear error message.
This commit is contained in:
@@ -1466,6 +1466,14 @@ class AppController:
|
||||
try:
|
||||
from src import rag_engine
|
||||
engine = rag_engine.RAGEngine(self.rag_config, self.active_project_root)
|
||||
# If the engine's embedding provider failed to initialize
|
||||
# (e.g. local embedding but sentence-transformers not installed),
|
||||
# the engine is in a broken state even though __init__ returned.
|
||||
# Surface this as an error instead of reporting 'ready' (which
|
||||
# would let the user trigger RAG queries that silently fail).
|
||||
if engine.embedding_provider is None:
|
||||
self._set_rag_status("error: RAG embedding provider failed to initialize (e.g. missing dependencies)")
|
||||
return
|
||||
with self._rag_engine_lock:
|
||||
self.rag_engine = engine
|
||||
# If the engine is empty and we have files, trigger indexing
|
||||
|
||||
Reference in New Issue
Block a user