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

4.9 KiB

F07 — Expose bounded Rust step sessions through existing NAPI workers

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

Scheduling source of truth: manifest entry F07. 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

Expose a small pull session (load/create/advance/submit/finalize/dispose) in the existing worker, backed by the same financial kernel. advance returns a tagged union: progress, decision batch, or complete. For a decision batch, all due strategies receive immutable views from the same ledger revision; collect all decisions before ordered admission. Use one native test strategy/intent trace for conformance, not a port of every Rust built-in. Per-session dataset load once; cross-trial residency is P03.

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/orchestrator/src/backtest/native-worker.ts
  • apps/stock/orchestrator/src/backtest/native-worker-protocol.ts
  • apps/stock/orchestrator/src/backtest/NativeBacktestWorker.ts

Write locks: native-public-api, worker-protocol. One agent owns this change. Lock names do not override actual overlapping files.

Dependencies and blockers

Implementation requires F06, C02 integrated.

Architecture decisions: ADR-004. 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

  • TS caller handles every step variant; it never assumes each advance returns a decision. Progress/cancel boundaries remain bounded.
  • All due decisions reference one barrier revision. Reversing callback evaluation order cannot change output when contexts/states are unchanged; final admission uses declared owner priority.
  • No partial barrier is committed if a decision throws. Rust returns per-intent accepted/rejected outcomes; business rejection is not a rollback of the observed decision event.
  • Native conformance intent trace and TS fixture use identical financial transitions. Native built-in production strategy parity is not required.
  • Worker crash/cancel/lease loss cannot publish successful stale results; snapshot/ID/version mismatches reject.

Mandatory tests

  • step_tagged_union, immutable_barrier_revision, reverse_callback_order, decision_exception_aborts_barrier, rejected_intent_is_committed_outcome.
  • Existing native-worker/runner cancellation and lease tests; extend P01 with step and context-byte timings.

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.