# Detection Engine Hardening Plan ## Objectives Ensure the detection pipeline produces actionable opportunities with production-grade heuristics and hands them off to the execution stack automatically. Current implementation primarily logs opportunities and uses simplified scoring parameters. ## Action Items 1. **Opportunity Scoring & Filtering** - [ ] Define canonical scoring function (profitability, confidence, liquidity, latency) aligned with business thresholds. - [ ] Replace ad-hoc ROI/price-impact checks with configurable policies (pull from config/env). - [ ] Add regression tests covering borderline cases (low confidence, high slippage, gas-constrained opportunities). 2. **Execution Handoff** - [x] Implement direct handoff to `ArbitrageExecutor` via callback (see `SetOpportunityHandler`). - [ ] Ensure backpressure handling (bounded queue, metrics when saturated). - [ ] Introduce retry/backoff for transient execution failures. 3. **Concurrency & Worker Pools** - [ ] Review `WorkerPool` sizing, ensure graceful shutdown and error propagation. - [ ] Add instrumentation (metrics/logs) for scan time, queue depth, dropped opportunities. 4. **Historical Validation** - [ ] Replay recorded blocks/datasets to validate hit rate and false positives. - [ ] Store misclassified opportunities for manual review. 5. **Configuration & Docs** - [ ] Centralise detection thresholds in config files (`config/*.yaml`) and document in `docs/5_development/CONFIGURATION.md`. - [ ] Update runbooks to describe detection tuning knobs and alerting thresholds. ## References - `pkg/arbitrage/detection_engine.go` - `pkg/arbitrage/service.go` (execution integration) - `pkg/metrics` for instrumentation