stock-bot/docs/development/backlog/tasks/D01.md
Boki b4af840d4e 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.
2026-10-22 20:51:25 -04:00

5.6 KiB

D01 — Introduce availability-aware dataset v2

Parent epic: E3. Priority/severity: P0 / Critical. Relative complexity: M. Recommended specialization: TypeScript trading infrastructure.

Scheduling source of truth: manifest entry D01. No task is authorized until the plan is approved. Dependencies and decision references below describe the design; the manifest controls current readiness.

Evidence and root cause

Intended behavior and implementation scope

Add interval start/end, availableAt, venue/calendar revision and source sequence to frozen events; preserve missing VWAP as missing. Keep v1 snapshots immutable. Convert daily session labels only with an explicit versioned calendar; fail closed for unknown venue/time semantics. Include per-series identity/timeframe so a run can select exactly one execution feed per instrument and separate feature-only series.

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.

Likely files and ownership

  • libs/core/types/src/historical-data.ts
  • apps/stock/orchestrator/src/data/historical-dataset.ts
  • apps/stock/orchestrator/src/services/StorageService.ts

Write locks: dataset-contract. One agent owns this change. Lock names do not override actual overlapping files.

Dependencies and blockers

No code prerequisite. Global execution approval and write-lock acquisition still required.

Architecture decisions: ADR-003. Agents may not independently amend their policies.

Parallel eligibility: only with disjoint actual files and reserved write locks; read FIRST-WAVE.md for the initial exact ownership boundaries.

Acceptance criteria

  • A new manifest/hash is produced for every conversion; v1 hashes still verify.
  • US daily bars become available at actual session end, including DST and half days; invalid/duplicate conflicts reject.
  • Warmup and trade ranges are separate, with no invented VWAP or interpolation.

Mandatory tests

  • dataset_v1_compatibility, dataset_v2_hash, DST_half_day, missing_vwap, conflicting_duplicate.
  • Future-suffix mutation does not change prior observable prefixes.

Apply the relevant quality gates; submit exact commands, outcomes and skipped checks. Named cases above are required regression scenarios, not claims that those tests already exist.

Regression risks and rollback

Compatibility or lifecycle regression; preserve frozen inputs, old results and existing failure tests. Keep migrations additive and previous results readable. Do not add a switch that restores a correctness defect. Versioned cutover/migration is required only when persisted contracts or active engines change; never silently fall back to old economics.

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.