Commit 53b2252
Implement full 4-layer high selectivity handling
Add complete 4-layer defense against high selectivity scenarios:
Layer 1: Exploration Queue (already implemented in multihop_search.rs)
- Uses RejectAndNeedExpand to enable continued graph traversal
Layer 2: Match Rate Detection
- Automatically detects high selectivity after 30 samples
- If match rate < 2%, enables exploration mode (RejectAndNeedExpand)
- Caches result using compare-and-swap for thread safety
Layer 3: Checkpoint-Based Timeout
- Checks timeout every 1000 visits instead of every visit
- Reduces syscall overhead from Instant::now() by ~99%
Layer 4: Two-Tier Early Stop
- Soft timeout (default 10ms): triggers when elapsed > soft AND matched >= min_matched_count
- Hard timeout (default 100ms): unconditional termination to bound worst-case latency
Added comprehensive tests for all 4 layers:
- Match rate detection (low/high match rate scenarios)
- Checkpoint interval behavior
- Hard early stop
- Soft early stop with/without enough matches
- Timeout clamping (soft <= hard)
- Default constants verification
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>1 parent 7c4f3f8 commit 53b2252
1 file changed
Lines changed: 556 additions & 11 deletions
0 commit comments