feat(research): run stateful TypeScript strategies on canonical replay

This commit is contained in:
Boki 2026-10-23 13:08:24 -04:00
parent 0870b55830
commit 2bcadbd117
14 changed files with 1864 additions and 33 deletions

View file

@ -73,3 +73,11 @@ The owner accepted F08 and requested continuation after the handoff explicitly n
- Direct trusted program objects suffice here. S02 supplies the first real SMA strategy and trusted worker composition; R01/A02 own immutable/untrusted artifacts and isolation. Keep the existing legacy `StrategyRegistry` instead of broadening its execution-service factory into the canonical author API.
Required regression scenarios include mixed owner cadence/warmup, reversed callback order and independent RNG draws, prefix/future-suffix integrity, late callback failure after a committed barrier, ambiguous post-native-submit failure, risk-rejection feedback with state advancement, repeated/partial targets, owned cancellation feedback, frozen/retained-reference isolation, invalid state/Promise/mode rejection, and compile-time absence of financial mutation services. Fresh retries must equal uninterrupted decision/state/RNG/economic results. Preserve existing conformance/result hashes and paper recovery tests. Measure deterministic strategy staging on representative release workloads without a DSL/cache or an unrelated hot-loop optimization.
## Reviewed implementation handoff — 2026-10-23
Implemented the pinned contract in `contracts/canonical-strategy.ts`, `backtest/strategy-runtime.ts`, the shared native replay loop and a narrow native order-feedback decoder. The exact architecture allowlist adds only the new trusted host runtime; direct native entry points remain unchanged. `tsconfig.contracts.json` permanently includes the author type tests.
Independent review found and fixed two issues before acceptance: rejected async callbacks could leave unhandled rejections, and optional-looking Zod unknown fields accepted an empty feedback tag. Actual Promises are now observed without awaiting; arbitrary thenables remain invalid and uninvoked. Feedback tags require object payloads while nested financial diagnostics stay opaque. Subprocess regressions cover immediate, delayed and foreign-realm rejection; native failure tests prove all-owner atomic diagnostic state.
Full repository checks passed (78 tooling, 43 utility, 44 calculation, 390 integration, 144 Rust tests), plus 58 disposable recovery tests, 43 focused release tests and extra strict test TypeScript/lint/formatting. The 48-session paired benchmark preserves every financial ID/hash; measured stateful overhead is 14–313 ms across six 10,000-total-bar workloads. This includes validation/staging/feedback, not pure callback cost. See the [wave handoff](../../ROADMAP.md#fourteenth-wave-execution--2026-10-23) and canonical manifest for exact commands, hashes and measurement limitations. New S01 implementation remains uncommitted.

View file

@ -55,3 +55,11 @@ Keep migrations additive and previous results readable. Do not add a switch that
## 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.