feat(research): download original canonical run results (RP08)

This commit is contained in:
Boki 2026-10-27 12:34:15 -04:00
parent 8e9d0cf619
commit e8a6b70968
8 changed files with 245 additions and 13 deletions

View file

@ -90,6 +90,42 @@ Rust returns financial facts, including orders, fills, positions and valuation.
`BacktestRunner` validates the result and commits it through [`PostgresBacktestRunRepository`](../../apps/stock/orchestrator/src/backtest/PostgresBacktestRunRepository.ts). Completion notifications follow persistence. The browser's [CanonicalResults](../../apps/stock/web-app/src/features/backtest/components/CanonicalResults.tsx) and [ResultProvenance](../../apps/stock/web-app/src/features/backtest/components/ResultProvenance.tsx) render this saved record. Reloading the page reads the same run; it does not rerun the simulation. WebSocket updates help refresh the display, but the database owns status and results.
### Take the result into a notebook or local AI workflow
Open a completed canonical run and choose **Download run result**. The file,
`run-<runId>.json`, contains the complete result already displayed, including the original
request. Changing the backtest's editable settings does not change an earlier run's file.
Downloading makes no additional API request and neither saves settings nor submits a run.
Useful fields for exploration:
| Field | Contents |
| --- | --- |
| `request` | Original dataset hash, strategy package/parameters, execution policy and engine/build identity. |
| `financial.projection` | Native fills and terminal valuation. |
| `financial.view` | Native orders, account and strategy-owned position views. |
| `financial.reporting` | Evaluation bounds, session samples and reporting policy. |
| `analytics` | Metrics, unavailable-value reasons and statistical assumptions. |
For a quick inspection with Bun:
```ts
const result = await Bun.file('/path/to/run-<runId>.json').json();
console.log(result.runId, result.request.datasetHash);
console.table(result.financial.projection.fills);
console.log(result.financial.projection.valuation, result.analytics.unavailable);
```
Financial decimal strings and null metric values remain unchanged; chart rounding is not
exported. Keep null reasons when comparing runs instead of treating missing metrics as zero.
Pair the result with its [retained dataset download](../backtest-datasets.md#downloading-a-retained-snapshot-for-local-exploration)
to explore observations and outcomes in VS Code, notebooks or local AI tools.
This is an analysis record, not a self-contained replay archive or an upload format. Bars
and engine binaries are separate; use **Reproduce original run** for the existing retained
execution path. The JSON includes the retained strategy JavaScript as text and never executes
it during download or JSON inspection. A local download failure offers **Retry run result download**.
## 6. Retry, cancel and reproduce are different operations
| Operation | What to expect |