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

4.8 KiB

S01 — Run deterministic TypeScript decisions on Rust sessions

Parent epic: E4. Priority/severity: P0 / Critical. Relative complexity: M. Recommended specialization: TypeScript trading infrastructure.

Scheduling source of truth: manifest entry S01. 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 deterministic-by-contract TS decisions with prefix-only observations plus existing reviewed incremental calculations; shared feature caching is not a prerequisite. Use the F07 tagged step/barrier API, owner-stamped IDs, explicit decision cadence and seeded randomness. Stage next strategy states and RNG cursors until the barrier is submitted. Decision exceptions discard staged states and abort the attempt; rejected financial intents still commit the observation/state transition and return feedback.

Exclusions

No unrelated refactor, new service or broker activation.

Likely files and ownership

  • apps/stock/orchestrator/src/strategies/
  • apps/stock/orchestrator/src/backtest/native-worker.ts
  • apps/stock/orchestrator/src/backtest/strategy-plan.ts
  • libs/core/types/src/

Write locks: strategy-contract, worker-protocol. Review concrete file overlap; first-wave writable paths are further restricted by FIRST-WAVE.md.

Dependencies and blockers

Implementation requires F07 integrated.

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

  • On the pinned supported runtime/build, controlled clock/random inputs and identical state yield identical fixture decision traces and economic hashes.
  • Each strategy sees its own state/positions and the same barrier portfolio snapshot, not a state mutated by another callback's early admission.
  • Retry restores strategy state, RNG position and decision sequence; quantity rejection does not pretend the observation never occurred.
  • Contract/type checks prohibit broker/account mutation services; trusted callbacks are not a security sandbox. No claim that repeated tests prove arbitrary TS deterministic.

Mandatory tests

  • same_seed_trace, all_callbacks_same_barrier_view, exception_restores_state_rng, rejected_order_feedback, repeated_target_no_duplicate.
  • Compile-time context tests and preserved strategy-recovery scenarios; P01 adds actual TS decision costs.

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

Compatibility or lifecycle regression; preserve frozen inputs, old results and existing failure tests. 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.