feat(research): prepare stored data by declared sessions (RP03)

This commit is contained in:
Boki 2026-10-27 01:07:45 -04:00
parent 302ba60e53
commit d2b78eacdf
10 changed files with 805 additions and 72 deletions

View file

@ -63,6 +63,33 @@ Historical Bun 1.2.17 sample, recorded before removal of the size-limit machiner
Results vary with machine load and garbage collection. This optional diagnostic remains
available; it does not impose input limits or change v1 content identity.
## Stored EOD preparation across declared sessions (v2)
In backtest **Settings → Prepare dataset from source export**, choose **Stored EOD —
declared sessions only** and upload the complete v2 metadata JSON. The panel displays
the selected series' declared session windows, clipped to the warmup/evaluation bounds,
in UTC. Preview reads these windows sequentially; retain saves the captured input and
hash without querying the mutable source again.
The reads are not an atomic database snapshot; the captured rows define the retained
dataset. Cancellation prevents subsequent reads/results but does not interrupt an
already dispatched Mongo query.
The existing API opts in explicitly:
```json
{ "metadata": { "...": "complete v2 metadata" }, "selection": "declared-sessions" }
```
Send this to `POST /api/v2/datasets/canonical/stored-source`. The response echoes
`selection` alongside `input` and `preparation`; retain uses that exact `input` and
`preparation.hash`. Omitting `selection` preserves the continuous-range query.
Empty selected sessions, invalid selected rows, duplicates and bars crossing a session
boundary fail preparation. Rows outside the declared windows are never read. Sessions,
corporate-action coverage and source timing remain explicit operator declarations:
successful preparation does not certify them or establish gap-free data. The source
inspector diagnoses its own selected range independently of these capture windows.
## Verification
`bun run check` includes complete-range reads without row caps, acceptance beyond the

View file

@ -15,3 +15,5 @@ Likely files/locks: `apps/stock/config/src/contracts/canonical-research.ts`, `ap
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.