5.2 KiB
S02 — Adapt one SMA strategy for the first canonical path
Parent epic: E4. Priority/severity: P1 / High. Relative complexity: M. Recommended specialization: TypeScript strategy/quant engineering.
Scheduling source of truth: manifest entry S02. 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
- STR-01 — Verified: Registry is a useful small boundary, but its factories receive mode/execution services; BaseStrategy mixes author decisions, order submission and hidden signal filtering. apps/stock/orchestrator/src/strategies/StrategyRegistry.ts:7; apps/stock/orchestrator/src/strategies/BaseStrategy.ts:315.
- FIN-04 — Verified: Native fills notify every strategy. TypeScript realized P&L uses aggregate symbol cost basis, not per-strategy cost basis. apps/stock/engine/src/backtest/engine.rs:489; apps/stock/orchestrator/src/execution/model.ts:108.
Intended behavior and implementation scope
Adapt one existing SMA strategy first into the approved TS decision API using the current registry alias. Remove direct ModeManager/ExecutionService access for this version; parameters and owner budget are explicit. Keep other strategies/version readers intact and visibly legacy/unsupported on the canonical path until adapted. A native conformance strategy is test-only, not a competing production implementation.
Exclusions
No unrelated refactor, new service or broker activation.
Likely files and ownership
- apps/stock/orchestrator/src/strategies/StrategyRegistry.ts
- apps/stock/orchestrator/src/strategies/BaseStrategy.ts
- apps/stock/orchestrator/src/strategies/builtin/SmaCrossoverStrategy.ts
- apps/stock/orchestrator/src/strategies/builtin/MeanReversionStrategy.ts
Write locks: strategy-builtins. One agent owns this change. Lock names do not override actual overlapping files.
Dependencies and blockers
Implementation requires S01 integrated.
No additional economic-policy approval is needed for this narrowly scoped task.
Parallel eligibility: only with disjoint actual files and reserved write locks; read FIRST-WAVE.md for the initial exact ownership boundaries.
Acceptance criteria
- The versioned SMA strategy runs via the Rust session with no service injection and isolated checkpoint state.
- Entry/exit and owner sizing are explicit; prior registry alias still resolves to a deliberate version/capability.
- A new canonical run can ship after this one strategy passes; migrating every native/TS built-in is not a release gate.
Mandatory tests
- sma_registry_alias, owner_budget_sizing, sma_checkpoint_restore, sma_next_open_trace.
- Legacy strategy/result compatibility remains; no wholesale BaseStrategy deletion.
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.
S01 integration handoff — 2026-10-23
Consume contracts/canonical-strategy.ts and backtest/strategy-runtime.ts: typed synchronous programs return JSON next state and financial intent; the host owns per-instance seeds/cursors and Rust owns admission/accounting. Reuse reviewed incremental calculation semantics. Preserve the current legacy factory contract; add only the small trusted built-in resolver/composition needed to select the canonical SMA version deliberately.
Wire that reviewed built-in through the existing native worker with explicit strategy/version/parameters and retained dataset/config inputs. Never serialize callback functions/source or accept arbitrary module paths. Keep legacy and conformance requests intact; unknown canonical strategies/versions reject explicitly. R05 still owns durable default and public-result migration. No browser/default activation or paper migration is implied here.
S01 retries whole attempts from frozen inputs and original state/seeds. Its snapshots are diagnostic, not native resume tokens. sma_checkpoint_restore should verify indicator state serialization/recomputation and full retry equivalence without introducing TS-only mid-run financial resume. Admission feedback is not a complete fill-event feed; positions/open orders remain authoritative native views.