feat(engine): add canonical risk and order matching
This commit is contained in:
parent
b65acccd91
commit
ccf333cc0a
13 changed files with 5129 additions and 36 deletions
|
|
@ -1,8 +1,8 @@
|
|||
# Revised development roadmap
|
||||
|
||||
Baseline `b7aeca4` · reviewed 2026-10-22 · **First six waves committed; F02/D02 validated, uncommitted**
|
||||
Baseline `b7aeca4` · reviewed 2026-10-22 · **F04/F05 independently reviewed and validated, uncommitted**
|
||||
|
||||
Authorization update: after explicitly approving ADR-002/003/004 and the validated F01/D01 implementation, the owner requested “commit and continue.” F01/D01 are committed as `b4af840`; F02/D02 were independently reviewed, integrated and validated from isolated worktrees. No other ADR is approved. Seventh-wave commits, pushes, PRs and trading operations remain outside scope.
|
||||
Authorization update: the latest owner request “do it” authorizes the explicitly proposed F05 continuation on accepted, independently reviewed and validated F04. No commit was requested: F04's exact source is applied as an explicit prerequisite overlay to F05's isolated worktree based on `b65accc`. No other ADR is approved. Commits, pushes, PRs and trading operations remain outside scope.
|
||||
|
||||
## Strategy and review outcome
|
||||
|
||||
|
|
@ -190,7 +190,7 @@ Existing v1 snapshots and financial runtimes remain unchanged. F01 is not a work
|
|||
|
||||
## Seventh-wave handoff — 2026-10-22
|
||||
|
||||
F02/D02 are independently accepted and `review` / `validated_uncommitted`. Base `b4af840`; isolated worktrees under `/tmp/stock-bot-wave7.UIkAQD/`. Financial and data owners implemented in parallel; an independent reviewer checked both; root integrated all ten reviewed files with matching hashes.
|
||||
F02/D02 were independently accepted and subsequently committed as `b65accc` at owner request. Base `b4af840`; isolated worktrees under `/tmp/stock-bot-wave7.UIkAQD/`. Financial and data owners implemented in parallel; an independent reviewer checked both; root integrated all ten reviewed files with matching hashes.
|
||||
|
||||
- **F02:** Owner-keyed quantity, remaining basis, realized P&L and fees; exact rational intermediates rounded once into the maintained decimal posting type. Fee-inclusive funding, wrong-owner disposal, overflow and identity conflicts reject atomically. Command/fill aliases return original replay-labelled receipts, including after intervening operations. Explicit market marks remain separate from fill prices; owner-level marked postings reconcile to account equity. Same-session boundary repetition is an accepted no-op, not a false session-change effect. Ledger-only checkpoints retain and validate ordered receipts by replay; ordinary transitions touch only affected state.
|
||||
- **D02:** Existing EOD `1m`/`5m`/`1h` Mongo collections now feed the common research storage admission path. Unix-second timestamps/listing identities validate; supported-provider capability reports distinguish configuration/connectivity from coverage. Default QuestDB priority remains, explicit provider selection is available at the storage API, and missing/error ranges never switch to daily/synthetic data. Real writer/read/normalizer composition and repeated legacy native runs are tested on synthetic provider records; HTTP/Mongo transport alone is replaced.
|
||||
|
|
@ -206,7 +206,36 @@ The manual release measurement also passed on the final integrated checkout (1 t
|
|||
|
||||
Limits: no F04 reservation/portfolio-risk policy, matcher, F06 replay, native session API, SQL/paper cutover, order/strategy/RNG session restoration or canonical-engine release. D02's provider selector is not a web/run-configuration control; no Mongo server-conformance, range-completeness or live-availability claim. Provider delayed-finalization caveats and the explicit bar-close simulation assumption are retained in the task evidence. PostgreSQL/Redis and Chromium suites were not rerun because their persistence/API/UI boundaries did not change. Existing build warnings remain.
|
||||
|
||||
Only exact identified stalled D02 sandbox test/worker processes were terminated after the successful escalated rerun; no development services/data were changed. Worktrees and logs remain available. The sixth-wave commit was made as requested; no seventh-wave commit, push, PR or trading operation occurred. Next after acceptance/commit: **F04 central cash reservations and portfolio risk enforcement**. Product/AI work remains subject to its unapproved ADRs.
|
||||
Only exact identified stalled D02 sandbox test/worker processes were terminated after the successful escalated rerun; no development services/data were changed. Worktrees and logs remain available. The subsequent owner request authorized the seventh-wave commit and **F04 central cash reservations and portfolio risk enforcement**. No push, PR or trading operation occurred. Product/AI work remains subject to its unapproved ADRs.
|
||||
|
||||
## Eighth-wave handoff — 2026-10-22
|
||||
|
||||
F04 is independently accepted and `review` / `validated_uncommitted`. Base `b65accc`; isolated worktree `/tmp/stock-bot-wave8.pKzr7p/f04`. One owner implemented five financial files, two read-only reviewers accepted them, and root integrated exactly matching hashes. See [execution policy clarifications](backlog/tasks/F04.md#execution-policy-clarifications).
|
||||
|
||||
- **RiskAccount** privately owns the existing Ledger. Explicit and target-derived normalized orders share funded admission; strategy-owned sells cannot borrow inventory or credit anticipated proceeds. Fill-time checks account for other reservations, adverse gaps and split-fill rounding; rejection releases the remainder without changing prior fills. Commission is computed from exact quantity × price × rate, rounded once.
|
||||
- Portfolio quantity/exposure uses owner-book rounding, including pending buys. Increasing risk requires fresh marks across held/pending assets. Reductions remain possible during stale data and marked-loss halts. Explicit account boundaries reset daily state only; drawdown peak/halt persists through rollover and restore. Instance-bound operator reset records its baseline, separate from strategy input.
|
||||
- Recorded accepted/rejected outcomes and fill aliases replay without reapplying effects or moving the clock. Checkpoints reconstruct and verify risk/ledger state, reservations and receipts. Overflow/malformed internal commands remain atomic errors, not ordinary risk rejections. Future adapters must honor the outer replay flag before publishing nested financial effects.
|
||||
|
||||
Validation: `CARGO_BUILD_JOBS=2 bun run check` passed build/types/contracts/lint/audit plus 60 tooling, 43 utility, 35 calculation, 342 integration and 77 Rust tests. Independent risk suites passed 18 cases; the broader financial suite passed 40 (overlapping totals). Two manual benchmarks are excluded from ordinary Rust runs; the new risk release benchmark was separately executed successfully in both author and integrated checkouts. Scoped rustfmt, diff checks and manifest DAG/readiness validation passed. Existing repository-wide rustfmt and planning-manifest Prettier style deviations were confirmed outside this change's formatting scope; no unrelated formatting rewrite.
|
||||
|
||||
The narrow release workload uses 1k/10k prebuilt mark/admit/partial-fill/release commands, three repeats, one active owner/asset or two active owners/four assets. Full checkpoint/outcome bytes and restored checkpoints match. Integrated 10k transition time was approximately 42–45ms single and 55–56ms multi, excluding build/loading/serialization; checkpoint and restore are measured separately. Only zero/one live reservation is exercised. This is not full backtest throughput or a scaling guarantee: normal risk checks scan retained book keys and live commitments with ordered-map costs; retained journal memory/restore work grows with history. Raw commands, logs, artifact/source hashes and measurements are in the manifest.
|
||||
|
||||
Limits: active legacy engines unchanged; no F05 matcher, target expansion/mode coordination, limit/TIF/capacity eligibility, F06 calendar/replay, F07 native sessions, paper/SQL cutover or full strategy/replay/RNG recovery. Operator capability is API separation, not untrusted-code security. PostgreSQL/Redis, browser and Python suites were not rerun because those boundaries did not change. No services/data were removed. No new-wave commit, push, PR or trading operation. Next after acceptance/commit: **F05 matching and order lifecycle on the canonical ledger/risk facade**; replay release remains gated by F06.
|
||||
|
||||
## Ninth-wave handoff — 2026-10-22
|
||||
|
||||
F05 is independently reviewed and `review` / `validated_uncommitted`. Its isolated worktree `/tmp/stock-bot-wave9.P8EKsc/f05` uses base `b65accc` plus the five exact F04 prerequisite files. The owner accepted continuation without requesting a prerequisite commit. One financial owner implemented; execution and quant reviewers accepted the final source; root integrated exactly matching hashes. See [F05 execution policies](backlog/tasks/F05.md#execution-policy-clarifications).
|
||||
|
||||
- **MatchingAccount** privately owns RiskAccount, with no competing ledger, fee or funding logic. Open-only and quote execution have explicit spread/slippage rounding, limit crossing, latency, session eligibility and shared liquidity. IOC/FOK/DAY/GTC transitions, partial fills, cancellation, rejection and terminal cancellation are deterministic. No synthetic end-of-run liquidation is introduced.
|
||||
- Owner-scoped absolute targets account for holdings and live commitments. Omitted assets remain unchanged; repeated targets preserve partial orders. Changed targets cancel only the owner's relevant commitments before risk-checked replacement. Declared target-array order is priority, not an atomic portfolio rebalance. Target and explicit-order modes cannot be mixed for an owner.
|
||||
- Structural batch validation precedes mutation. Physical execution identity prevents capacity reuse under changed delivery keys; delayed quotes retain their physical time and cannot fill orders that were not yet eligible. Exact retries replay original receipts without republishing nested effects. Checkpoints reconstruct matching, risk and ledger state. Unexpected numerical failure records the committed prefix and makes the attempt terminal; adapters must fail the run, never publish successful metrics from that prefix.
|
||||
- Admission uses a coordinator revision, distinct from the nested ledger snapshot revision. F06 must honor that token, physical event timing and failure contract; it must not restamp missed opens. Full replay/strategy/RNG session restoration remains later work.
|
||||
|
||||
Combined validation: `CARGO_BUILD_JOBS=2 bun run check` passed build/types/contracts/lint/audit plus 60 tooling, 43 utility, 35 calculation, 342 integration and **106 Rust tests**, zero failures. The 29 matching regressions also passed independently in both reviews (overlapping totals). Three manual benchmarks are ignored by the ordinary Rust suite; the new matching release measurement passed separately in both author and integrated builds. Scoped rustfmt, diff checks and final manifest/source verification passed.
|
||||
|
||||
The narrow release workload uses 1k/10k execution events and fills, each preceded by a submit (2k/20k coordinator commands plus setup), over one owner/asset or two owners/two assets, with three repeats. Integrated 10k apply time was 214–235ms single and 234–238ms multi. Apply includes fixture construction/assertions/outcome collection; checkpoint copying is separate, and restore includes cloning its checkpoint input. Serialization is outside these timers. Exact economics, checkpoint/outcome repeatability and restored checkpoint equality are asserted. Serialized checkpoint plus returned outcomes are approximately 12.6MB/128MB at 1k/10k; this is not RSS. Retained journals grow with history. These are component measurements, not end-to-end backtest throughput, a speedup claim or a reason to introduce caching/compaction prematurely. Full raw rows and artifact/source identities are in the manifest.
|
||||
|
||||
Limits: active legacy simulator and NAPI unchanged; no replay scheduler, paper/SQL cutover or full session restore. Checkpoints validate consistency, not authenticity or arbitrary-code security. PostgreSQL/Redis, browser and Python suites were not rerun because their boundaries did not change. Existing build warnings remain. No services/data removed; worktree/logs retained. **F04/F05 remain uncommitted. Next after acceptance: F06 deterministic availability-aware replay**, still the release gate for this matcher. No commit, push, PR or trading operation occurred.
|
||||
|
||||
## Deferred and rejected
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue