feat(research): add financial contracts and availability-aware datasets

Implement reviewed F01/D01 foundations without changing active trading runtimes. Validate strict Rust/TypeScript financial wire contracts, decimal postings, versioned datasets, explicit calendars, provenance, and v1 compatibility.
This commit is contained in:
Boki 2026-10-22 20:51:25 -04:00
parent 243e9ab43f
commit b4af840d4e
25 changed files with 4071 additions and 43 deletions

View file

@ -1,6 +1,6 @@
# Canonical development backlog
**First five waves committed; further implementation awaits architecture-policy approval.** Consult manifest execution_scope, [ROADMAP](../ROADMAP.md), [skeptical review](../REVIEW.md) and [first-wave handoff](../FIRST-WAVE.md). Other tasks and unresolved policies remain gated.
**First five waves committed; ADR-002/003/004 approved; F01/D01 validated, uncommitted.** Consult manifest execution_scope, [ROADMAP](../ROADMAP.md), [skeptical review](../REVIEW.md) and [first-wave handoff](../FIRST-WAVE.md). F01/D01 await owner acceptance/commit; other tasks and unresolved policies remain gated.
## One source of truth
@ -29,7 +29,7 @@ Relative size: S narrow correction, M coherent boundary, L sensitive owner-contr
| Task | Priority / status | Implementation prerequisites | Release gate | Specialist / size |
| --- | --- | --- | --- | --- |
| [F01 Define the minimal financial contract and economic fixtures](tasks/F01.md) | P0 / blocked | ADR-002, ADR-003, ADR-004 | — | Rust financial contract owner / M |
| [F01 Define the minimal financial contract and economic fixtures](tasks/F01.md) | P0 / review | ADR-002, ADR-003, ADR-004 (approved) | — | Rust financial contract owner / M |
| [F02 Implement one owner-aware financial ledger](tasks/F02.md) | P0 / blocked | F01, ADR-002 | — | Rust accounting / L |
| [F03 Add strategy-owned position books and fill allocations](tasks/F03.md) | P0 / merged → F02 | None | — | Rust portfolio accounting / M |
| [F04 Enforce cash reservations and portfolio risk centrally](tasks/F04.md) | P0 / blocked | F02, ADR-002, ADR-003 | — | Rust financial risk / L |
@ -42,7 +42,7 @@ Relative size: S narrow correction, M coherent boundary, L sensitive owner-contr
| Task | Priority / status | Implementation prerequisites | Release gate | Specialist / size |
| --- | --- | --- | --- | --- |
| [D01 Introduce availability-aware dataset v2](tasks/D01.md) | P0 / blocked | ADR-003 | — | TypeScript trading infrastructure / M |
| [D01 Introduce availability-aware dataset v2](tasks/D01.md) | P0 / review | ADR-003 (approved) | — | TypeScript trading infrastructure / M |
| [D02 Connect supported intraday storage to research datasets](tasks/D02.md) | P1 / blocked | D01 | — | TypeScript trading infrastructure / M |
| [D03 Add dataset eligibility and corporate-action safeguards](tasks/D03.md) | P1 / merged → D01 | None | — | TypeScript trading infrastructure / M |
| [D04 Provide prefix-safe shared feature calculation](tasks/D04.md) | P1 / deferred | S01, P01 | — | Quantitative feature engineering / M |
@ -115,4 +115,4 @@ Relative size: S narrow correction, M coherent boundary, L sensitive owner-contr
Before any wave: unique IDs; existing task/ADR references; acyclic implementation graph; no scheduled task dependent on merged/deferred work; approvals/readiness; actual file locks; isolated native build outputs/workspace dependencies and test databases. Release gates are checked separately at activation.
The first five waves are independently reviewed, validated and committed with owner approval. **W04** is committed as `550d8b7`; its five implementation/dependency hashes still match the reviewed and tested versions. Evidence is recorded in [FIRST-WAVE.md](../FIRST-WAVE.md#execution-record--2026-10-22), the [ROADMAP handoffs](../ROADMAP.md#fifth-wave-handoff--2026-10-22) and the manifest. The latest continuation request cannot satisfy unresolved policy choices: F01 needs ADR-002/003/004, D01 needs ADR-003, and R01 needs ADR-006. These are the only remaining scheduled tasks with satisfied code prerequisites; none is approval-ready yet. Deferred work remains deferred.
The first five waves are independently reviewed, validated and committed with owner approval. **W04** is committed as `550d8b7`. Evidence is recorded in [FIRST-WAVE.md](../FIRST-WAVE.md#execution-record--2026-10-22), the [ROADMAP handoffs](../ROADMAP.md#fifth-wave-handoff--2026-10-22) and the manifest. The owner's subsequent explicit approval of ADR-002/003/004 authorizes **F01 + D01** in parallel. R01 still needs ADR-006; other consumers wait for their dependencies. Deferred work remains deferred. No sixth-wave commit/push/PR or trading operation is authorized.

View file

@ -1,37 +1,34 @@
{
"schema_version": 1,
"plan_revision": "2026-10-22.14",
"plan_revision": "2026-10-22.16",
"repository_base": "b7aeca4",
"plan_status": "fifth_wave_committed_awaiting_policy_approval",
"plan_status": "sixth_wave_validated_uncommitted",
"execution_authorized": true,
"execution_scope": {
"authorized_by": "User: commit and continue (2026-10-22); commit validated W03 and continue next-ready W04",
"authorized_by": "User: yes (2026-10-22), explicitly approving ADR-002/003/004 as written and continuation with F01/D01",
"tasks": [
"W04"
"F01",
"D01"
],
"permissions": [
"isolated_implementation",
"local_tests",
"local_integration_review",
"planning_progress_updates",
"fifth_wave_implementation_commit",
"planning_closeout_commit"
"planning_progress_updates"
],
"excluded": [
"sixth_wave_commits_without_further_approval",
"push",
"pull_requests",
"live_or_paper_operations",
"other_backlog_tasks"
],
"pending_policy_decisions": [
"ADR-002",
"ADR-003",
"ADR-004",
"ADR-005",
"ADR-006",
"ADR-007"
],
"commit_authorized_by": "User: commit and continue (2026-10-22), after W04 validated handoff",
"continuation": "Requested; no remaining scheduled task has satisfied code AND ADR prerequisites. Explicit ADR-002/003/004 approval requested before F01/D01. No policy decision or deferred activation inferred."
"ADR-007",
"ADR-008"
]
},
"canonical_metadata": "This manifest alone owns task status, dependency edges, approvals, assignments and write locks. Task Markdown owns scope and acceptance criteria. Index/roadmap are derived views.",
"decisions": [
@ -43,17 +40,23 @@
{
"id": "ADR-002",
"file": "architecture/decisions/002-financial-policy.md",
"status": "approval_required"
"status": "approved",
"approved_by": "Owner explicit yes to ADR-002/003/004 as written",
"approved_on": "2026-10-22"
},
{
"id": "ADR-003",
"file": "architecture/decisions/003-time-and-datasets.md",
"status": "approval_required"
"status": "approved",
"approved_by": "Owner explicit yes to ADR-002/003/004 as written",
"approved_on": "2026-10-22"
},
{
"id": "ADR-004",
"file": "architecture/decisions/004-strategy-boundary.md",
"status": "proposed_for_plan_approval"
"status": "approved",
"approved_by": "Owner explicit yes to ADR-002/003/004 as written",
"approved_on": "2026-10-22"
},
{
"id": "ADR-005",
@ -316,7 +319,7 @@
"epic": "E2",
"priority": "P0",
"severity": "Critical",
"status": "blocked",
"status": "review",
"dependencies": [],
"decision_dependencies": [
"ADR-002",
@ -335,12 +338,28 @@
"financial-contract"
],
"parallel_policy": "Allowed only with satisfied dependencies/approvals and disjoint write locks AND actual files; see agents/integration.md.",
"assignment": null,
"branch": null,
"assignment": "/root/wave6_f01",
"branch": "wave6/f01-financial-contract",
"pull_request": null,
"completed_commit": null,
"blocker": null,
"release_gates": []
"release_gates": [],
"worktree": "/tmp/stock-bot-wave6.uIuYHz/f01",
"integration_base": "243e9ab43f82a4b467fb90d2bd35c9ada8af41e4",
"concrete_write_scope": [
"apps/stock/engine/src/financial/",
"apps/stock/engine/src/lib.rs",
"apps/stock/engine/Cargo.toml",
"Cargo.lock",
"libs/core/types/src/financial-engine.ts",
"libs/core/types/src/index.ts",
"test/fixtures/economics/",
"test/integration/financial-contract.test.ts"
],
"integration_state": "validated_uncommitted",
"reviewed_by": "/root/wave6_review",
"verification_reference": "ROADMAP.md#sixth-wave-handoff--2026-10-22",
"review_notes": "Independently accepted, integrated, and combined gates passed. No commit authorized in this wave; awaiting owner acceptance/commit before scheduling dependents."
},
{
"id": "F02",
@ -576,7 +595,7 @@
"epic": "E3",
"priority": "P0",
"severity": "Critical",
"status": "blocked",
"status": "review",
"dependencies": [],
"decision_dependencies": [
"ADR-003"
@ -593,12 +612,26 @@
"dataset-contract"
],
"parallel_policy": "Allowed only with satisfied dependencies/approvals and disjoint write locks AND actual files; see agents/integration.md.",
"assignment": null,
"branch": null,
"assignment": "/root/wave6_d01",
"branch": "wave6/d01-dataset-v2",
"pull_request": null,
"completed_commit": null,
"blocker": null,
"release_gates": []
"release_gates": [],
"worktree": "/tmp/stock-bot-wave6.uIuYHz/d01",
"integration_base": "243e9ab43f82a4b467fb90d2bd35c9ada8af41e4",
"concrete_write_scope": [
"libs/core/types/src/historical-data.ts",
"apps/stock/orchestrator/src/data/historical-dataset-v2.ts",
"apps/stock/orchestrator/src/data/historical-dataset.ts",
"apps/stock/orchestrator/src/contracts/historical.ts",
"test/integration/historical-dataset-v2.test.ts",
"test/fixtures/historical-v2/"
],
"integration_state": "validated_uncommitted",
"reviewed_by": "/root/wave6_review",
"verification_reference": "ROADMAP.md#sixth-wave-handoff--2026-10-22",
"review_notes": "Independently accepted, integrated, and combined gates passed. No commit authorized in this wave; awaiting owner acceptance/commit before scheduling dependents."
},
{
"id": "D02",
@ -1865,7 +1898,7 @@
}
],
"review_note": "Independent skeptical revision: four superseded tasks retain stable IDs; deferred work is not a dependency of scheduled tasks. Release gates are distinct from implementation prerequisites.",
"integration_base": "95842c39d0b26dccd594279f3a632e9afe20186f",
"integration_base": "243e9ab43f82a4b467fb90d2bd35c9ada8af41e4",
"validation": {
"date": "2026-10-22",
"integration_base": "1148673",
@ -2006,6 +2039,38 @@
],
"commit_authorized_by": "User: commit and start the next wave (2026-10-22)"
}
},
{
"wave": "fifth_wave",
"scope": {
"authorized_by": "User: commit and continue (2026-10-22); commit validated W03 and continue next-ready W04",
"tasks": [
"W04"
],
"permissions": [
"isolated_implementation",
"local_tests",
"local_integration_review",
"planning_progress_updates",
"fifth_wave_implementation_commit",
"planning_closeout_commit"
],
"excluded": [
"push",
"pull_requests",
"live_or_paper_operations",
"other_backlog_tasks"
],
"pending_policy_decisions": [
"ADR-002",
"ADR-003",
"ADR-004",
"ADR-006",
"ADR-007"
],
"commit_authorized_by": "User: commit and continue (2026-10-22), after W04 validated handoff",
"continuation": "Requested; no remaining scheduled task has satisfied code AND ADR prerequisites. Explicit ADR-002/003/004 approval requested before F01/D01. No policy decision or deferred activation inferred."
}
}
],
"second_wave": [
@ -2602,6 +2667,7 @@
]
},
"continuation_readiness": {
"historical_note": "This was the fifth-wave closeout readiness check. Superseded by the owner's subsequent explicit approval of ADR-002/003/004 and the sixth-wave F01/D01 execution scope above.",
"date": "2026-10-22",
"after_commit": "550d8b769baae13f60dd22490a4e3ab42abd008b",
"remaining_scheduled_tasks": 32,
@ -2630,5 +2696,95 @@
],
"requested_approval": "ADR-002/003/004 as written before F01 financial contracts/regression fixtures and D01 availability-aware datasets; awaiting explicit owner response",
"notes": "Deferred optimization triggers remain unmet; no alternative task started. Readiness checked independently by /root/next_ready_audit."
},
"sixth_wave": [
"F01",
"D01"
],
"sixth_wave_notes": [
"Owner explicitly approved ADR-002/003/004. No other ADR approved.",
"F01 owns financial contract, Rust dependency/lockfile, types index export and economic fixtures. D01 owns dataset contracts and additive v2 normalizer/fixtures; root integrates D01 type exports to avoid index overlap.",
"Existing financial runtimes and v1 dataset hash/load semantics remain unchanged. No F02 ledger, F06 replay, F07 NAPI sessions, paper cutover or new endpoint is included.",
"Implementation in isolated worktrees; independent review and combined integration gates passed; awaiting owner acceptance/commit."
],
"sixth_wave_validation": {
"result": "passed",
"reviewer": "/root/wave6_review",
"base": "243e9ab43f82a4b467fb90d2bd35c9ada8af41e4",
"repository_check": {
"command": "CARGO_BUILD_JOBS=2 bun run check",
"log": "/tmp/stock-bot-wave6.uIuYHz/check-escalated.log",
"tooling_tests": 60,
"utility_tests": 43,
"calculation_tests": 35,
"integration_tests": 334,
"rust_tests": 44,
"failed": 0,
"note": "Initial sandbox attempt hit native spawn EPERM and worker timeouts; escalated full rerun passed. Full build/typecheck/contracts/lint/secret audit passed."
},
"final_focused": {
"command": "bun test test/integration/financial-contract.test.ts test/integration/historical-dataset-v2.test.ts test/integration/dataset-preparation.test.ts",
"tests": 35,
"assertions": 601,
"failed": 0,
"log": "/tmp/stock-bot-wave6.uIuYHz/focused-final.log",
"rust_recheck": "cargo test -p engine --lib --offline: 44 passed after JSON formatting; /tmp/stock-bot-wave6.uIuYHz/rust-final.log"
},
"author_and_independent_review": {
"financial": "9 TypeScript tests/456 assertions and 44 Rust tests independently passed.",
"dataset": "15 v2 tests/95 assertions independently passed; main-workspace legacy+v2 dataset tests:26/145.",
"native_smoke": "Author rebuilt isolated addon; 69 native compatibility tests/178 assertions passed outside sandbox. Included in combined integration gate, not additional coverage."
},
"scoped_checks": [
"Strict standalone TypeScript on both new source/test groups passed.",
"Explicit ESLint on seven new/changed TypeScript files passed.",
"Prettier check on all changed TypeScript and new economic JSON fixtures passed.",
"git diff --check passed."
],
"source_verification": {
"hashes": {
"Cargo.lock": "21aaf3923c697b0a4e464033f6127a1fffe44ee2b0fc57585f992b7445e3c69f",
"apps/stock/engine/Cargo.toml": "02b6c190ed9ebf2c5d355a3bc36264954d2d2585438da15f0250d34943654aa7",
"apps/stock/engine/src/lib.rs": "671eb892cd0ba321a77851223ccbc9ac18d80a048a30f5f280c7893aea887619",
"apps/stock/engine/src/financial/contract.rs": "67d309f3bbeae57c2744c307c76320e7e75f011f01a9c2ff5364d4668d1749a5",
"apps/stock/engine/src/financial/mod.rs": "c5c7397829043ff09e2471f327a243b7ecece7a270f9c5966466e8c52e23da4e",
"apps/stock/engine/src/financial/scalar.rs": "fdb99264f5570a0f4a8493a4a2636e7f5f2980bdf45e8c2179de3fb5ef1f2034",
"apps/stock/engine/src/financial/tests.rs": "1d3a8fb80133284eaa2aa6fb558fb40c4f563a28d098340752101852b4d9fbf7",
"libs/core/types/src/financial-engine.ts": "0c838d12b09847c4a7e3f6fc56f08f8fcfdadb50ed126106145ed67e188c8652",
"test/fixtures/economics/contracts.json": "f68913d6ca1726fb0bbd2f04391bfca0476edd570d54717225b0a47a4e11939e",
"test/fixtures/economics/ledger-specs.json": "01e174b5f619b92777fb6f735abd630249472150301df6beb9c44d7db9d868bf",
"test/fixtures/economics/scalars.json": "d7bf11525d5f293365271fb8ab47531fd395758d087736715550f53554100d87",
"test/integration/financial-contract.test.ts": "22d99809d0f56e2151975ca6d07555694b115ff8e7a76c5c0831ba63f2ca486d",
"libs/core/types/src/historical-data.ts": "577a453ea1c4f1938deeaeba8746a9a8643d9cbb6d27665347828fade2a72895",
"apps/stock/orchestrator/src/data/historical-dataset-v2.ts": "1ff26166cf1492cfac946145f5f27c2a7f0b5cde188c44cdd6a17a93c5a766fa",
"test/integration/historical-dataset-v2.test.ts": "c8dba1b7a91c8699ef2a8a58f04005666e92eacdb8433af471a9da1b571331d0",
"test/fixtures/historical-v2/dataset.ts": "3559566eee87175ee03042c66ea45c6d0e166b6627de838c96a510d702196b36",
"libs/core/types/src/index.ts": "b2ff7c8d423d3c37379a94d5d1aaa6a80581a19df7f628958b36fe972360527d"
},
"exceptions": [
"types/index.ts intentionally merges financial and v2 dataset exports; build and types tests cover the merged file.",
"Cargo.toml preserves original CRLF/no-terminal-newline formatting; normalized TOML text matches reviewed source.",
"contracts.json and ledger-specs.json are Prettier-normalized; parsed JSON equals reviewed fixtures, followed by Rust/TS reruns."
]
},
"native_artifact": {
"path": "apps/stock/engine/dist/engine.node",
"sha256": "33fafb4ff0d783f3bfd675c6a5d7922e2939dd296f9c63e98bc1eec464e19c7f",
"author_worktree_sha256": "179df84c0e553265e9908086b512a19902a32ff556a3c2a17307645c43e32618",
"note": "Both built locally from their own worktrees; no addon copied across worktrees."
},
"not_run": [
"PostgreSQL/Redis fixture suite and Chromium E2E not rerun in this additive contract-only wave; no SQL/API/UI or active-runtime cutover changed.",
"No throughput certification; optional author synthetic normalizer timing was exploratory, not a repeatable benchmark claim."
],
"limitations": [
"Financial projection is not a restorable session. F02 owns ledger transitions, dedup receipts and operation-specific exact basis arithmetic; F04/F06/F07 own risk/replay/sessions.",
"Dataset v2 remains an additive API, not active storage/replay integration. Explicit calendars are caller-supplied; partial-session intraday bars are unsupported; unknown coverage remains exploratory.",
"Retained v1 datasets and current financial runtimes are unchanged. No full backtest economic-correctness claim follows from these tests.",
"Initial isolated library builds encountered existing browser/logger ordering resolution and stock-config dependency prerequisites; scoped builds/retries passed, no build-system fix claimed.",
"Existing Rust/frontend build warnings remain."
],
"cleanup": "Only verified stale sandbox check/test/worker processes were stopped after the successful escalated run; root session13178 exited143 and author session45451 exited143. No user services, databases, containers or files were removed. Worktrees/logs remain available.",
"handoff": "F01/D01 remain review/validated_uncommitted; F02/D02 await accepted integration and further execution authorization. No sixth-wave commit, push, PR, trading operation or other task started."
}
}

