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

19 lines
4.5 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# RP03 — Prepare stored data from explicitly declared sessions
Parent: E12. Priority P1 / High. Complexity M. Owner continuation authorizes this next research-product slice; optional performance work stays deferred. Dependencies: RP01 and D01. ADR-003/006 remain unchanged.
Problem/evidence: `apps/stock/web-api/src/services/stored-dataset-preparation.ts` reads one continuous warmup-to-end range before strict OHLCV validation. Interior after-hours null-volume rows therefore block multi-session preparation. RP02 avoided the issue with one session. The existing v2 dataset/calendar and Rust replay already support multiple sessions; `StorageService` must remain strict.
Contract: preserve `{metadata}` and its current response. Opt in with `{metadata, selection: "declared-sessions"}` at the existing stored-source endpoint; its response adds the same selection literal alongside unchanged captured `input` and `preparation`. No new dataset hash format or database migration. The calendar plus captured bars remain replay provenance; selection describes how source rows were captured.
Scope: one series/provider as today. Intersect the selected series' declared calendar sessions with `[warmupStart, tradeEnd)`, read each nonempty window sequentially through the strict reader, validate against that individual window, snapshot values before another await, combine and assign deterministic global ordinals. Empty selected sessions fail; invalid selected rows abort the entire preparation. An interval crossing the declared close fails normalizer validation; never shrink the query to hide it. Check aborts between reads. No interpolation, post-filtering, calendar inference, source writes, new caps/cache or financial-policy changes. Sparse nonempty sessions retain existing semantics; do not claim complete coverage.
Web scope: a third input choice, "Stored EOD — declared sessions only", reuses metadata upload, preview and captured-input retention. Show the explicit session scope and intersected UTC windows. Verify the echoed response selection; reject missing/wrong mode. Existing loading/error/empty states and mode-change cancellation apply. An unresolved retention receipt locks the input/mode and retries the same input/hash without source reads. Inspector diagnostics remain independent and do not establish calendar coverage.
Likely files/locks: `apps/stock/config/src/contracts/canonical-research.ts`, `apps/stock/web-api/src/services/stored-dataset-preparation.ts`, `apps/stock/web-app/src/features/backtest/services/backtestApiV2.ts`, `.../components/DatasetPreparation.tsx`, focused stored-preparation API/UI tests. Root owns backlog, documentation, integration and browser test file. One implementation owner; disjoint from RP04.
Acceptance/tests: unchanged default query/output; two sessions with an intervening invalid close marker succeed only in explicit session mode; selected null/OHLC/identity/duplicate errors and missing sessions fail; per-window out-of-range adapter results fail; DST, early close and clipped bounds use declared instants; partial bars fail; metadata/earlier-row mutation cannot affect captured results; abort prevents later reads; repeated same capture has the same v2 hash; wrong response mode and late replies fail; retention retry never rereads. Extend the real browser preparation workflow. Validate a read-only actual stored multi-session preview against exact selected source rows; no new research execution is required.
Gates: focused regressions, types/strict lint, full repository check, relevant disposable PostgreSQL retention tests and Chromium workbench. Independent backend/frontend acceptance before completion. Risk: hiding source defects outside incorrectly declared sessions or implying gap-free data; declarations remain explicit and unverified by the UI.
Accepted October 27, 2026: explicit session-window capture and its web workflow are implemented with unchanged default behavior and dataset identity rules. Independent backend/frontend reviewers accepted. Root passed the full repository check, 14 relevant PostgreSQL tests and all 20 Chromium scenarios. Actual read-only AAPL October 1–2 preparation captured 156 unchanged bars with identical repeated hashes; the continuous query still rejects its interior null-volume marker. No real dataset retention or research run was performed. [Combined evidence](../../real-data-research.md) records scope, hashes and limitations; [usage](../../../backtest-datasets.md#stored-eod-preparation-across-declared-sessions-v2) explains the explicit selection.