4d2a6666a4
The RAG engine's search() returns List[RAGChunk] (dataclass instances),
but _rag_search_result's return type is Result[list[Metadata]] (a list
of dicts). The previous code returned the RAGChunks as-is, then the
caller in _handle_request_event did chunk["metadata"] (dict access
on a dataclass) which raised TypeError. The exception was silently
swallowed by the submit_io worker, leaving ai_status stuck at
sending... for the full 50-second test poll before failing.
Two surgical changes:
1. _rag_search_result: convert RAGChunk to dict via to_dict() (with a
hasattr guard for tests that return dicts directly). Matches the
function's documented return type.
2. _handle_request_event: use isinstance guards + dict.get() on the
chunk fields. Defensive against the type mismatch and matches the
dict contract.
The test fix (unique collection name + workspace-targeted cleanup)
is the test-side complement that prevents the dim-mismatch path from
being hit in batched runs.
Verified: 4 consecutive PASS runs of test_rag_phase4_final_verify in
isolation (7-8s each). 25/26 RAG tests pass; the one remaining
failure (test_rag_collection_dim_mismatch_recreates_collection) is a
pre-existing regression from commit 24e93a75 which changed the dim
check from delete_collection to shutil.rmtree without updating the
test mock setup. Out of scope for this fix.