stock-bot/docs/development/backlog/tasks/C02.md

2.9 KiB

C02 — Reject malformed native data and preserve milliseconds

Parent epic: E1. Priority/severity: P1 / High. Relative complexity: S. Recommended specialization: Rust/NAPI boundary.

Scheduling source of truth: manifest entry C02. 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

Validate all input rows before admission; return row-indexed errors instead of filter_map dropping rows. Preserve epoch milliseconds, reject non-finite/invalid OHLC and duplicate conflicting identities.

Measurable benefit: Stops silent dataset corruption.

Exclusions

No unrelated refactor, new service, broker enablement, or silent reinterpretation of historical results.

Likely files and ownership

  • apps/stock/engine/src/api/backtest.rs
  • test/integration/ingestion-backtest.test.ts

Write locks: native-public-api. 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.

No additional economic-policy approval is needed for this narrowly scoped task.

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

Acceptance criteria

  • One invalid row causes an atomic load failure with its index; valid neighbors are not partially installed.
  • Events at 1001ms and 1999ms remain distinct and ordered; unknown data types fail explicitly.

Mandatory tests

  • Native bridge tests invalid OHLC/NaN/missing field/unsupported type and sub-second round trip.
  • Existing native load fixtures remain accepted.

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

Financial or compatibility regression; preserve existing fixtures and version changed semantics. 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.