29 lines
3.1 KiB
Markdown
29 lines
3.1 KiB
Markdown
# ADR-005 — Shared kernel, distinct persistence boundaries
|
|
|
|
Status: **approved by owner continuation, 2026-10-23**. After the handoff named S01 and linked this pending decision, the owner instructed “commit all of it and continue.” This approves the documented direction for the next task; paper migration/default activation remain separately gated. Preservation of existing recovery is required.
|
|
|
|
## One implementation
|
|
|
|
Use one internal Rust `apply(state, command) -> effects` financial kernel.
|
|
|
|
- Research keeps state resident and applies events directly. Do **not** serialize, clone or rehydrate a full account snapshot per observation.
|
|
- Paper loads the committed snapshot into private staged native state inside the existing SQL transaction, invokes the same kernel, persists snapshot/orders/fills/ordered journal effects atomically, commits, then publishes. Failed SQL work discards the staged state.
|
|
- Snapshot encoding is a boundary operation, not the hot-loop algorithm. Exact per-effect views remain available where the existing recovery journal requires them; do not replace them with a final batch state.
|
|
|
|
TS owns SQL custody, not independent accounting. No native/DB two-phase commit and no new event-sourcing framework.
|
|
|
|
## Decision durability
|
|
|
|
Preserve [restore-before-each-step and intent transactions](../../../../apps/stock/orchestrator/src/execution/StrategyRecovery.ts#L151), [account locks and duplicate/conflict handling](../../../../apps/stock/orchestrator/src/execution/PostgresExecutionRepository.ts#L46), and existing failure tests. Paper strategy contexts use committed event views; never substitute a later account state. Restore RNG/decision cursors along with checkpoint state.
|
|
|
|
All currently supported paper order policies must be preserved or a migration explicitly refused. F05 covers market/limit and DAY/GTC/IOC/FOK; do not silently drop IOC/FOK at cutover.
|
|
|
|
## Migration
|
|
|
|
C06 contains unsafe legacy research/paper composition; it does not build a temporary second worker framework. F02 builds owner accounting once. S03 adopts the kernel and durable recovery without waiting for Sharpe/Sortino or web pages. S04 verifies paper feed/readiness. S06 retires competing active execution after those gates, retaining result readers/research algorithms.
|
|
|
|
Compare financial transitions for the **same event and intent trace**. Research and paper receive different real-world prices/availability; identical P&L is not promised for different inputs. Broker fills remain future external facts to reconcile, not simulated orders that can be rejected after occurrence.
|
|
|
|
## S01 retry scope
|
|
|
|
The existing durable research runner retries whole attempts. S01 follows that boundary: create a fresh native session from frozen data/configuration, clone original strategy states and restore original per-owner seeds, then recompute observations, decisions and RNG cursors. Per-barrier TypeScript diagnostic snapshots are not independently resumable financial checkpoints. Do not add a native checkpoint wire or accept a TS-only mid-run resume merely for S01. Existing Rust checkpoint reconstruction and paper SQL checkpoints remain preserved; S03 owns their durable integration.
|