Commit a583e32
fix: hybrid retrieval graceful degradation with Promise.allSettled (#581)
* fix: hybrid retrieval graceful degradation with Promise.allSettled
Replace Promise.all with Promise.allSettled in hybridRetrieval() so that
if either vector or BM25 search throws, the other search's results are
still used instead of failing the entire query.
Behavior:
- One search fails → other search results returned, failed side logged
- Both fail → throws with failureStage=hybrid.parallelSearch
- Diagnostics correctly reflect 0 for failed search counts
Fixes Bug 3 from community code audit.
* Fix both-backend-fail guard: check rejection status, not array length
Resolves reviewer rwmjhb's F1 and MR1 feedback:
**F1: Fix both-fail guard**
- Changed from checking `results.length === 0` to checking
`settledResults.status === "rejected"` for both backends
- Empty result sets are now correctly distinguished from failures
- Error message enriched with rejection reasons for debugging
**MR1: Update existing tests + add new test coverage**
- Updated 2 existing tests in query-expander.test.mjs to reflect
graceful-degradation behavior (no longer throws on partial failures)
- Added new test file: retriever-graceful-degradation.test.mjs
with 7 comprehensive tests covering:
- Both backends fail → throws error
- One fails, one succeeds → uses successful backend results
- Both succeed with empty results → returns empty array
- Empty results vs. both-fail distinction
**SE-approved implementation** (3 conditions verified):
1. Fallback behavior confirmed: fuseResults() handles partial failures
2. Type safety: Promise.allSettled pattern maintained
3. Error enrichment: rejection reasons included in error message
All 20 tests passing (7 new + 13 existing).
---------
Co-authored-by: Charon <charon@openclaw.ai>1 parent 619d703 commit a583e32
File tree
4 files changed
+405
-33
lines changed- src
- test
4 files changed
+405
-33
lines changedSome generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
920 | 920 | | |
921 | 921 | | |
922 | 922 | | |
923 | | - | |
| 923 | + | |
924 | 924 | | |
925 | 925 | | |
926 | 926 | | |
927 | 927 | | |
928 | 928 | | |
929 | | - | |
930 | | - | |
931 | | - | |
| 929 | + | |
932 | 930 | | |
933 | 931 | | |
934 | 932 | | |
935 | 933 | | |
936 | 934 | | |
937 | | - | |
938 | | - | |
939 | | - | |
| 935 | + | |
940 | 936 | | |
| 937 | + | |
| 938 | + | |
| 939 | + | |
| 940 | + | |
| 941 | + | |
| 942 | + | |
| 943 | + | |
| 944 | + | |
| 945 | + | |
| 946 | + | |
| 947 | + | |
| 948 | + | |
| 949 | + | |
| 950 | + | |
| 951 | + | |
| 952 | + | |
| 953 | + | |
| 954 | + | |
| 955 | + | |
| 956 | + | |
| 957 | + | |
| 958 | + | |
| 959 | + | |
| 960 | + | |
| 961 | + | |
| 962 | + | |
| 963 | + | |
| 964 | + | |
| 965 | + | |
| 966 | + | |
| 967 | + | |
| 968 | + | |
| 969 | + | |
| 970 | + | |
| 971 | + | |
| 972 | + | |
941 | 973 | | |
942 | 974 | | |
943 | 975 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
255 | 255 | | |
256 | 256 | | |
257 | 257 | | |
258 | | - | |
| 258 | + | |
259 | 259 | | |
260 | 260 | | |
261 | 261 | | |
| |||
264 | 264 | | |
265 | 265 | | |
266 | 266 | | |
267 | | - | |
268 | | - | |
269 | | - | |
270 | | - | |
271 | | - | |
272 | | - | |
273 | | - | |
274 | | - | |
| 267 | + | |
| 268 | + | |
| 269 | + | |
| 270 | + | |
| 271 | + | |
| 272 | + | |
| 273 | + | |
| 274 | + | |
| 275 | + | |
| 276 | + | |
275 | 277 | | |
| 278 | + | |
276 | 279 | | |
277 | 280 | | |
278 | | - | |
| 281 | + | |
279 | 282 | | |
| 283 | + | |
280 | 284 | | |
281 | | - | |
282 | | - | |
| 285 | + | |
| 286 | + | |
| 287 | + | |
| 288 | + | |
| 289 | + | |
| 290 | + | |
283 | 291 | | |
284 | 292 | | |
285 | 293 | | |
286 | 294 | | |
287 | | - | |
| 295 | + | |
288 | 296 | | |
289 | 297 | | |
290 | | - | |
| 298 | + | |
| 299 | + | |
291 | 300 | | |
292 | 301 | | |
293 | 302 | | |
294 | 303 | | |
295 | 304 | | |
296 | | - | |
297 | | - | |
298 | | - | |
299 | | - | |
300 | | - | |
301 | | - | |
302 | | - | |
303 | | - | |
| 305 | + | |
| 306 | + | |
| 307 | + | |
| 308 | + | |
| 309 | + | |
| 310 | + | |
304 | 311 | | |
| 312 | + | |
| 313 | + | |
| 314 | + | |
| 315 | + | |
| 316 | + | |
| 317 | + | |
305 | 318 | | |
306 | 319 | | |
307 | | - | |
| 320 | + | |
| 321 | + | |
| 322 | + | |
| 323 | + | |
| 324 | + | |
| 325 | + | |
308 | 326 | | |
| 327 | + | |
309 | 328 | | |
310 | | - | |
311 | | - | |
| 329 | + | |
| 330 | + | |
312 | 331 | | |
313 | 332 | | |
314 | 333 | | |
| |||
0 commit comments