View file

@ -18,6 +18,12 @@ Measurable benefit: Defines point-in-time truth before new replay logic.
Absorb D03 in the same manifest version: record universe/as-of and corporate-action coverage, distinguish signal-adjusted from raw execution prices and retain limitations. Do not build an action feed or a correctness-gate evidence subsystem. Known unsupported action ranges reject executable policy; unknown coverage stays explicitly exploratory, never silently verified.
### Sixth-wave scope clarification
Implement a separate additive v2 normalizer; leave the existing v1 loader, persisted snapshots, SQL, APIs and runtime unchanged. Callers supply source/revision-labelled UTC session tables with an IANA time zone; never infer an exchange from a symbol suffix or weekdays. Initially accept only full-duration intraday bars contained within a session; partial-session bars are unsupported. Explicit availability and interval-end assumptions remain distinct and hash-retained.
Verify the original hash before converting v1 and retain it as the parent hash. Converted VWAP is unknown because v1 cannot distinguish provider VWAP from a synthesized value. Unknown universe/action coverage stays exploratory, including after executable-policy validation; validation is not research certification. Trade-end bars remain available for terminal marking, while later replay enforces the half-open decision window. Prefix tests here prove normalization stability, not the future F06 replay gate.
## Exclusions
No unrelated refactor, new service or broker activation.

