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

@ -1,8 +1,8 @@
{
"schema_version": 1,
"plan_revision": "2026-10-23.31",
"plan_revision": "2026-10-23.32",
"repository_base": "b7aeca4",
"plan_status": "fourteenth_wave_in_progress",
"plan_status": "fourteenth_wave_in_review",
"execution_authorized": true,
"execution_scope": {
"authorized_by": "User: commit all of it and continue (2026-10-23), after handoff explicitly named S01 and linked pending ADR-005. F08 accepted and committed as 3838295; continue with S01 under ADR-004/005. No paper/default cutover or unrelated ADR approval.",
@ -904,7 +904,7 @@
"epic": "E4",
"priority": "P0",
"severity": "Critical",
"status": "in_progress",
"status": "review",
"dependencies": [
"F07"
],
@ -934,12 +934,14 @@
"release_gates": [],
"worktree": "/tmp/stock-bot-wave14.JYfazy/s01",
"integration_base": "3838295eec8e84a46115462ca6c5d5c8c7fab66b",
"integration_state": "isolated_implementation",
"integration_state": "validated_uncommitted",
"implementation_slices": [
{ "owner": "/root/s01_contract", "scope": "Typed strategy contract, shared pull driver, staged per-owner runtime, native admission-feedback parser and focused tests", "worktree": "/tmp/stock-bot-wave14.JYfazy/s01", "branch": "wave14/s01-runtime" },
{ "owner": "/root/s01_test_review", "scope": "Disjoint real-native multi-owner failure/retry/integrity tests and measured strategy fixture after pinned API handoff", "worktree": "/tmp/stock-bot-wave14.JYfazy/verification", "branch": "wave14/s01-verification" }
],
"review_notes": "Whole-attempt restart from frozen inputs/initial states/seeds; diagnostic TS snapshots are not resumable financial checkpoints. Per-owner observation cursors and RNG/decision sequences; native Order effects supply admission feedback. Direct trusted host programs only; S02 owns built-in/worker wiring, S03 paper recovery, R05 default/persistence cutover."
"review_notes": "Exact eight-file integration independently reviewed; root added permanent author type gate. Full repository, disposable recovery and release checks passed. Whole-attempt retry, mixed cadence, staged owner state/RNG and native admission feedback verified. Rejected Promise cleanup and missing envelope tags fixed before acceptance. Paired 48-session measurement preserves exact economic identities; see fourteenth_wave_validation. Trusted direct programs only; S02/S03/R05 own later worker/paper/default integration.",
"reviewed_by": ["/root/s01_final_review", "/root"],
"verification_reference": "ROADMAP.md#fourteenth-wave-execution--2026-10-23"
},
{
"id": "S02",
@ -5222,5 +5224,213 @@
"Root pinned S01 whole-attempt restart and per-owner state/RNG/observation semantics after independent runtime/recovery inspection. Existing native API has no checkpoint wire; do not introduce a partial TS-only resume.",
"One implementation owner controls strategy contract/shared driver/native admission feedback. Disjoint verification owner waits for pinned API. Root owns metadata/integration; independent review checks both slices.",
"Trusted direct programs only. S02 owns real-strategy/worker composition, S03 paper migration, R05 durable canonical/default cutover. Other ADRs, untrusted-code isolation, financial policy and existing active runtimes remain unchanged."
]
],
"fourteenth_wave_validation": {
"state": "validated_uncommitted",
"work_root": "/tmp/stock-bot-wave14.JYfazy",
"committed_before_implementation": [
"3838295eec8e84a46115462ca6c5d5c8c7fab66b",
"0870b5583045b98d7f02598e61d772c489af5441"
],
"scope": "S01 trusted host runtime only. No Rust financial semantics, worker request, SQL/paper, active legacy registry, user strategy loading or default cutover changes. S02 owns one real strategy and trusted worker composition.",
"source_integration": {
"owner_files": 8,
"exact_hashes": {
"apps/stock/orchestrator/src/backtest/strategy-runtime.ts": "c46bd8704ecbbb0a0d70fa60ff7d062a2398614ad0d5d8c6f23540f5b4e1b56e",
"apps/stock/orchestrator/src/backtest/native-replay.ts": "61e296f6cff7b441612872742d60379087f7661557bbb52db7b039128e425232",
"apps/stock/orchestrator/src/contracts/canonical-strategy.ts": "479347248ef19077ef7d4802a2023911c37c6cb7d14d2a6857133d24bd219bea",
"apps/stock/orchestrator/src/contracts/native-replay.ts": "bc7d98d735e453c78d174d80aba2a94637193c77bcfe14f65ffd12f305221789",
"scripts/test/architecture.test.ts": "afc718d1b157d6d501508bb9be6e0f204cdaaa822a8e15c9dbaec1b4ba562716",
"scripts/test/strategy-runtime.test.ts": "1da6beaf983e4a391610d32efa93b7435ae3ce9cce849ea07692742bd9b732d4",
"test/integration/strategy-runtime.test.ts": "6c95437b2bf2c7c6c42a70f8d16aa4b046cb81453bd0fb45556f256853dadd99",
"test/contracts/strategy-runtime.type-test.ts": "9017fd3eba72b3628e77ac79e884af2bb1251b1b9d06ca29df71b23b923c73f6"
},
"root_gate": "tsconfig.contracts.json permanently includes test/contracts/strategy-runtime.type-test.ts",
"root_gate_sha256": "eab2122e8741b7e129e8fefbe62441460df5dfcab80c5eaec1c105db46bd07e9",
"source_archive": "/tmp/stock-bot-wave14.JYfazy/integrated-source.tar",
"source_archive_sha256": "aa568bf216b111fc161ff1ade7962f6aa773c6117eb202c0a29ace4cbaa3a86f",
"measured_source": {
"root": "/home/boki/repos/stock-bot",
"commit": "0870b5583045b98d7f02598e61d772c489af5441",
"dirty": true,
"sha256": "29d0b55e68aa31f0005a1dc81b4b2bd5ac24716148884549fc16159360c9932b",
"files": 1172
},
"note": "Only planning records changed after measurement; source hashes remain those independently reviewed and validated."
},
"review": {
"reviewer": "/root/s01_final_review",
"disposition": "Accepted exact eight-file integration and final performance methodology/results; no remaining blocker. Reviewer read code/logs, did not execute builds/tests.",
"fixed_findings": [
"Invalid async callbacks could leave unhandled Promise rejections; intrinsic rejection observation now covers immediate, delayed and foreign-realm Promises without awaiting or invoking arbitrary thenables.",
"Zod unknown fields accepted missing Risk/Operator tags; decoder now requires object-valued tags while leaving nested financial diagnostics opaque."
],
"independent_tests": "15 real-native scenarios /249 assertions; trace-format determinism includes all no-op decisions; owner unit tests also verify malformed post-submit feedback cannot partially advance TS state."
},
"gates": {
"full": {
"command": "CARGO_BUILD_JOBS=2 bun run check",
"log": "/tmp/stock-bot-wave14.JYfazy/integration-check.log",
"passed": true,
"tests": {
"tooling": 78,
"utilities": 43,
"calculations": 44,
"integration": 390,
"rust": 144
},
"existing_manual_rust_ignored": 4,
"other": "Build/typecheck/permanent contracts/audit/lint passed."
},
"extra_strict_types": {
"command": "bunx tsc --project /tmp/stock-bot-wave14.JYfazy/tsconfig.integration.json --noEmit",
"log": "/tmp/stock-bot-wave14.JYfazy/integration-extra-types-final.log",
"passed": true,
"note": "Initial temporary config lacked root Bun typeRoots; corrected external config only. Production and permanent contract gates passed."
},
"disposable_recovery": {
"command": "PIPELINE_TEST_DATABASE_URL=postgres://fixture:fixture@127.0.0.1:32811/stock_bot_safety BACKTEST_TEST_REDIS_URL=redis://127.0.0.1:32812/15 bun run test:postgres",
"log": "/tmp/stock-bot-wave14.JYfazy/integration-postgres.log",
"passed": 58,
"assertions": 345
},
"release_focused": {
"command": "bun test scripts/test/strategy-runtime.test.ts test/integration/strategy-runtime.test.ts test/integration/native-replay.test.ts test/integration/native-replay-projection.test.ts test/integration/native-replay-report.test.ts",
"log": "/tmp/stock-bot-wave14.JYfazy/integration-release-focused.log",
"passed": 43,
"assertions": 568
},
"scoped": "Explicit ESLint --no-ignore --max-warnings 0 for new unit/integration/type fixtures, scoped Prettier and git diff --check passed. Existing architecture script curly findings were not expanded or rewritten.",
"not_run": "Browser/Python boundaries unchanged; not rerun. Counts overlap. No paper/default activation."
},
"native": {
"release_sha256": "6fe9dae546b4fc1d50b064b2ad50b0a3d08a0208ede3c568bf0f95e549c57b9e",
"matches": "apps/stock/engine/dist/engine.node == target/release/libengine.so; same financial artifact as F08",
"owner_debug_sha256": "ee43d8aeba4de5f1bd6d076348f7336f732411222036fec2f47f8442deb2537a",
"verifier_debug_sha256": "24e8c31995a752bc8915c737ce34564698bb5b518e5cf4ac5dffcd039593e4eb",
"isolation": "Root verified owner/verifier engine, types and calculations workspace links resolve within their respective worktrees; each addon matches its own local debug library."
},
"performance": {
"conformance": {
"command": "bun run scripts/benchmark-research.ts --session --measure --profile=all --format=projection --bars=10000",
"raw": "/tmp/stock-bot-wave14.JYfazy/conformance-10k-projection.json",
"raw_sha256": "39925fd1742df32ddd356bef0b03889d72ea18e2d11027c64ee0cb5448105ddc",
"comparison": "/tmp/stock-bot-wave14.JYfazy/conformance-comparison.json",
"comparison_sha256": "e897c7fb9e7dad710014d23db4b812631396caf69da0c98212386ddd387a5240",
"assertion": "Six workloads, four samples each; same dataset/policy/strategy hashes and exact complete-result/common-financial hashes as accepted F08. Same native artifact. Historical wall-time changes reflect different shared-host load; no speedup attribution."
},
"stateful": {
"command": "bun run /tmp/stock-bot-wave14.JYfazy/strategy-benchmark.ts",
"harness": {
"path": "/tmp/stock-bot-wave14.JYfazy/strategy-benchmark.ts",
"sha256": "0d9f6ac8c9a073b2661dc4fb41cab1a5f3b6d2934fb36a19d42bef49ed9e59c3"
},
"smoke": "--smoke passed all six tiny workload pairs before full execution",
"raw": "/tmp/stock-bot-wave14.JYfazy/strategy-comparison.json",
"raw_sha256": "57a1d12fb6ff92b84dca0593b3d95eb52c0e5b3b9135ebceca819ef57a3da76c",
"summary": "/tmp/stock-bot-wave14.JYfazy/strategy-summary.json",
"summary_sha256": "a324e580dcf562567041082338ab4e35a5455289a50cc6d6a5eb497843bed285",
"timed_sessions": 48,
"untimed_reference_captures": 24,
"total_bars_per_workload": 10000,
"rows": [
{
"profile": "none",
"assets": 1,
"owners": 1,
"decisions": 9999,
"recorded_ms": 860.6842254999999,
"stateful_ms": 948.9492395000002,
"added_ms": 88.26501400000029,
"added_percent": 10.255214558942827,
"recorded_decision_ms": 11.100141499980168,
"stateful_decision_ms": 94.17082600002038,
"full_result_hash": "ba38c860ec1ea215118f3cee4ffbb214d4d22c00e6b5f59fcc041570e6595d39"
},
{
"profile": "none",
"assets": 10,
"owners": 2,
"decisions": 1998,
"recorded_ms": 357.3840935,
"stateful_ms": 371.74131,
"added_ms": 14.357216499999993,
"added_percent": 4.0173070825268775,
"recorded_decision_ms": 2.3033820000006813,
"stateful_decision_ms": 19.935226999995734,
"full_result_hash": "c9d2f8c913394fa37b3a4e057567ffa1463413ec5dbcda9c2c26109078b27103"
},
{
"profile": "sparse",
"assets": 1,
"owners": 1,
"decisions": 9999,
"recorded_ms": 907.9061945000001,
"stateful_ms": 1050.4517705,
"added_ms": 142.54557599999998,
"added_percent": 15.700473998693475,
"recorded_decision_ms": 10.62779800000419,
"stateful_decision_ms": 100.2197030000076,
"full_result_hash": "96cd34df8ef15c5dfb50607035ea3ddd038e66e248fd5e2cbf85c6255e487ff2"
},
{
"profile": "sparse",
"assets": 10,
"owners": 2,
"decisions": 1998,
"recorded_ms": 511.2353980000001,
"stateful_ms": 527.2819215,
"added_ms": 16.046523499999864,
"added_percent": 3.1387739508600854,
"recorded_decision_ms": 2.3143130000000838,
"stateful_decision_ms": 26.409344500000202,
"full_result_hash": "35cbb5cabda1716a87ae54442f214f4030ddadf9e894271a90d6852590ea8211"
},
{
"profile": "turnover",
"assets": 1,
"owners": 1,
"decisions": 9999,
"recorded_ms": 1568.5752975,
"stateful_ms": 1881.493087,
"added_ms": 312.9177895,
"added_percent": 19.94917234759015,
"recorded_decision_ms": 12.920671999951082,
"stateful_decision_ms": 267.69706899998255,
"full_result_hash": "f6f92431d08c1f52d4b5ceea4860b9607750da2d0c07ce68e57c92d23a1e948d"
},
{
"profile": "turnover",
"assets": 10,
"owners": 2,
"decisions": 1998,
"recorded_ms": 1924.771716,
"stateful_ms": 2211.8719705,
"added_ms": 287.1002544999999,
"added_percent": 14.9160678179874,
"recorded_decision_ms": 3.2020279999999275,
"stateful_decision_ms": 279.2468269999845,
"full_result_hash": "ecf3f66cc98da3a6813c6a33f31ecb9f26ede7d6f1ac57eb6375c95a11279263"
}
],
"assertion": "Exact captured decision replay preserves every financial ID and complete projection hash. Repeated/reversed program order preserves diagnostic/RNG hashes. Integer-cent oracle verifies this fixed fixture.",
"interpretation": "Stateful wall overhead 14-313 ms /3.1-19.9%, including construction, state validation/staging, RNG, callbacks and admission feedback. This is a profiling baseline, not pure callback cost or justification for a DSL/cache.",
"limitations": [
"Timed sessions are in a warmed process after an untimed reference capture; four samples per mode in counterbalanced separate processes.",
"Each callback updates four scalar fields and draws once; no complex models/large state/shared features are measured.",
"Both modes retain a decision tape; peak RSS includes it and reference activity. Oracle/hash verification excluded from executionWallMs.",
"10000 total bars, not per asset. No queue/storage/durable job, cold-start SLA, allocation attribution or isolated-host confidence interval.",
"S01 decision IDs enlarge payloads compared with F08 conformance. Only the exact-decision paired control measures stateful overhead without that confound."
]
}
},
"limitations": [
"Trusted synchronous author contract, not an untrusted-code sandbox or proof of arbitrary JS determinism.",
"Diagnostic snapshots cannot resume financial state. Retry reconstructs the whole attempt from frozen data/config, initial states and original seeds.",
"Feedback represents native admission effects, not a complete later fill-event stream; current holdings/orders remain native views.",
"Existing financial/time/risk/model limitations remain; multi-asset default mark-policy gate unresolved."
],
"cleanup": "Stopped only disposable --rm fixtures 0547b8ad5629caea34a7191d44c09beba2f58770dcc2d57e938526a39118864f and a6b5721f9cce058e341abbba8f33234bda1cef318ae3d438fa4e95181f4feeac. Development services untouched; worktrees/logs/archives retained.",
"next": "After acceptance: S02 one SMA program and explicit trusted worker composition; no additional economic-policy approval needed for its scoped task. R01/R11 await ADR-006; S03/R05 retain paper/default activation gates."
}
}