feat(research): run trusted SMA strategies through native workers

This commit is contained in:
Boki 2026-10-23 14:07:53 -04:00
parent 4f6e44a853
commit ca5abdde0e
16 changed files with 1682 additions and 28 deletions

View file

@ -1,8 +1,8 @@
{
"schema_version": 1,
"plan_revision": "2026-10-23.33",
"plan_revision": "2026-10-23.34",
"repository_base": "b7aeca4",
"plan_status": "fifteenth_wave_in_progress",
"plan_status": "fifteenth_wave_in_review",
"execution_authorized": true,
"execution_scope": {
"authorized_by": "User: commit and continue (2026-10-23), after S01 validated handoff named S02. S01 accepted and committed as 2bcadbd. Continue only S02 under approved ADR-002/003/004/005.",
@ -969,7 +969,7 @@
"epic": "E4",
"priority": "P1",
"severity": "High",
"status": "in_progress",
"status": "review",
"dependencies": [
"S01"
],
@ -994,7 +994,7 @@
"release_gates": [],
"worktree": "/tmp/stock-bot-wave15.zi3GmP/strategy",
"integration_base": "2bcadbd117c288577a26615e6d132cf49ea074e4",
"integration_state": "isolated_implementation",
"integration_state": "validated_uncommitted",
"implementation_slices": [
{
"owner": "/root/s02_strategy",
@ -1006,8 +1006,27 @@
"owner": "/root/s02_worker",
"scope": "Additive trusted worker request/result supervision with dedicated tests",
"worktree": "/tmp/stock-bot-wave15.zi3GmP/worker",
"branch": "wave15/s02-worker"
"branch": "wave15/s02-worker",
"integration_handoff": "Root imported six-file draft after explicit takeover authorization, corrected nonempty-array input typing and readonly expected test arrays, and completed all validation. Worker owner made no concurrent edits."
}
],
"reviewed_by": [
"/root/s02_review",
"/root"
],
"verification_reference": "ROADMAP.md#fifteenth-wave-execution--2026-10-23",
"review_notes": "All ten source/test files independently approved with exact hashes. Full repository, strict test types/lint/format, disposable recovery, release and built-worker parity gates passed. Long-only policy differs explicitly from legacy; R01/R05 retain artifact and durable/public cutover. Paired 48-session exact-decision benchmark identifies aggregate strategy/state overhead; P08 planned only. Root finished worker validation after owner tool approval stalled; no new source semantics changed during takeover.",
"concrete_write_scope": [
"apps/stock/orchestrator/src/contracts/builtin-strategy.ts",
"apps/stock/orchestrator/src/strategies/canonical-sma.ts",
"apps/stock/orchestrator/src/contracts/strategy-replay.ts",
"apps/stock/orchestrator/src/backtest/native-worker-protocol.ts",
"apps/stock/orchestrator/src/backtest/native-worker.ts",
"apps/stock/orchestrator/src/backtest/NativeBacktestWorker.ts",
"test/fixtures/canonical-sma.ts",
"test/integration/canonical-sma.test.ts",
"test/integration/canonical-strategy-worker.test.ts",
"test/fixtures/canonical-strategy-worker.ts"
]
},
{
@ -1972,6 +1991,37 @@
"review_notes": "Independent financial-normalizer and measurement/provenance reviews passed; final 72-tooling gate and strict test types/lint passed. Paired final-source release benchmarks cover all three 10k profiles and sparse/turnover at 100k. Historical baseline source-retention limitation is explicit; measured final source is archived. Owner accepted and authorized commit e3bd722 on 2026-10-23.",
"verification_reference": "ROADMAP.md#twelfth-wave-handoff--2026-10-23"
},
{
"id": "P08",
"title": "Reduce measured TypeScript strategy decision overhead",
"epic": "E7",
"priority": "P1",
"severity": "High",
"status": "blocked",
"dependencies": [
"S02",
"P07"
],
"decision_dependencies": [],
"task_file": "backlog/tasks/P08.md",
"findings": [
"PER-02"
],
"complexity": "M",
"specialization": "TypeScript performance/deterministic runtime engineering",
"write_locks": [
"strategy-contract",
"strategy-builtins",
"benchmark-harness"
],
"parallel_policy": "One runtime/strategy optimization owner. Disjoint review may proceed; actual file overlap with S03/S05 or benchmark work blocks concurrency. Scope exact files before edits.",
"assignment": null,
"branch": null,
"pull_request": null,
"completed_commit": null,
"blocker": "Requires S02 acceptance/commit and explicit next-wave authorization. Profile subphase costs before choosing a local optimization; preserve current contracts and all invariants.",
"release_gates": []
},
{
"id": "A01",
"title": "Add research-only principals and durable job budgets",
@ -5481,6 +5531,339 @@
"S01 accepted after frozen-hash and diff verification. No new-wave implementation commit yet.",
"Pinned S02 explicit long-only version, reviewed crossover arithmetic, exact owner-budget whole-share sizing, monotonic available observations and native Fresh gating; legacy semantics unchanged.",
"Minimal trusted worker selection/result envelope binds exact strategy provenance and native identity/policy/format. No callback/source/path or checkpoint transport.",
"S03 is code/ADR-ready but not authorized in this wave. R05 owns durable/default/public result cutover; ADR-006/007/008 remain pending."
]
"S03 is code/ADR-ready but not authorized in this wave. R05 owns durable/default/public result cutover; ADR-006/007/008 remain pending.",
"Paired S02 benchmark demonstrates aggregate TS strategy/state overhead, especially 252-bar windows. P08 is a narrow planned follow-up, recommended after S02 acceptance; no optimization or extra task implementation in this wave."
],
"fifteenth_wave_validation": {
"state": "validated_uncommitted",
"work_root": "/tmp/stock-bot-wave15.zi3GmP",
"committed_before_implementation": [
"2bcadbd117c288577a26615e6d132cf49ea074e4",
"4f6e44a85395929a16a0d7ba622f7ae7986e4afe"
],
"scope": "One explicitly versioned long-only SMA and strict trusted selection through existing native worker. No Rust financial semantics, legacy registry, SQL, web/default or paper migration.",
"source_integration": {
"owner_files": 10,
"exact_hashes": {
"apps/stock/orchestrator/src/contracts/builtin-strategy.ts": "bd648e863f00419a7210b17ccc796ab72ba4e72edf5c04cd61af9e61527bc4d2",
"apps/stock/orchestrator/src/strategies/canonical-sma.ts": "d76ba01e40f3eed073bcada2b40078bba6f0f1702fb9e7fcdca0278775d4b01b",
"apps/stock/orchestrator/src/contracts/strategy-replay.ts": "fccba629266524c4e2a79dc95d5a89f4eea3e64b5790ea7a1c38c8121360528b",
"apps/stock/orchestrator/src/backtest/native-worker-protocol.ts": "43b0e01fd59cb6bbd483e4858555e0cdc4666c3e4835786d01442ab86520f1e5",
"apps/stock/orchestrator/src/backtest/native-worker.ts": "0f5583d72aad6841962d017565fadcecb6be775ff6b8abacbb54da9a5e0f95e1",
"apps/stock/orchestrator/src/backtest/NativeBacktestWorker.ts": "fdfa65d61b22c959ec83c83a19e6e9acbaee7d8d855b950ab30306b65b65565c",
"test/fixtures/canonical-sma.ts": "138aa061225a8d6340c788c1e914fc6eb9649234718eb273ffe5139cc6f3acb1",
"test/integration/canonical-sma.test.ts": "18d523784e5f7b3ad81729cc04de0c2af27e804e8cb0b30cda0b94551403c15b",
"test/integration/canonical-strategy-worker.test.ts": "5b0410932e96d5091e19761fba7cc3d6a2e3944cad796f55fe369fd4d0553942",
"test/fixtures/canonical-strategy-worker.ts": "546a6fc502a53260ece4361177bc4e784e97ec3f2423f65193d231eba06149bc"
},
"reviewed_hash_list_sha256": "44780f2b0f276e74c4e1b28b7297ac37a51537942e97e9595686b77ab46bb662",
"source_archive": "/tmp/stock-bot-wave15.zi3GmP/integrated-source.tar",
"source_archive_sha256": "660604296a75dc148e82622e92d8459e7d795b672ff8d4644dc6ae9a408ae948",
"measured_source": {
"root": "/home/boki/repos/stock-bot",
"commit": "4f6e44a85395929a16a0d7ba622f7ae7986e4afe",
"dirty": true,
"sha256": "8c5cd9d17e3870ebe21e95f2013b39ef00d7aa981245471f6a801fa162c42696",
"files": 1179
},
"note": "Only planning records changed after measurement; all ten source hashes remain independently reviewed and validated. Reconstruct measured source from planning commit4f6e44a plus the ten-file archive."
},
"review": {
"reviewer": "/root/s02_review",
"disposition": "Approved frozen strategy and worker integration, no blocking findings; read-only review. Reviewed measurements and supports narrow P08 follow-up; no reviewer tests/builds.",
"root_takeover": "Worker owner approval request stalled about415s and aborted with no test session; explicit ownership handoff permitted root final corrections/validation.",
"corrections": [
"Mutation test now starts with a detached mutable dataset rather than mutating the intentionally frozen fixture.",
"Schema min(1) preserves nonempty arrays without unnecessary input tuples; request author type uses schema input; readonly expectations copied for Bun strict types."
]
},
"checks": [
{
"command": "CARGO_BUILD_JOBS=2 bun run check",
"result": "passed",
"counts": {
"tooling": 78,
"utilities": 43,
"calculations": 44,
"integration": 432,
"rust": 144,
"rust_manual_ignored": 4
},
"log": "/tmp/stock-bot-wave15.zi3GmP/integration-check.log"
},
{
"command": "bunx tsc --project /tmp/stock-bot-wave15.zi3GmP/tsconfig.integration.json --noEmit",
"result": "passed",
"log": "/tmp/stock-bot-wave15.zi3GmP/integration-test-types.log"
},
{
"command": "Scoped ESLint --no-ignore --max-warnings 0 and Prettier --check over all ten integrated TypeScript files; git diff --check",
"result": "passed"
},
{
"command": "PIPELINE_TEST_DATABASE_URL=postgres://fixture:fixture@127.0.0.1:32814/stock_bot_safety BACKTEST_TEST_REDIS_URL=redis://127.0.0.1:32813/15 bun run test:postgres",
"result": "passed",
"tests": 58,
"assertions": 345,
"log": "/tmp/stock-bot-wave15.zi3GmP/integration-postgres.log"
},
{
"command": "CARGO_BUILD_JOBS=2 bun run --cwd apps/stock/engine build:release",
"result": "passed",
"log": "/tmp/stock-bot-wave15.zi3GmP/integration-native-release.log"
},
{
"command": "bun test test/integration/canonical-sma.test.ts test/integration/canonical-strategy-worker.test.ts scripts/test/native-bindings.test.ts",
"result": "passed against release addon",
"tests": 48,
"assertions": 175,
"log": "/tmp/stock-bot-wave15.zi3GmP/integration-release-focused.log"
},
{
"command": "bun /tmp/stock-bot-wave15.zi3GmP/packaged-worker-smoke.ts",
"result": "built dist/native-worker.js matches direct native trace/projection/report",
"evidence": {
"verified": true,
"summaries": [
{
"resultFormat": "trace",
"sha256": "73bc6b6c195547ad32df76613e25195c806e66d4f81e7e4ee4034d4200561055"
},
{
"resultFormat": "projection",
"sha256": "1ea0bc7ceb82d7cf70ab40a597cea9963e65303a92fead25ef04f69f313009e0"
},
{
"resultFormat": "report",
"sha256": "643a06a8824134f7cbf2a1c1b981c7bebfabe3ce86ba0ac3312ac0ad02a6a00e"
}
]
},
"harness_sha256": "fef64af8f6f38870a8470a168c19e0b9d9ee5bad59371f0a7aed00ae9927c2de"
}
],
"environment_notes": [
"Root restricted IPC test stalled and was interrupted, then unrestricted focused tests passed42/160; full/release gates used required subprocess permissions.",
"Dedicated worker test typing initially exposed array-tuple/readonly expectation issues; corrected before final strict pass.",
"Browser and Python boundaries unchanged; those suites not rerun."
],
"financial_fixture": {
"fast": 2,
"slow": 3,
"closes": [
3,
2,
1,
4,
5,
1,
1
],
"ownerBudget": "40",
"initialCapital": "10000",
"quantity": "10",
"entryNextOpen": "5",
"exitNextOpen": "2",
"feeRate": "0.01",
"totalFees": "0.7",
"terminalEquity": "9969.3"
},
"native": {
"path": "/home/boki/repos/stock-bot/apps/stock/engine/dist/engine.node",
"sha256": "6fe9dae546b4fc1d50b064b2ad50b0a3d08a0208ede3c568bf0f95e549c57b9e",
"artifact": "/home/boki/repos/stock-bot/target/release/libengine.so",
"buildProfile": "release",
"generated_types_sha256": "62c0338e9909e6bfe3feb713949fb3b063bf2b5831044763bdbdb9cf87f9f703",
"note": "Same native release artifact as S01/F08; no Rust change."
},
"performance": {
"command": "bun /tmp/stock-bot-wave15.zi3GmP/sma-benchmark.ts",
"harness": {
"path": "/tmp/stock-bot-wave15.zi3GmP/sma-benchmark.ts",
"sha256": "f0f6ec1957c752635597d6c91c725ae1ab55287fb1b445bc6095f93cde106b0c"
},
"raw_file": "/tmp/stock-bot-wave15.zi3GmP/sma-release.json",
"raw_sha256": "0e0231722401933564e4ea390146c71615a6e96241f4472c3d801d96f7923485",
"log": "/tmp/stock-bot-wave15.zi3GmP/sma-release.log",
"host": {
"platform": "linux",
"arch": "x64",
"kernel": "6.8.0-146-generic",
"cpu": "AMD Ryzen 9 9950X3D 16-Core Processor",
"logicalCpus": 32,
"memoryBytes": 98683457536,
"loadAverage": [
1.24,
2.03,
3.06
]
},
"host_load_at_finish": [
2.8,
2.38,
3.09
],
"runtime": {
"bun": "1.2.17",
"nodeCompatibility": "v22.6.0",
"executableSha256": "6cd2f181c30d3cb1497b0b9d4bc9d63eb1ec4a9142f809183fed18fcc4e1051b",
"rustc": "rustc 1.88.0 (6b00bc388 2025-06-23)",
"bunLockSha256": "1a2b653bbaaeb5075785b860487557b8fc379f0c50cbe8f2554c90e4a3ac4514",
"cargoLockSha256": "8f2ecaa4f1790f14e1650326f78fbf246f454dad6139dc4cb0d61383b9e301e8"
},
"timed_sessions": 48,
"untimed_reference_sessions": 24,
"smoke": "passed all three short-period shapes; raw sma-smoke.json retained",
"summary": [
{
"workload": {
"totalBars": 10000,
"assets": 1,
"owners": 1,
"fastPeriod": 5,
"slowPeriod": 15,
"untradedAssets": 0
},
"verified": true,
"samples_per_mode": 4,
"recorded_ms": 1091.0554985,
"sma_ms": 1466.9523095,
"added_ms": 375.89681099999984,
"added_percent": 34.45258389850825,
"sma_decision_phase_ms": 326.81869449997794,
"sma_bars_per_second": 6816.854191673367,
"decisions": 9999,
"fills": 997,
"full_financial_hash": "25fadb03424da2ab9c7e405358332ae89de492a83c71882e8bbef04b1d7f318e"
},
{
"workload": {
"totalBars": 10000,
"assets": 10,
"owners": 2,
"fastPeriod": 5,
"slowPeriod": 15,
"untradedAssets": 8
},
"verified": true,
"samples_per_mode": 4,
"recorded_ms": 409.59593200000006,
"sma_ms": 478.2034970000001,
"added_ms": 68.60756500000002,
"added_percent": 16.750060154406032,
"sma_decision_phase_ms": 66.50624600000037,
"sma_bars_per_second": 20911.599481674217,
"decisions": 1998,
"fills": 194,
"full_financial_hash": "02afdf4e00a589bdae0c66ab4416a6d8cbb130543deb4ff5b4a8e18421a7250e"
},
{
"workload": {
"totalBars": 10000,
"assets": 10,
"owners": 10,
"fastPeriod": 5,
"slowPeriod": 15,
"untradedAssets": 0
},
"verified": true,
"samples_per_mode": 4,
"recorded_ms": 624.1090814999999,
"sma_ms": 916.3397714999999,
"added_ms": 292.23069,
"added_percent": 46.82365609832904,
"sma_decision_phase_ms": 275.0971249999985,
"sma_bars_per_second": 10912.982619569733,
"decisions": 9990,
"fills": 970,
"full_financial_hash": "3616bfd9c6061abb217bd5b8451650c68e0167c9830b3b8cf0143323c6513526"
},
{
"workload": {
"totalBars": 10000,
"assets": 1,
"owners": 1,
"fastPeriod": 15,
"slowPeriod": 252,
"untradedAssets": 0
},
"verified": true,
"samples_per_mode": 4,
"recorded_ms": 1018.2021005000001,
"sma_ms": 2350.8183565,
"added_ms": 1332.6162559999998,
"added_percent": 130.87934658017332,
"sma_decision_phase_ms": 1201.672781500027,
"sma_bars_per_second": 4253.837806034675,
"decisions": 9999,
"fills": 975,
"full_financial_hash": "056f9253b2b2c9ce00aab6fa6776534e931e87273b7c1ea75e345ff57e999971"
},
{
"workload": {
"totalBars": 10000,
"assets": 10,
"owners": 2,
"fastPeriod": 15,
"slowPeriod": 252,
"untradedAssets": 8
},
"verified": true,
"samples_per_mode": 4,
"recorded_ms": 409.37107850000007,
"sma_ms": 636.4676205,
"added_ms": 227.09654199999989,
"added_percent": 55.47449586133864,
"sma_decision_phase_ms": 223.09511149999656,
"sma_bars_per_second": 15711.718362269776,
"decisions": 1998,
"fills": 150,
"full_financial_hash": "99f624549deb03d41a9ca47030ef5f39bdb98f497063af6c4bf8adc5fee013af"
},
{
"workload": {
"totalBars": 10000,
"assets": 10,
"owners": 10,
"fastPeriod": 15,
"slowPeriod": 252,
"untradedAssets": 0
},
"verified": true,
"samples_per_mode": 4,
"recorded_ms": 593.9949515000001,
"sma_ms": 1681.4738735,
"added_ms": 1087.478922,
"added_percent": 183.07881561178553,
"sma_decision_phase_ms": 1042.1618619999977,
"sma_bars_per_second": 5947.163472236965,
"decisions": 9990,
"fills": 750,
"full_financial_hash": "fb8024de3c4a710d5e7773575d59ad4904a4955ef14a15d6122bf7284526e98c"
}
],
"limitations": [
"10,000 TOTAL bars in full workloads, not per asset. Synthetic sawtooth fixture unchanged; one owner per selected asset. Ten-assets/two-owners explicitly leaves eight assets untraded while all ten replay/mark.",
"No database, durable queue, public-result mapping, real native-worker IPC, or production wall-clock throughput measurement. Each child imports modules and directly executes the canonical runtime.",
"Each fresh child first runs an untimed SMA reference to capture exact submitted financial identities. Timed fresh sessions therefore run in warmed processes; imports, preparation, reference capture and process wall time are separate.",
"Actual versioned SMA code uses bounded slow+1 JSON history and reviewed trailing calculations. Both 5/15 and 15/252 are measured; large-period copying/scanning costs remain included.",
"Recorded control replays exact captured decisions through the same Rust/native pull loop. Complete financial projection hashes including all IDs must match; there is no TypeScript accounting oracle or financial normalization.",
"executionWallMs includes native-session construction, replay, state copying/strategy/staging/feedback where applicable, finalization and disposal. Benchmark verification/hashing is measured separately.",
"decisionMs includes host validation/state copying/strategy execution/admission feedback for SMA and tape lookup/checks for recorded control. Difference is not pure callback or NAPI crossing cost.",
"Both modes retain reference decision tapes; RSS includes reference activity and tape memory. No allocation attribution or resident-dataset caching claim.",
"Two separate processes per mode, two fresh timed sessions each, counterbalanced mode order. Second SMA session reverses owner callback order and must preserve financial and diagnostic hashes. This checks fresh whole-attempt recomputation, not native checkpoint resume.",
"Shared host, no timing assertion, confidence interval, cold-start SLA, or cross-artifact performance attribution. Root must freeze source and use the matching release addon before execution."
],
"interpretation": "Verified aggregate host/strategy/state overhead, not per-function attribution. Long-window decision phase is about51\u201362%of total owner-dense wall. Profiles in P08 must distinguish schema parsing, copying/freezing, trailing calculations and allocation before optimization. No cross-shape scaling or S02 speedup claim."
},
"cleanup": {
"stopped_exact_containers": [
"d42bc73629ccfc7d816ad6d603a0131b3cd95fe53be0cc68d0bafadbf0bf2407",
"6333a832a853e86a35b7a646e96ede511e9a22fcc90ff58643f70ad702dd8db2"
],
"development_resources_touched": false,
"worktrees_and_evidence_retained": true
},
"next": "Accept/commit S02; recommended next P08 measured local TS decision/state optimization. S03 also code/ADR-ready; R01/R11 still require ADR-006. No extra task/default/paper approval inferred."
}
}