58 lines
4.5 KiB
Markdown
58 lines
4.5 KiB
Markdown
# 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](../manifest.json). 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
|
|
|
|
- **FIN-01 — Verified:** Both execution paths can act on a completed bar and fill against its current close; this is not a defensible default bar-close policy. [apps/stock/engine/src/backtest/engine.rs:249](../../../../apps/stock/engine/src/backtest/engine.rs#L249); [apps/stock/orchestrator/src/services/ExecutionService.ts:224](../../../../apps/stock/orchestrator/src/services/ExecutionService.ts#L224).
|
|
- **DAT-01 — Verified:** Dataset v1 has one bar timestamp and interval in the manifest, without explicit bar-end/availability semantics. Session dates cannot safely be treated as observation times. [libs/core/types/src/historical-data.ts:90](../../../../libs/core/types/src/historical-data.ts#L90); [apps/stock/orchestrator/src/services/StorageService.ts:177](../../../../apps/stock/orchestrator/src/services/StorageService.ts#L177).
|
|
- **PER-01 — Verified:** EventQueue insertion scans prior events; native run is synchronous/one-shot and returns full JSON. Actual end-to-end bottleneck distribution still needs controlled measurements. [apps/stock/engine/src/backtest/mod.rs:138](../../../../apps/stock/engine/src/backtest/mod.rs#L138); [apps/stock/engine/src/api/backtest.rs:194](../../../../apps/stock/engine/src/api/backtest.rs#L194).
|
|
|
|
## 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](F05.md), [D01](D01.md), [P01](P01.md) 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](../../QUALITY-GATES.md). 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.
|