Summary
stage_tournament() in mts/src/mts/loop/stages.py mixes evaluation, retry policy, gate selection, prompt rewriting, persistence, and event emission in one control-heavy function. The current structure is harder to test, harder to optimize, and harder to modify safely.
Scope
- Split
stage_tournament() into focused components/helpers such as:
- tournament evaluator/runner
- retry strategy
- gate decision resolver
- recovery/event recorder
- Reduce broad
except Exception blocks by isolating failure boundaries
- Preserve current semantics for rapid mode, trend-aware gate, retry learning, and replay generation
- Add targeted tests around the extracted pieces instead of only end-to-end stage behavior
Acceptance Criteria
stage_tournament() becomes materially smaller and mostly orchestration-only
- retry logic, gate resolution, and persistence/event side effects are separated into testable units
- rapid mode and standard mode behavior remain unchanged
- regression tests cover retry and gate behavior after refactor
Files
mts/src/mts/loop/stages.py
- related generation pipeline tests under
mts/tests/
Summary
stage_tournament()inmts/src/mts/loop/stages.pymixes evaluation, retry policy, gate selection, prompt rewriting, persistence, and event emission in one control-heavy function. The current structure is harder to test, harder to optimize, and harder to modify safely.Scope
stage_tournament()into focused components/helpers such as:except Exceptionblocks by isolating failure boundariesAcceptance Criteria
stage_tournament()becomes materially smaller and mostly orchestration-onlyFiles
mts/src/mts/loop/stages.pymts/tests/