4.9 KiB
RP19 — Show retained final risk state in research results
Parent E12. Priority P2 / Medium interpretation gap. Complexity S. Dependencies W03 and RP18. Owner's “commit and continue” authorizes this follow-up and validated commits. One frontend implementer owns CanonicalResults.tsx and its workbench component tests; root owns browser integration and planning state. Independent review required.
Verified evidence: apps/stock/web-app/src/features/backtest/components/CanonicalResults.tsx displays valuation, sampled metrics and policy JSON but never reads financial.view.risk. An independent actual-result render probe (/tmp/stock-bot-post-rp18-result-audit.tsx) produces identical HTML when both flags are flipped in each of the three retained cost scenarios. The validated result already supplies those fields through apps/stock/config/src/contracts/canonical-replay.ts and the existing result endpoint. RP18's baseline and stressed-cost results have drawdownHalted: true; understanding why their paths differ currently requires downloading JSON. The cost experiment already explains independent execution and retained spread; do not duplicate it.
Scope: add a compact, read-only Final risk state section to the canonical result overview, using only the retained financial view and policy. Show daily-loss and drawdown halt flags, their exact monetary limits, daily equity baseline, peak equity, risk session identity/start and last processed risk-event time. Use existing currency/time formatting and exact native decimal strings. A true flag means risk-increasing orders are halted at that snapshot; a false flag is not proof that no earlier halt or other rejection occurred.
Explain the snapshot's limits: daily-loss state can reset at an account risk-session boundary; price recovery alone does not clear a latched drawdown halt. The last event time is not a first-halt timestamp. Compact results do not supply halt history or rejection counts. Do not derive halt state from sampled drawdown, final equity or trade counts. Keep loaded-result rendering synchronous with no extra requests or mutable template lookup.
Exclusions: API/schema/database/native changes, risk resets or new controls, financial calculations, event/rejection journals, new research runs, paper/live activation, strategy changes, performance work and broad result-page refactoring. Existing parent loading/error behavior and legacy result views remain in place; an empty fill list must not hide retained risk facts. The existing fills-only view remains focused on fills.
Acceptance and mandatory tests:
- Overview renders both flags and exact retained limits/baselines, session and timestamp for a completed canonical result. Clear state labels distinguish active-at-end from inactive-at-end.
- Component regressions cover neither/either/both flags, a latched drawdown despite recovered terminal equity, final daily state after a session reset, an empty fill list and switching between runs without stale risk details. Assert no extra API request, no mutation of the result and no inferred halt timestamp/rejection count. Existing downloads, metrics and fills-only tests still pass.
- A disposable PostgreSQL/Redis/native browser fixture completes a real halted run, opens its saved result, checks the displayed flags/limits against retained Rust output, reloads it, and also verifies a non-halted result. Viewing/reloading adds no runs or dispatches and does not change saved financial results. Existing same-flow browser scenarios remain valid.
- Focused component tests, application/authored-test types, scoped lint/formatting, repository check and relevant real browser integration pass. No new economic policy tests are needed because financial semantics are unchanged.
Regression risk: presenting final false flags as historical absence, labeling the last processed event as a halt timestamp, or implying all orders must stop when exposure-reducing orders remain permitted. Review wording against risk.rs (increase_check, observe_equity, risk-session boundary handling). Preserve the existing distinction between authoritative native risk and sampled research analytics.
Implementation agents work in an isolated branch/worktree. Root integrates the narrow diff after baseline/focused validation, runs combined gates and records evidence in real-data-research.md before marking the task done. All seven conditional tasks remain deferred.
Accepted October 27, 2026: planning 7a86b15e, implementation e6616fdc. Independent review passed 48 component tests / 445 assertions. Root full repository check passed (1,378 integration, 150 Rust tests); four relevant browser scenarios passed 91 assertions with disposable stores. Types, lint, formatting and diff checks passed. Execution evidence records baseline failures, the restricted-check and browser-build setup corrections, and final gates. No financial semantics or stored research data changed.