feat(engine): add deterministic historical replay

This commit is contained in:
Boki 2026-10-22 23:34:35 -04:00
parent ccf333cc0a
commit 417a7bd21e
10 changed files with 2055 additions and 28 deletions

View file

@ -1,13 +1,13 @@
{
"schema_version": 1,
"plan_revision": "2026-10-22.21",
"plan_revision": "2026-10-22.23",
"repository_base": "b7aeca4",
"plan_status": "ninth_wave_validated_uncommitted",
"plan_status": "tenth_wave_validated_uncommitted",
"execution_authorized": true,
"execution_scope": {
"authorized_by": "User: do it (2026-10-22), authorizing the explicitly proposed F05 continuation on accepted integrated F04; no commit requested",
"authorized_by": "User: commit all and do it (2026-10-22), authorizing the F04/F05 commit and proposed F06 continuation",
"tasks": [
"F05"
"F06"
],
"permissions": [
"isolated_implementation",
@ -16,7 +16,7 @@
"planning_progress_updates"
],
"excluded": [
"commits_without_further_approval",
"new_wave_commits_without_further_approval",
"push",
"pull_requests",
"live_or_paper_operations",
@ -437,7 +437,7 @@
"epic": "E2",
"priority": "P0",
"severity": "Critical",
"status": "review",
"status": "done",
"dependencies": [
"F02"
],
@ -460,7 +460,7 @@
"assignment": "/root/wave8_f04",
"branch": "wave8/f04-financial-risk",
"pull_request": null,
"completed_commit": null,
"completed_commit": "ccf333cc0ae9bcf1cc81ff6cc50099686738def2",
"blocker": null,
"release_gates": [],
"worktree": "/tmp/stock-bot-wave8.pKzr7p/f04",
@ -468,14 +468,14 @@
"concrete_write_scope": [
"apps/stock/engine/src/financial/"
],
"integration_state": "validated_uncommitted",
"integration_state": "validated_committed",
"reviewed_by": [
"/root/wave8_risk_review",
"/root/wave8_quant_review"
],
"review_notes": "Both independent reviewers and combined gates passed; owner accepted continuation to F05. Integrated F04 remains uncommitted, with frozen source hashes recorded in eighth_wave_validation.",
"review_notes": "Both independent reviewers and combined gates passed; owner accepted continuation to F05. Integrated F04 remains uncommitted, with frozen source hashes recorded in eighth_wave_validation. Subsequently committed at owner request as ccf333c.",
"verification_reference": "ROADMAP.md#eighth-wave-handoff--2026-10-22",
"accepted_by": "Owner: do it, authorizing proposed F05 continuation on validated integrated F04 (2026-10-22)"
"accepted_by": "Owner: commit all and do it (2026-10-22), accepting F04/F05 and authorizing F06"
},
{
"id": "F05",
@ -483,7 +483,7 @@
"epic": "E2",
"priority": "P0",
"severity": "Critical",
"status": "review",
"status": "done",
"dependencies": [
"F04"
],
@ -507,7 +507,7 @@
"assignment": "/root/wave9_f05",
"branch": "wave9/f05-matching",
"pull_request": null,
"completed_commit": null,
"completed_commit": "ccf333cc0ae9bcf1cc81ff6cc50099686738def2",
"blocker": null,
"release_gates": [
"F06"
@ -523,13 +523,14 @@
"concrete_write_scope": [
"apps/stock/engine/src/financial/"
],
"integration_state": "validated_uncommitted",
"review_notes": "Both independent reviewers accepted the final frozen source; root integrated matching hashes and passed all repository checks plus the release matching measurement. No active runtime cutover; F06 remains the replay release gate.",
"integration_state": "validated_committed",
"review_notes": "Both independent reviewers accepted the final frozen source; root integrated matching hashes and passed all repository checks plus the release matching measurement. No active runtime cutover; F06 remains the replay release gate. Subsequently committed at owner request as ccf333c.",
"reviewed_by": [
"/root/wave9_execution_review",
"/root/wave9_quant_review"
],
"verification_reference": "ROADMAP.md#ninth-wave-handoff--2026-10-22"
"verification_reference": "ROADMAP.md#ninth-wave-handoff--2026-10-22",
"accepted_by": "Owner: commit all and do it (2026-10-22), accepting F04/F05 and authorizing F06"
},
{
"id": "F06",
@ -537,7 +538,7 @@
"epic": "E2",
"priority": "P0",
"severity": "Critical",
"status": "blocked",
"status": "review",
"dependencies": [
"F05",
"D01",
@ -558,12 +559,26 @@
"rust-replay"
],
"parallel_policy": "Allowed only with satisfied dependencies/approvals and disjoint write locks AND actual files; see agents/integration.md.",
"assignment": null,
"branch": null,
"assignment": "/root/wave10_f06",
"branch": "wave10/f06-replay",
"pull_request": null,
"completed_commit": null,
"blocker": null,
"release_gates": []
"release_gates": [],
"worktree": "/tmp/stock-bot-wave10.8uCLfa/f06",
"integration_base": "ccf333cc0ae9bcf1cc81ff6cc50099686738def2",
"concrete_write_scope": [
"apps/stock/engine/src/financial/replay.rs",
"apps/stock/engine/src/financial/replay_tests.rs",
"apps/stock/engine/src/financial/mod.rs"
],
"integration_state": "validated_uncommitted",
"review_notes": "Both independent reviewers accepted exact frozen source; combined repository gates and integrated release replay measurement passed. Internal bar replay only; active simulator/NAPI/SQL unchanged. Material sequential equal-time risk approximation remains the canonical multi-asset default policy gate.",
"reviewed_by": [
"/root/wave10_replay_review",
"/root/wave10_quant_review"
],
"verification_reference": "ROADMAP.md#tenth-wave-handoff--2026-10-22"
},
{
"id": "F07",
@ -3230,5 +3245,122 @@
],
"handoff": "F04/F05 independently reviewed and validated, uncommitted. Next after owner acceptance: F06 availability-aware deterministic replay. No commit, push, PR, other task implementation or trading operation.",
"cleanup": "No services/data removed; isolated worktree and logs retained."
},
"canonical_release_gates": [
{
"id": "multi_asset_mark_policy",
"status": "requires_owner_disposition",
"applies_to": [
"R05"
],
"capability": "Canonical multi-asset research as the default",
"evidence": "F06 sequential_equal_time_marks_can_latch_risk_before_synchronized_barrier: offsetting same-time marks preserve final equity but latch intermediate daily/drawdown halts under F04/F05 per-mark risk.",
"resolution": "Owner must explicitly accept the disclosed versioned sequential-mark approximation or approve a coordinated atomic-mark policy change with independent fixtures before default activation.",
"does_not_block": [
"F06 additive integration",
"F07 internal/native adapter work",
"single-asset component work"
],
"task_reference": "backlog/tasks/R05.md",
"approved_by": null
}
],
"tenth_wave": [
"F06"
],
"tenth_wave_base": "ccf333cc0ae9bcf1cc81ff6cc50099686738def2",
"tenth_wave_notes": [
"Owner authorized committing all existing reviewed F04/F05 work and continuing F06; existing work committed ccf333c. No push, PR or trading operations.",
"One isolated implementation owner, two independent read-only reviewers; root owns planning/integration. Dependencies F05/D01/P01 committed; ADR003 approved.",
"Internal prepared-bar replay only. Frozen D01 adaptation and public NAPI sessions stay F07; TypeScript strategy state/RNG stays S01; metrics F08. No active legacy cutover.",
"Pin true session initialization, late-data mark/volume handling, series tie breaks, shared coordinator barrier revision, terminal failure and half-open trading bounds."
],
"tenth_wave_validation": {
"base": "ccf333cc0ae9bcf1cc81ff6cc50099686738def2",
"integration_state": "validated_uncommitted",
"committed_prerequisites": "Owner requested all existing changes committed, producing ccf333c for F04/F05 plus planning. F06 uses that exact base without overlays.",
"repository_check": {
"command": "CARGO_BUILD_JOBS=2 bun run check",
"log": "/tmp/stock-bot-wave10.8uCLfa/integration-check.log",
"exit_code": 0,
"passed": {
"tooling": 60,
"utils": 43,
"calculations": 35,
"integration": 342,
"rust": 131
},
"rust_manual_benchmarks_ignored": 4,
"other_gates": "Build, typecheck, contracts, lint and secret audit passed."
},
"independent_review": {
"timing": "/root/wave10_replay_review: accepted frozen source; independently ran debug artifact focused25passed/1ignored and full131passed/4ignored, zero failures. Reviewed completed frozen release measurement.",
"quant": "/root/wave10_quant_review: accepted frozen source; focused25passed/1ignored, zero failures; reviewed full-suite log and release measurement. No competing financial authority or future-data exposure through prefix API.",
"debug_artifact": "/tmp/stock-bot-wave10.8uCLfa/f06/target/debug/deps/engine-318becfe365f2c10",
"debug_artifact_sha256": "1e90db0aa3aeb327ac1aeb6985b47f0226c1231077d78b499e969b49b43c688f",
"coordination": "Quant focused Cargo invocation finished without recompilation before direct-binary-only coordination; subsequent timing review executed the frozen test binary. No shared/symlinked native build output between worktrees."
},
"scoped_checks": [
"rustfmt --edition 2021 --check --config skip_children=true on three changed financial files passed.",
"git diff --check; manifest IDs/task/ADR references, acyclic dependencies and authorized prerequisite readiness passed.",
"Integrated source hashes match the three independently reviewed files; base and previously committed financial files remain unchanged."
],
"source_hashes": {
"apps/stock/engine/src/financial/replay.rs": "0c9d466e96549571ae29247528351058f5a91563215f5bed83cfaea0205411cf",
"apps/stock/engine/src/financial/replay_tests.rs": "3e2b150bc142f5361592328f807a5e577732bc515a3d38ca525bed8e52952ee4",
"apps/stock/engine/src/financial/mod.rs": "6c90bd6ec2bd2702f9c9e3a13c226e3578749c83cd2b06dcdb51dd6aceb3bb90"
},
"native_artifact": {
"path": "apps/stock/engine/dist/engine.node",
"sha256": "26c323c45ab947146db71424008406ae37c6603293ed46b8b81cda80c1d2fd95",
"note": "Built from integrated checkout; native API still uses legacy simulator."
},
"measurement": {
"command": "CARGO_BUILD_JOBS=2 cargo test -p engine --lib --release --offline replay_scaling_measurement -- --ignored --nocapture",
"author_log": "/tmp/stock-bot-wave10.8uCLfa/f06-replay-release-frozen.log",
"integrated_log": "/tmp/stock-bot-wave10.8uCLfa/integration-replay-release.log",
"result": "1 passed,0 failed;134 filtered. Author and integrated frozen builds passed18 rows each; earlier ledger/risk/matching manual measurements not repeated.",
"artifact": "target/release/deps/engine-abe56cbc3e15ae30",
"artifact_sha256": "0d20d304471e0f780b72f133ceefb120a5f3f20becb3b5042137efeb46b29f73",
"host": "AMD Ryzen9 9950X3D; Linux6.8 x86_64; Rust/Cargo1.88.0; build jobs2. Author/integrated release artifact hashes match.",
"workload": "1/2assets with1k/10k/100k total execution bars plus1feature/cadence row;3repeats, no explicit warmup. Exactly1decision/buy/fill quantity1@10,fee0.1,initialcapital10000; remaining traversal performs marks/open events. Fixed synthetic10ms bars exercise internal prepared cursor, not D01 interval normalization.",
"timing": "Input generation/cloning excluded. Load includes canonicalization/validation/event sorting/exact binding serialization. Traversal includes fixture decision construction and matcher marks/journals. Checkpoint copy and restore separately timed; restore includes new/load/fixed-trace replay and full checkpoint validation copy. Output serialization excluded.",
"equality": "Expected cash9989.9/equity9999.9 and one accepted fill asserted. Full checkpoint bytes identical across3repeats per fixture; restored checkpoint equal. Ordinary permutation regressions also compare full checkpoints. No cross-platform determinism claim.",
"raw_integrated_rows": [
"replay instruments=1 execution_bars=1000 total_bars=1001 repeat=0 load_us=808 replay_us=10823 checkpoint_us=3512 restore_us=14572 checkpoint_bytes=4204033 fills=1",
"replay instruments=1 execution_bars=1000 total_bars=1001 repeat=1 load_us=662 replay_us=9907 checkpoint_us=1736 restore_us=14115 checkpoint_bytes=4204033 fills=1",
"replay instruments=1 execution_bars=1000 total_bars=1001 repeat=2 load_us=766 replay_us=9337 checkpoint_us=1582 restore_us=12684 checkpoint_bytes=4204033 fills=1",
"replay instruments=1 execution_bars=10000 total_bars=10001 repeat=0 load_us=7004 replay_us=108708 checkpoint_us=37550 restore_us=160897 checkpoint_bytes=42449082 fills=1",
"replay instruments=1 execution_bars=10000 total_bars=10001 repeat=1 load_us=6876 replay_us=101074 checkpoint_us=26523 restore_us=151922 checkpoint_bytes=42449082 fills=1",
"replay instruments=1 execution_bars=10000 total_bars=10001 repeat=2 load_us=7099 replay_us=99939 checkpoint_us=24254 restore_us=149012 checkpoint_bytes=42449082 fills=1",
"replay instruments=1 execution_bars=100000 total_bars=100001 repeat=0 load_us=78537 replay_us=1062133 checkpoint_us=338708 restore_us=1631855 checkpoint_bytes=429579131 fills=1",
"replay instruments=1 execution_bars=100000 total_bars=100001 repeat=1 load_us=77106 replay_us=1113410 checkpoint_us=288906 restore_us=1546489 checkpoint_bytes=429579131 fills=1",
"replay instruments=1 execution_bars=100000 total_bars=100001 repeat=2 load_us=76279 replay_us=1061281 checkpoint_us=277388 restore_us=1556940 checkpoint_bytes=429579131 fills=1",
"replay instruments=2 execution_bars=1000 total_bars=1001 repeat=0 load_us=721 replay_us=8325 checkpoint_us=1334 restore_us=11212 checkpoint_bytes=4200000 fills=1",
"replay instruments=2 execution_bars=1000 total_bars=1001 repeat=1 load_us=697 replay_us=8090 checkpoint_us=1246 restore_us=11194 checkpoint_bytes=4200000 fills=1",
"replay instruments=2 execution_bars=1000 total_bars=1001 repeat=2 load_us=721 replay_us=7795 checkpoint_us=1207 restore_us=10951 checkpoint_bytes=4200000 fills=1",
"replay instruments=2 execution_bars=10000 total_bars=10001 repeat=0 load_us=7768 replay_us=87483 checkpoint_us=25049 restore_us=140364 checkpoint_bytes=42419059 fills=1",
"replay instruments=2 execution_bars=10000 total_bars=10001 repeat=1 load_us=7793 replay_us=87431 checkpoint_us=25305 restore_us=136945 checkpoint_bytes=42419059 fills=1",
"replay instruments=2 execution_bars=10000 total_bars=10001 repeat=2 load_us=7667 replay_us=87640 checkpoint_us=26653 restore_us=138028 checkpoint_bytes=42419059 fills=1",
"replay instruments=2 execution_bars=100000 total_bars=100001 repeat=0 load_us=84055 replay_us=958878 checkpoint_us=286388 restore_us=1422346 checkpoint_bytes=429289118 fills=1",
"replay instruments=2 execution_bars=100000 total_bars=100001 repeat=1 load_us=83135 replay_us=906061 checkpoint_us=275798 restore_us=1394171 checkpoint_bytes=429289118 fills=1",
"replay instruments=2 execution_bars=100000 total_bars=100001 repeat=2 load_us=85020 replay_us=961257 checkpoint_us=278030 restore_us=1421355 checkpoint_bytes=429289118 fills=1"
],
"limits": "One-fill canonical Rust component workload, not order-heavy TS/NAPI, storage, batch or cold-process throughput; no speedup claim. Preparation O(n log n); event traversal linear plus existing matching/risk/map/journal work. Serialized full checkpoint~4.2/42.4/429MB at1k/10k/100k, not RSS. Journals/history retained; no compaction."
},
"not_run": [
"Disposable PostgreSQL/Redis, browser and Python suites: persistence/API/UI/Python boundaries unchanged."
],
"limitations": [
"Trusted prepared bars/session tables, not frozen D01 admission. F07 must verify/adapt dataset hashes, decimals, calendars, execution selection, eligibility and limitations.",
"Quote replay and abutting same-series venue sessions reject. Internal synthetic test intervals are not a new persisted dataset timeframe.",
"Sequential equal-time marks can latch intermediate daily/drawdown halts despite recovered synchronized equity. Explicit regression/model limitation; canonical_release_gates.multi_asset_mark_policy remains unresolved before R05 multi-asset default.",
"Event budgets bound count, not wall time. No mutable matcher access, but host APIs are not untrusted-code security boundaries; F07 must not expose checkpoints/full prepared data to strategies.",
"Checkpoints bind exact canonical input/config content and validate fixed decision replay; not authenticated provenance, arbitrary TS determinism or strategy/RNG recomputation.",
"Event-index-derived IDs can differ when a feature dataset changes; unused-feature tests compare unchanged economic/cadence behavior, not IDs across different bindings.",
"No active simulator, NAPI, SQL/paper or web cutover. Existing build warnings remain."
],
"handoff": "F04/F05 committed ccf333c at owner request. F06 independently reviewed and validated, uncommitted. Next after acceptance: F07 verified dataset/native pull adapter; F08 result projection may follow with coordinated contracts. No push, PR, other task implementation or trading operation.",
"cleanup": "No services/data removed; isolated worktree and logs retained."
}
}