feat(engine): expose canonical replay sessions through native workers

This commit is contained in:
Boki 2026-10-23 00:54:36 -04:00
parent 417a7bd21e
commit e3635f23cf
26 changed files with 2693 additions and 33 deletions

View file

@ -18,16 +18,30 @@ F06 consumes internal typed prepared bars/session tables, not an independently a
Expose recorded model limitations, including F06's explicitly unsupported abutting venue sessions and F04/F05's sequential equal-time portfolio marks (intermediate valuations can latch risk halts). An event budget bounds event count, not wall time or the cost of an individual matching transition. These are not promises of atomic multi-asset valuation, arbitrary-calendar support or constant-latency cancellation.
## Execution handoff clarifications
- Add a separate NAPI FinancialReplaySession and a fixed-intent-trace request variant in the existing worker. Keep the legacy run request and durable runner default unchanged. The trace path is for conformance/debugging, not a declarative strategy language or S01 strategy runtime.
- Verify frozen D01 inputs inside the worker before native creation; native prepared input remains a trusted host boundary, not independent proof of a supplied dataset hash. Convert represented numeric values to plain decimal strings, expanding scientific notation and rejecting precision/range loss rather than silently rounding.
- Pin a strict version/session/dataset envelope and validate response identities. Emit prefix observation deltas and one shared financial/order/risk view; never pass full prepared data/checkpoints to a callback or clone retained checkpoints in the hot loop. A small read-only F06 range accessor is permitted; replay and risk semantics are not changed.
- Permit a test-only include of the new adapter from the financial test module: the crate excludes its API module from ordinary unit builds. Exercise the production host/direct-Replay parity without enabling unrelated legacy NAPI wrappers or changing production module direction. The thin exported wrapper delegates one-to-one to that host and is separately tested through the built addon.
- The conformance loop may evaluate fixture callbacks in varied order, but submits the complete due-owner batch once. Callback failure fails/disposes the attempt; no partial submission or later successful finalization. Production strategy state/RNG, artifact imports and durable canonical cutover remain S01/R05.
- Preserve existing process supervision: one process/request, hard cancellation, wait for close after a result, rejection after abort, failed worker reuse and stale attempt protection. Run existing runner cancellation/lease regressions, including the disposable PostgreSQL suite at integration.
- Extend the existing P01 harness with actual session preparation/load, advance/submit call timings and counts, context/delta bytes and finalization. Calls include real Rust/serialization work; do not label them empty crossings or end-to-end strategy throughput.
## Exclusions
No unrelated refactor, new service, broker enablement, or silent reinterpretation of historical results.
## Likely files and ownership
- apps/stock/engine/src/api/backtest.rs
- apps/stock/engine/src/api/replay.rs (additive session; existing backtest API unchanged)
- apps/stock/engine/src/financial/replay.rs (read-only published-observation range accessor only)
- apps/stock/orchestrator/src/backtest/native-replay.ts
- apps/stock/orchestrator/src/contracts/native-replay.ts (schema-only boundary)
- apps/stock/orchestrator/src/backtest/native-worker.ts
- apps/stock/orchestrator/src/backtest/native-worker-protocol.ts
- apps/stock/orchestrator/src/backtest/NativeBacktestWorker.ts
- scripts/benchmark-research.ts and focused native/worker fixtures
Write locks: native-public-api, worker-protocol. One agent owns this change. Lock names do not override actual overlapping files.