docs(development): accept S01 and pin trusted SMA worker scope

This commit is contained in:
Boki 2026-10-23 13:15:52 -04:00
parent 2bcadbd117
commit 4f6e44a853
4 changed files with 103 additions and 34 deletions

View file

@ -19,12 +19,11 @@ 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
- `apps/stock/orchestrator/src/contracts/builtin-strategy.ts` and `strategies/canonical-sma.ts`: one strategy/schema owner.
- `apps/stock/orchestrator/src/contracts/strategy-replay.ts` and the existing native worker protocol/child/supervisor: a disjoint worker owner consumes the pinned selection schema.
- Dedicated strategy and worker integration tests/fixtures follow those owners. Root owns planning/integration; review is independent.
Write locks: strategy-builtins. One agent owns this change. Lock names do not override actual overlapping files.
Preserve the legacy registry, BaseStrategy and built-ins unchanged; reuse their alias mapping. No generic registry rewrite. Actual overlapping files override symbolic locks.
## Dependencies and blockers
@ -58,8 +57,20 @@ Report scope changes (if any), fixture expectations, API/schema changes, measure
## 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.
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 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.
## Execution contract — 2026-10-23
S01 is accepted as `2bcadbd`. The trusted selection is `{ownerId, strategyId, strategyVersion, seed, instrumentId, seriesId, ownerBudget, parameters: {fastPeriod, slowPeriod}}`. Existing SMA aliases normalize to `sma_crossover`; the explicit new version is `sma-crossover-long-only/v1`. Reject legacy quantity/fraction/holding-period parameters and unknown fields on this version. It deliberately differs from legacy short entries and account-wide sizing.
One instance consumes one declared instrument/series included in its native cadence. Use the reviewed `movingAverageCrossover` with a bounded `slowPeriod + 1` close window, including warmup and its existing equality rules. Process availability-order observations only if their `(event_time, source_sequence)` advances; delayed older observations do not rewrite history. A real golden cross establishes a whole-share target `floor(ownerBudget / close)` using exact decimal inputs; no minimum-one purchase. Hold that target through the bullish phase, including ties; a death cross establishes zero. Repeat the same target on fresh selected input so native target reconciliation preserves or retries commitments. Missing, stale or no-new selected input emits sparse empty targets, preserving existing GTC intent. Match the last accepted observation to the native Fresh input before emitting a target. Budget is desired gross notional, not a new hard risk allocation; Rust alone handles fees, gaps, funding and risk.
Keep finite plain JSON indicator state; validate reconstruction without exposing initial-state injection over IPC. Whole-attempt retries start from original inputs. No rolling-sum arithmetic rewrite or feature-cache framework.
Add strict `runStrategyReplay` version1 requests with existing dataset/config/eventBudget/resultFormat and trusted selections only. Return a versioned `strategyReplayResult` envelope containing normalized selections actually executed and the unchanged native result. The parent captures detached normalized inputs before fork and binds selections, native identity, policy and format on return. No callbacks, source, arbitrary paths, checkpoint transport or second worker infrastructure. Existing legacy/conformance requests remain supported.
Required additions: warmup/tie/delayed-bar/freshness cases; exact budget and native fee/gap rejection; separate owners; whole retry and JSON reconstruction; real worker/direct equality in all formats; malformed/tampered responses, crashes and cancellation (including result-before-close); legacy worker regressions. Full repository and disposable recovery gates follow integration. Measure representative release SMA replay without calling it pure callback cost or claiming a performance improvement.