fix(rag): Resolve RAG test failures and race conditions
- Fixed circular import in chromadb by using lazy imports in ag_engine.py. - Moved RAG engine initialization to background threads in AppController to avoid blocking UI. - Added _rag_engine_lock to prevent race conditions during engine re-initialization. - Updated Gemini embedding model to gemini-embedding-001 (available) from ext-embedding-004 (not found). - Fixed _rebuild_rag_index to use fresh ag_engine instance from self in every iteration. - Optimized est_rag_phase4_final_verify.py and est_rag_phase4_stress.py to wait for RAG sync before continuing. - Added dummy embedding fallback in LocalEmbeddingProvider if sentence-transformers fails to load.
This commit is contained in:
@@ -33,30 +33,19 @@ def test_rag_large_codebase_verification_sim(live_gui):
|
||||
client.set_value('rag_emb_provider', 'local')
|
||||
client.set_value('auto_add_history', True)
|
||||
|
||||
# Wait for settings to apply
|
||||
for _ in range(50):
|
||||
if client.get_value('rag_emb_provider') == 'local':
|
||||
break
|
||||
time.sleep(0.1)
|
||||
|
||||
# 3. Trigger Initial Indexing
|
||||
print("[SIM] Triggering initial indexing of 50 files...")
|
||||
start = time.time()
|
||||
client.click('btn_rebuild_rag_index')
|
||||
|
||||
# Wait for ready
|
||||
# Wait for settings to apply and engine to sync (initial indexing happens automatically)
|
||||
print("[SIM] Waiting for automatic initial indexing...")
|
||||
start_initial = time.time()
|
||||
success = False
|
||||
for _ in range(100):
|
||||
status = client.get_value('rag_status')
|
||||
if status == 'ready':
|
||||
if client.get_value('rag_emb_provider') == 'local' and client.get_value('rag_status') == 'ready':
|
||||
success = True
|
||||
break
|
||||
time.sleep(0.5)
|
||||
|
||||
duration_initial = time.time() - start
|
||||
assert success, f"Initial indexing timed out. Final status: {status}"
|
||||
print(f"[SIM] Initial indexing took {duration_initial:.2f}s")
|
||||
|
||||
duration_initial = time.time() - start_initial
|
||||
assert success, f"RAG sync/initial indexing failed. Status: {client.get_value('rag_status')}"
|
||||
print(f"[SIM] Initial indexing (automatic) took {duration_initial:.2f}s")
|
||||
|
||||
# 4. Trigger Incremental Indexing (no changes)
|
||||
print("[SIM] Triggering incremental indexing (no changes)...")
|
||||
start = time.time()
|
||||
@@ -86,6 +75,13 @@ def test_rag_large_codebase_verification_sim(live_gui):
|
||||
# 6. Verify retrieval of modified content
|
||||
client.set_value('current_provider', 'gemini_cli')
|
||||
client.set_value('gcli_path', os.path.abspath(os.path.join(os.path.dirname(__file__), "mock_gcli.bat")))
|
||||
|
||||
# Wait for models to load to avoid status overwrite
|
||||
for _ in range(50):
|
||||
if "models loaded" in client.get_gui_state().get('ai_status', ''):
|
||||
break
|
||||
time.sleep(0.2)
|
||||
|
||||
client.set_value('ai_input', "What is the modified content?")
|
||||
client.click('btn_gen_send')
|
||||
|
||||
@@ -124,13 +120,21 @@ def test_rag_large_codebase_verification_sim(live_gui):
|
||||
# But we can verify by searching for a deleted file's content.
|
||||
client.set_value('ai_input', "What is in file_49.txt?")
|
||||
client.click('btn_gen_send')
|
||||
time.sleep(5)
|
||||
|
||||
session = client.get_session()
|
||||
entries = session.get('session', {}).get('entries', [])
|
||||
# Wait for User entry to appear in history
|
||||
last_user = None
|
||||
for _ in range(50):
|
||||
session = client.get_session()
|
||||
entries = session.get('session', {}).get('entries', [])
|
||||
users = [e for e in entries if e.get('role') == 'User']
|
||||
if users:
|
||||
last_user = users[-1]
|
||||
# Check if this is our latest message
|
||||
if "What is in file_49.txt?" in last_user.get('content', ''):
|
||||
break
|
||||
time.sleep(0.5)
|
||||
|
||||
# Last User message should NOT contain context from file_49
|
||||
last_user = next(e for e in reversed(entries) if e.get('role') == 'User')
|
||||
assert last_user, "Last user message not found"
|
||||
content = last_user.get('content', '')
|
||||
|
||||
# Check if "Source: file_49.txt" exists in the context block
|
||||
|
||||
Reference in New Issue
Block a user