Private
Public Access
0
0

fix(rag): add CWD fallback in index_file for path-resolution resilience

RAGEngine.index_file silently returns when the joined base_dir+file_path
doesn't exist. This caused the RAG batch test to fail with 0 indexed
documents when the live_gui subprocess's active_project_root resolved
to a parent dir (e.g. tests/artifacts/) instead of the workspace
(tests/artifacts/live_gui_workspace/).

The fix: if the primary path doesn't exist, try CWD+file_path. The
base_dir takes priority; CWD is a safety net for relative-path
resolution across the spawn CWD boundary.

This is a defensive fix at the rag_engine layer. It does NOT fix the
underlying path-leakage issue in tests/conftest.py (hardcoded
Path('tests/artifacts/live_gui_workspace')) which needs a proper
fixture refactor. The RAG test still fails in batch due to that
deeper issue, documented in docs/reports/rag_test_batch_failure_status_20260609_pm3.md.

Behavior:
- base_dir+file_path exists: indexed from base_dir (unchanged)
- base_dir+file_path missing, CWD+file_path exists: indexed from CWD (new)
- Both missing: silently returns (unchanged)

Verified: tests/test_rag_index_file_path_fallback.py (3 tests, all pass)
- test_index_file_finds_file_via_cwd_fallback
- test_index_file_uses_base_dir_first
- test_index_file_silently_returns_when_no_match

Note: test file was removed before commit because it was being
abandoned along with the broader path-hygiene refactor. The fix
itself is preserved in src/rag_engine.py.
This commit is contained in:
2026-06-09 12:31:21 -04:00
parent b801b11c3b
commit eb8357ec0e
2 changed files with 229 additions and 1 deletions
+10 -1
View File
@@ -223,7 +223,16 @@ class RAGEngine:
full_path = os.path.join(self.base_dir, file_path)
if not os.path.exists(full_path):
return
# CWD fallback: handle the case where base_dir was resolved to a
# parent directory (e.g. live_gui subprocess path resolution under
# batch test conditions) but the file is in the subprocess's CWD.
# The base_dir takes priority; this is a safety net for relative
# path resolution across the spawn CWD boundary.
cwd_path = os.path.join(os.getcwd(), file_path)
if os.path.exists(cwd_path):
full_path = cwd_path
else:
return
try:
mtime = os.path.getmtime(full_path)