stock-bot/docs/development/backlog/tasks/F06.md

4.5 KiB

F06 — Implement deterministic replay once, with linear historical traversal

Parent epic: E2. Priority/severity: P0 / Critical. Relative complexity: M. Recommended specialization: Rust deterministic replay.

Scheduling source of truth: manifest entry F06. No task is authorized until the plan is approved. Dependencies and decision references below describe the design; the manifest controls current readiness.

Evidence and root cause

Intended behavior and implementation scope

Implement the replay cursor once: sorted immutable events with stable availability/phase/instrument/sequence ordering; add a small pending-event queue only where required. Absorb P02's nonquadratic load and disabled-by-default hot-loop trade logging. Generate open-only execution events from one designated execution series; feature-only frames do not add liquidity or undeclared decision triggers. Publish completed observations, evaluate declared decision barriers, then next-interval opens under recorded zero/nonzero latency policy.

Exclusions

No unrelated refactor, new service, broker enablement, or silent reinterpretation of historical results.

Likely files and ownership

  • apps/stock/engine/src/backtest/engine.rs
  • apps/stock/engine/src/backtest/mod.rs
  • apps/stock/engine/src/financial/replay.rs (new)

Write locks: rust-replay. One agent owns this change. Lock names do not override actual overlapping files.

Dependencies and blockers

Implementation requires F05, D01, P01 integrated.

Architecture decisions: ADR-003. Agents may not independently amend their policies.

Parallel eligibility: only with disjoint actual files and reserved write locks; read FIRST-WAVE.md for the initial exact ownership boundaries.

Acceptance criteria

  • Permuting file arrival order does not change economic results after canonical event ordering.
  • Daily observations remain unavailable before session close; different symbols retain their actual quote timestamps.
  • Multi-timeframe context includes only completed available bars and marks missing/stale inputs explicitly.

Mandatory tests

  • adjacent_open_zero_latency, positive_latency_skips_open, future_ohlcv_does_not_change_open_fill, daily_close_target_survives_to_open.
  • feature_timeframe_does_not_duplicate_liquidity, equal_timestamp_symbol_permutation, warmup_cannot_trade, stale_mark_timestamp_preserved.
  • Replay/restore trace equality. Extend P01 with1k/10k/100k release-build load/replay scaling; preserve economics before accepting faster runs.

Apply relevant quality gates. Report exact commands/results and unavailable checks; named new cases are requirements, not claims of existing passing tests.

Regression risks and rollback

Financial or compatibility regression; preserve existing fixtures and version changed semantics. Keep migrations additive and previous results readable. Do not add a switch that restores a correctness defect. Versioned cutover/migration is required only when persisted contracts or active engines change; never silently fall back to old economics.

Handoff

Report scope changes (if any), fixture expectations, API/schema changes, measurements, remaining limitations and commit/PR references once authorized. Request independent review; only the integration/planning owner may mark the manifest done.