8.4 KiB
R05 — Freeze complete provenance and cut over durable canonical runs
Parent epic: E6. Priority/severity: P0 / Critical. Relative complexity: M. Recommended specialization: Full-stack research product.
Scheduling source of truth: manifest entry R05. 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
- WEB-04 — Verified: Existing results snapshot configuration and datasets but do not capture an immutable strategy artifact/engine build/model/seed bundle. Legacy projection can fall back to mutable definition fields. libs/core/types/src/backtest-run.ts:4; apps/stock/web-api/src/services/backtest-result.ts:107.
- KEEP-02 — Verified: Preserve frozen/hash-verified historical snapshots and fenced durable runner attempts; extend them instead of creating a second job engine. apps/stock/orchestrator/src/data/historical-dataset.ts:98; apps/stock/orchestrator/src/backtest/BacktestRunner.ts:190.
- FIN-05 — Updated after S01/S02/F08: Canonical TypeScript decisions on Rust sessions and canonical reports already exist. The durable runner still calls the legacy
runBacktestpath; the canonical worker constructs the current built-in implementation by identity. R05 must connect retained executable identity and canonical results to durable admission, not introduce another strategy engine. native-worker.ts:26, strategy-runtime.ts:224, canonical-result.ts:37, BacktestRunner.ts:191.
Intended behavior and implementation scope
Freeze strategy/model artifact IDs, parameters, seed, code/lockfile/build hashes and execution policies at submission. For a selected frozen dataset, pin its hash immediately; for a source request, retain the immutable query and atomically attach the first prepared dataset/hash before replay begins. Expose preparing versus reproducibility-finalized state. Wire the canonical Rust session with existing registered TS strategies into the durable runner and versioned result DTO. Exact reproduction API/UI is R12.
Consume F08's additive canonical analytics/report contract here. Version the persisted/public projection so canonical fractions, genuine zero exposure and null reasons bypass legacy percentage conversion/placeholder suppression. Preserve owner books and distinguish fills from round trips. Additional position valuations needed by the UI must come from Rust or be explicitly unavailable; do not invent marks, average-price basis or unrealized P&L in TypeScript merely to satisfy the old DTO. Keep historical readers unchanged and prove reopen/render compatibility during this cutover.
R02 now saves catalog versions and validated parameters with execution blocked at API, repository and SQL boundaries. Replace those gates only for verified supported execution. Before parallel implementation, pin the executable artifact/build binding: a retained bundle hash must never certify execution of a different current createBuiltinStrategy implementation. Verify the exact executable identity before the first decision; mismatches fail closed without a legacy-name fallback. Start with a trusted built-in single-asset vertical slice, retaining candidate isolation and multi-asset policy gates. That milestone alone does not complete all R05 requirements or authorize default activation.
Measurable benefit: Creates reproducible, project-gated runs usable by humans and AI.
Exclusions
No general workflow framework, browser IDE, multi-tenant identity platform or second simulator.
Likely files and ownership
- apps/stock/orchestrator/src/backtest/BacktestRunner.ts
- apps/stock/orchestrator/src/backtest/PostgresBacktestRunRepository.ts
- apps/stock/web-api/src/services/backtest-v2.service.ts
- libs/core/types/src/backtest-run.ts
Write locks: result-contract, web-backtest-service, web-backtest-detail. One agent owns this change. Lock names do not override actual overlapping files.
Dependencies and blockers
Implementation requires F08, S02, R01, R10, D01, W03, C06 integrated.
Architecture decisions: ADR-006. 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
- Changing template, strategy source or provider history after dataset freezing cannot alter an admitted run. A source query alone is not labelled a frozen dataset.
- No strategy decision executes before artifact verification and atomic dataset binding; failed preparation remains diagnosed and retry-safe.
- A retained-version/current-build mismatch rejects before execution; successful provenance identifies the executable that actually ran. Changing the current built-in implementation cannot silently change a retained version's behavior.
- New results declare financialEngine=rust and strategyExecution separately; correctness-gate evidence requires approved engine/data gates, not a UI flag.
- Before making canonical multi-asset research the default, obtain explicit owner disposition of sequential equal-time mark risk: either accept the disclosed versioned approximation or approve a coordinated atomic-mark policy/implementation with independent fixtures. F04/F05 currently evaluate each ordered mark; F06 demonstrates offsetting simultaneous moves can latch intermediate loss/drawdown halts. A passing deterministic replay suite alone does not resolve this material modeling issue. Single-asset component work and additive native integration need not wait for this decision.
Mandatory tests
- mutate_template_after_submit, freeze_before_first_decision, frozen_seed_replay, provider_change_after_dataset_bind.
- retained_artifact_executable_binding, current_builtin_mismatch_rejected_before_decision, catalog_version_never_falls_back_to_legacy_name.
- Full durable runner restart/lease/cancel suite and result contract compatibility.
- Canonical reporting fractions/zero/null reasons, owner attribution and fill-versus-round-trip semantics survive persistence/reopen/UI rendering; existing legacy rows retain their prior interpretation.
- Multi-asset default activation rejects while the mark-policy disposition is absent; accepted policy/version/limitations are frozen in provenance, with offsetting-mark regression evidence.
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
Schema/API backward compatibility, historical provenance and UI state regression. 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.
Web/API contract and user states
- API: Run/results expose immutable request plus resolved dataset binding, provenance and preparation state. No exact-reproduce endpoint until R12.
- Backend/data dependencies: Existing request_snapshot/dataset_hash/results extended with retained provenance and engine correctness-gate evidence metadata.
- Loading/error/empty behavior: API distinguishes preparing, dataset-pinned, running, failed and completed. W02/R11 render these fields without fabricated provenance.
- User-facing completion is demonstrated by the acceptance criteria and interaction tests above; a backend-only implementation is insufficient where a UI is in scope.
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.