View file

@ -14,6 +14,12 @@ Scheduling source of truth: [manifest entry F01](../manifest.json). No task is a
Define only the contracts consumed by the first financial vertical slice: scalar posting rules, owner IDs, account risk-session boundary, commands/effects, snapshot version and stable decision identity. Use a maintained checked decimal implementation, not bespoke arithmetic. Absorb C05: add small hand-derived JSON/table fixtures beside their consumers, without a reference simulator or an expected-failure test campaign. Freeze the TS/Rust command/context shape before consumers implement it.
### Sixth-wave scope clarification
The additive contract separates strategy intents from engine-internal fill/mark/session commands. The snapshot is an economic projection, **not** a complete recoverable session. Full observation contexts, sessions and native bindings remain F06/F07 work; this task must not introduce a second executable engine.
The maintained decimal wrapper provides checked ingress, fixed-8 posting, addition and subtraction. Generic multiplication/division are intentionally absent: intermediate rounding needs operation-specific F02 tests, especially proportional basis release. Remaining-basis and command-conflict fixtures are hand-derived F02 specifications, not claims of implemented ledger or deduplication behavior. TypeScript validates wire shapes and canonical decimal strings only; it does no financial arithmetic.
## Exclusions
No unrelated refactor, new service, broker enablement, or silent reinterpretation of historical results.
@ -37,7 +43,7 @@ Parallel eligibility: only with disjoint actual files and reserved write locks;
## Acceptance criteria
- Financial postings use8 decimal places with explicit round-half-away-from-zero at ties (matching current TS half-up behavior); reject overflow/non-finite/excess-precision external commands. Float observations/features are not converted into money strings on every native crossing.
- Financial postings use 8 decimal places with explicit round-half-away-from-zero at ties (matching current TS half-up behavior); reject overflow/non-finite/excess-precision external commands. Float observations/features are not converted into money strings on every native crossing.
- Authoritative basis is remaining cost amount, not rounded average price. Fixture buys3 shares for total5; partial/final disposals release exactly5 basis in total.
- Stable protocol snapshot/command serialization and unknown-version rejection pass small Rust/TS contract fixtures; scope is one supported version, not a compatibility-negotiation framework.
- Each regression fixture lists economic assumptions, hand calculation and owning task. Each implementation task adds its own passing regression coverage; do not merge a blanket failing suite.