perf(research): add compact replay projections and representative profiling
This commit is contained in:
parent
19e9dad68b
commit
e3bd722e31
21 changed files with 2830 additions and 130 deletions
|
|
@ -1,14 +1,14 @@
|
|||
# Revised development roadmap
|
||||
|
||||
Baseline `b7aeca4` · handoff 2026-10-23 · **F07 reviewed, validated and committed**
|
||||
Baseline `b7aeca4` · execution 2026-10-23 · **F09/P07 reviewed and validated; uncommitted**
|
||||
|
||||
Authorization update: the owner accepted and committed the reviewed F07 changes as `e3635f2` on 2026-10-23. The accompanying performance question requests assessment, not optimization implementation. No other ADR or multi-asset mark policy is approved. Pushes, PRs, trading operations and further task implementation remain outside scope.
|
||||
Authorization update: after committing F07 (`e3635f2`, completion record `19e9dad`), the owner requested performance stories and continuation. This authorizes F09 compact projections and P07 profiling, preserving existing financial semantics. F08 retains separate historical reporting work. No other ADR or multi-asset mark policy is approved; new commits, pushes, PRs and trading/default-engine operations remain outside scope.
|
||||
|
||||
## Strategy and review outcome
|
||||
|
||||
Use TypeScript for strategies, research and the web product; one Rust kernel owns money, risk, matching and replay. Preserve durable decisions/checkpoints, transactional execution, frozen datasets, reviewed calculations and failure-oriented tests.
|
||||
|
||||
The skeptical review consolidates **52 separate task definitions into 43 scheduled tasks plus 5 conditional tasks**. Four old IDs remain merged redirects, not extra work. This is a smaller delivery plan, not a smaller correctness standard. See [review findings and dispositions](REVIEW.md), [complete index](backlog/README.md) and [canonical manifest](backlog/manifest.json).
|
||||
The skeptical review established 43 scheduled tasks, 5 conditional tasks and 4 merged redirects. The measured F09/P07 additions bring the current plan to **45 scheduled + 5 conditional + 4 merged = 54 retained IDs**. See [review findings and dispositions](REVIEW.md), [complete index](backlog/README.md) and [canonical manifest](backlog/manifest.json).
|
||||
|
||||
The existing web workbench improves during engine migration. Legacy results remain labelled; fixing controls or terminal valuation does not make same-bar economics trustworthy. C06 blocks shared-runtime legacy research rather than building another soon-to-be-retired simulator runtime.
|
||||
|
||||
|
|
@ -35,7 +35,7 @@ Long-only is the approved first canonical model, not deletion of short history o
|
|||
| --- | --- | --- |
|
||||
| M0: safe interim behavior | C01/C02/C03/C04/C06; O01; P01 | Scoped terminal/funding/input fixes; failed init cleans up; shared-runtime research rejected; migration lock and honest baseline measurements |
|
||||
| M1: usable current workbench | W01–W04 | Save, submit, cancel, inspect and reopen tested in browser; unsupported controls hidden; legacy economic limitations visible |
|
||||
| M2: canonical Rust/TS research | F01/F02/F04–F08, D01, S01/S02; R01/R10/W03/C06 then R05 | Owner-aware finance, deterministic replay, one TS strategy and retained input provenance work through durable runs |
|
||||
| M2: canonical Rust/TS research | F01/F02/F04–F09, D01, S01/S02; R01/R10/W03/C06 then R05; P07 measurements | Owner-aware finance, deterministic replay, compact results, one TS strategy and retained input provenance work through durable runs |
|
||||
| M3: useful research product | R02/R03/R04/R11/R12 | Catalog/workspace/dataset selection and original reproduction; metadata/UI proceed alongside engine work |
|
||||
| M4: batch research and validation | R06–R09, P04; S05 when ready | Bounded sweeps, summary comparisons, OOS/reset-segment walk-forward and measured worker scaling; regime panels only with S05 |
|
||||
| M5: paper parity and AI research | S03/S04, A01–A04 | Recovery parity, operator readiness, isolated bounded AI experiments and evidence-linked human paper promotion |
|
||||
|
|
@ -52,6 +52,8 @@ flowchart LR
|
|||
D01[Availability-aware eligible datasets] --> F06
|
||||
P01[Existing-path measurements] --> F06
|
||||
F06 --> F07[Bounded NAPI sessions] --> S01[TS decisions] --> S02[One SMA]
|
||||
F07 --> F09[Compact financial projections] --> F08
|
||||
F07 --> P07[Representative replay profiling]
|
||||
C02[Boundary integrity] --> F07
|
||||
F06 --> F08[Canonical projections + reviewed TS statistics]
|
||||
S02 --> R05[Durable canonical runs]
|
||||
|
|
@ -271,6 +273,40 @@ Limits remain explicit: trusted host interface, not an untrusted-code sandbox; n
|
|||
|
||||
Only the two named disposable fixture containers and their recreatable synthetic data were removed; development services were untouched. Worktree/logs retained. Browser/Python suites were not rerun because those boundaries did not change. **F07 is committed. Next recommended: F08 canonical metrics/result projections**, now code/ADR-ready but not yet authorized. S01 requires ADR-005 approval. No push, PR, default cutover or trading operation occurred.
|
||||
|
||||
## Twelfth-wave handoff — 2026-10-23
|
||||
|
||||
Two focused performance stories replace a broad optimization request: [F09](backlog/tasks/F09.md) emits compact authoritative terminal values/owned fills with optional complete diagnostics; [P07](backlog/tasks/P07.md) profiles no-trade, sparse and high-turnover workloads using the existing harness. F08 consumes F09 and later adds explicit session sampling/exposure/statistical policies. No session-close values are inferred from risk baselines, and fills are not relabelled completed trades.
|
||||
|
||||
Base `19e9dad`; isolated worktrees under `/tmp/stock-bot-wave12.F9Rlh4/`. One native/result contract owner, one disjoint benchmark owner, root planning/integration and independent review. Baseline profiling was measured on F07; compact comparisons used the accepted F09 contract. Internal journals/recovery, legacy/default paths and all mark-policy release gates remain. No framework, DSL, cache, worker-pool or web-pagination expansion.
|
||||
|
||||
Both stories are independently reviewed and `review` / `validated_uncommitted`. Root integrated 14 source/test files with exact reviewed hashes. F09's accepted contract was overlaid into P07's isolated worktree before compact comparison work; neither owner independently changed the other's contract.
|
||||
|
||||
- **F09:** native `project()` returns the existing authoritative ledger valuation and actual owned fills copied from committed commands/effects. It skips replay aliases and retains separate gross cash movement and fee postings, signed owner contributions and residual cost basis. Typed serialization borrows journal facts; no checkpoint copying, financial replay or TypeScript accounting is introduced. Complete-state/identity/format/cancellation guards cover the compact path. Full `finalize()` output, defaults, internal journals and recovery are preserved.
|
||||
- **P07:** the existing harness now selects no-trade, sparse and turnover profiles with identical callback cadence, plus trace/projection/both output. It records native-finalization, decoding, validation and disposal separately. Comparisons require the same dataset, policy, strategy, artifact, terminal view and actual fill facts. Full per-format hashes remain independent; no TypeScript valuation is fabricated to compare formats. A 200,000-fill regression prevents a benchmark-only JavaScript argument-limit failure.
|
||||
|
||||
Validation: full `CARGO_BUILD_JOBS=2 bun run check` passed build/types/contracts/lint/audit, 63 tooling, 43 utility, 35 calculation, 359 integration and **136 Rust tests**, zero failures; four existing manual benchmarks remain intentionally ignored. After the final benchmark files were integrated, all **72 tooling tests / 10,184 assertions** passed. Extra strict test/script TypeScript, scoped ESLint, rustfmt and diff checks passed. Disposable PostgreSQL/Redis suites passed **58 tests / 345 assertions** before and after integration. Independent debug and integrated release native/worker checks each passed **23 tests / 198 assertions**. These focused tests overlap larger suites. No browser/Python rerun was needed for unchanged boundaries.
|
||||
|
||||
Paired release results below use identical frozen source and addon `d98308d0…`, two fresh processes with two fresh native sessions each, including reversed callback order. Numbers are median **replay/decision/finalization/disposal time**, excluding native construction and benchmark-only oracle/hash work. Bars are total across assets. Preparation/imports, whole-trial time, all phase timings, RSS, hashes and raw report paths are recorded in the manifest. This is synthetic component conformance throughput on a shared host, not durable-job latency or an isolated-host SLA.
|
||||
|
||||
| Total bars | Profile | Assets / owners | Full trace | Compact | Reduction |
|
||||
| --- | --- | --- | ---: | ---: | ---: |
|
||||
| 10,000 | No trade | 1 / 1 | 1.142s | 0.744s | 34.9% |
|
||||
| 10,000 | No trade | 10 / 2 | 0.599s | 0.296s | 50.7% |
|
||||
| 10,000 | Sparse | 1 / 1 | 1.184s | 0.835s | 29.5% |
|
||||
| 10,000 | Sparse | 10 / 2 | 0.720s | 0.419s | 41.8% |
|
||||
| 10,000 | Turnover | 1 / 1 | 2.105s | 1.467s | 30.3% |
|
||||
| 10,000 | Turnover | 10 / 2 | 2.598s | 1.804s | 30.6% |
|
||||
| 100,000 | Sparse | 1 / 1 | 11.918s | 8.097s | 32.1% |
|
||||
| 100,000 | Sparse | 10 / 2 | 7.312s | 4.245s | 41.9% |
|
||||
| 100,000 | Turnover | 1 / 1 | 21.027s | 14.821s | 29.5% |
|
||||
| 100,000 | Turnover | 10 / 2 | 26.501s | 18.743s | 29.3% |
|
||||
|
||||
Every selected comparison passed independent economic oracles, complete result repeatability and common financial equality. All six 10k diagnostic hashes also match the historical F07 baseline. That intermediate extended harness's source bodies were not retained, only their hashes, so historical timings are contextual; speedup claims use the final paired source, which is archived with all 21 changed files as measured. Final planning edits follow the measurements; application source remains identical. No 100k no-trade run is claimed.
|
||||
|
||||
At 10k turnover, output falls from **66.7MB to 9.8MB** single and **103.6MB to 19.4MB** multi. At 100k turnover it falls from 672MB/1.044GB to 98.6MB/195.8MB. Full diagnostics remain available; this is an export reduction, not deletion of retained history. Compact 10k advance/submit accounts for 70–88% of run time. Those mixed timers should be profiled before selecting another optimization. Fixture TS decisions take only 0.9–3.5%; these results do not justify a DSL. Compact schema validation and disposal remain measured costs; removing checks or recovery history is not the next step.
|
||||
|
||||
Only the two exact disposable fixture containers and their synthetic data were removed; development services were untouched. Worktrees, logs and measured-source archive remain available. No commits, pushes, PRs, default cutover or trading operation occurred. **Next after acceptance: F08 historical equity/session/exposure and versioned statistics**, with explicit sampling conventions. S01 and product/AI work retain their pending ADR gates; the equal-time multi-asset risk-mark restriction remains unresolved.
|
||||
|
||||
## Deferred and rejected
|
||||
|
||||
Conditional: shared feature cache D04; cross-trial resident datasets P03; large-detail pagination/storage P05; tiny DSL P06; expanded cross-service monitoring O02. Each has a measured/real-need trigger and is not a prerequisite for scheduled work.
|
||||
|
|
|
|||
|
|
@ -1,12 +1,12 @@
|
|||
# Canonical development backlog
|
||||
|
||||
**First eleven waves reviewed, validated and committed.** F07 was accepted and committed as `e3635f2`. Consult manifest execution_scope, [ROADMAP](../ROADMAP.md), [skeptical review](../REVIEW.md) and [first-wave handoff](../FIRST-WAVE.md). ADR-002/003/004 are approved. Other tasks/policies remain gated; the latest performance question does not authorize implementation.
|
||||
**First eleven waves committed; F09/P07 reviewed, validated and uncommitted.** F09 adds optional compact terminal/fill projection; P07 proves matching finances and measured speedups at 10k/100k bars. F08 retains historical metrics. Consult manifest execution_scope and [handoff](../ROADMAP.md#twelfth-wave-handoff--2026-10-23). ADR-002/003/004 are approved; other policies/default cutovers remain gated.
|
||||
|
||||
## One source of truth
|
||||
|
||||
[manifest.json](manifest.json) owns scheduling metadata: status, priorities, dependencies, ADR approvals, assignments and write locks. Task Markdown owns implementation scope/evidence/acceptance. This index and the [graph](dependencies.mmd) are derived views. Only the planning/integration owner updates scheduling state.
|
||||
|
||||
**43 scheduled + 5 deferred + 4 merged IDs = 52 retained IDs.** Merged records preserve traceability; never execute them separately. Deferred work requires its stated trigger and explicit activation.
|
||||
**45 scheduled + 5 deferred + 4 merged IDs = 54 retained IDs.** F09/P07 add the measured projection/profiling work. Merged records preserve traceability; never execute them separately. Deferred work requires its stated trigger and explicit activation.
|
||||
|
||||
States: ready, claimed, in_progress, review, done, blocked, deferred, merged. “Ready” means no code/ADR prerequisite, not execution authority. Implementation dependencies require accepted integration. `release_gates` govern enabling an end-to-end feature, not component coding or integration; conditional gates apply only to the named capability. F05 may integrate before F06, but its replay behavior is not released until F06 proves it.
|
||||
|
||||
|
|
@ -36,7 +36,8 @@ Relative size: S narrow correction, M coherent boundary, L sensitive owner-contr
|
|||
| [F05 Unify matching and order lifecycle on the ledger](tasks/F05.md) | P0 / done | F04, ADR-003 | F06 | Rust execution semantics / L |
|
||||
| [F06 Implement deterministic replay once, with linear historical traversal](tasks/F06.md) | P0 / done | F05, D01, P01, ADR-003 | — | Rust deterministic replay / M |
|
||||
| [F07 Expose bounded Rust step sessions through existing NAPI workers](tasks/F07.md) | P0 / done | F06, C02, ADR-004 | — | Rust/TypeScript integration / M |
|
||||
| [F08 Publish canonical metrics and versioned result projections](tasks/F08.md) | P1 / ready | F06, ADR-002, ADR-003 | — | Quant analytics/Rust integration / M |
|
||||
| [F08 Publish canonical metrics and versioned result projections](tasks/F08.md) | P1 / blocked | F06, F09, ADR-002, ADR-003 | — | Quant analytics/Rust integration / M |
|
||||
| [F09 Return compact canonical replay projections](tasks/F09.md) | P1 / review | F07, ADR-002, ADR-003, ADR-004 | — | Rust/TypeScript financial integration / M |
|
||||
|
||||
### E3 — Point-in-time datasets and features
|
||||
|
||||
|
|
@ -94,6 +95,7 @@ Relative size: S narrow correction, M coherent boundary, L sensitive owner-contr
|
|||
| [P04 Schedule deterministic batches across a bounded worker pool](tasks/P04.md) | P2 / blocked | F07, R06, C06, P01, ADR-008 | — | Performance/infrastructure engineering / M |
|
||||
| [P05 Separate result summaries from paged detail payloads](tasks/P05.md) | P2 / deferred | R06, P01 | — | Performance/infrastructure engineering / M |
|
||||
| [P06 Conditionally add a minimal Rust-executed strategy plan](tasks/P06.md) | P2 / deferred | P04, S01, ADR-008 | — | Rust/TS performance compiler boundary / M |
|
||||
| [P07 Profile representative canonical replay workloads](tasks/P07.md) | P1 / review | F07, P01 | F09 for compact comparisons | Performance/test infrastructure / M |
|
||||
|
||||
### E8 — Authorized, isolated AI research
|
||||
|
||||
|
|
@ -115,4 +117,4 @@ Relative size: S narrow correction, M coherent boundary, L sensitive owner-contr
|
|||
|
||||
Before any wave: unique IDs; existing task/ADR references; acyclic implementation graph; no scheduled task dependent on merged/deferred work; approvals/readiness; actual file locks; isolated native build outputs/workspace dependencies and test databases. Release gates are checked separately at activation.
|
||||
|
||||
The first eleven waves are independently reviewed, validated and committed with owner approval; see the [eleventh-wave handoff](../ROADMAP.md#eleventh-wave-handoff--2026-10-23) and manifest evidence. Next recommended: **F08 canonical metrics/result projections**, whose code and ADR prerequisites are satisfied; readiness is not execution authority. S01 still needs ADR-005 and R01 needs ADR-006. The unresolved multi-asset mark-policy gate still blocks default activation, not additive components. No push, PR, trading operation or further task implementation is authorized.
|
||||
The first eleven waves are independently reviewed, validated and committed. Current authorization covers **F09 compact projections and P07 profiling** only. P07 baseline files can progress in parallel; paired projection measurements consume the accepted F09 contract afterward. F08 adds historical sampling/statistics next, without reconstructing accounting in TS. S01 needs ADR-005 and R01 needs ADR-006. The unresolved multi-asset mark-policy gate still blocks default activation. No new commit, push, PR or trading operation is authorized.
|
||||
|
|
|
|||
|
|
@ -15,6 +15,7 @@ flowchart TD
|
|||
F06["F06: Implement deterministic replay once, with linear historical traversal"]
|
||||
F07["F07: Expose bounded Rust step sessions through existing NAPI workers"]
|
||||
F08["F08: Publish canonical metrics and versioned result projections"]
|
||||
F09["F09: Return compact canonical replay projections"]
|
||||
end
|
||||
subgraph E3["E3: Point-in-time datasets and features"]
|
||||
D01["D01: Introduce availability-aware dataset v2"]
|
||||
|
|
@ -55,6 +56,7 @@ flowchart TD
|
|||
P04["P04: Schedule deterministic batches across a bounded worker pool"]
|
||||
P05["P05: Separate result summaries from paged detail payloads (conditional)"]
|
||||
P06["P06: Conditionally add a minimal Rust-executed strategy plan (conditional)"]
|
||||
P07["P07: Profile representative canonical replay workloads"]
|
||||
end
|
||||
subgraph E8["E8: Authorized, isolated AI research"]
|
||||
A01["A01: Add research-only principals and durable job budgets"]
|
||||
|
|
@ -86,8 +88,13 @@ flowchart TD
|
|||
C02 --> F07
|
||||
ADR004 --> F07
|
||||
F06 --> F08
|
||||
F09 --> F08
|
||||
ADR002 --> F08
|
||||
ADR003 --> F08
|
||||
F07 --> F09
|
||||
ADR002 --> F09
|
||||
ADR003 --> F09
|
||||
ADR004 --> F09
|
||||
ADR003 --> D01
|
||||
D01 --> D02
|
||||
S01 --> D04
|
||||
|
|
@ -169,6 +176,9 @@ flowchart TD
|
|||
P04 --> P06
|
||||
S01 --> P06
|
||||
ADR008 --> P06
|
||||
F07 --> P07
|
||||
P01 --> P07
|
||||
F09 -. compact comparisons only .-> P07
|
||||
R06 --> A01
|
||||
O01 --> A01
|
||||
ADR007 --> A01
|
||||
|
|
|
|||
File diff suppressed because it is too large
Load diff
|
|
@ -13,19 +13,23 @@ Scheduling source of truth: [manifest entry F08](../manifest.json). No task is a
|
|||
|
||||
## Intended behavior and implementation scope
|
||||
|
||||
F09 now supplies the independently deliverable compact terminal/owned-fill projection. F08 consumes it and adds historical sampling/statistical reporting; do not duplicate its native transport work. F09 is not completion of this story.
|
||||
|
||||
Use canonical Rust ledger postings, owned fills, occupied intervals and session-ending marks as the sole financial inputs. Reuse reviewed TypeScript statistical functions in `libs/calculations/src/analytics/` for return ratios and reports; do not port them to Rust merely for language uniformity. Add a small adapter for the engine-declared session calendar rather than blindly regrouping every venue by UTC date.
|
||||
|
||||
Version economics and metrics independently. Define sampling, annualization, benchmark and risk-free conventions in the result policy. Missing benchmark/risk-free inputs must not silently become invented measurements. Undefined or unsupported metrics are null with reasons. Adapt existing result DTOs without rewriting old rows.
|
||||
|
||||
Measurable benefit: comparable, independently checked rankings without a second ledger or a needless analytics rewrite.
|
||||
|
||||
Before implementation, pin reporting-only conventions in the handoff: account boundaries currently execute before equal-time observations and are not automatically close-equity samples; partial final sessions must be explicit; exposure needs a declared elapsed/venue-time denominator; the reviewed statistics currently assume 252 periods and default to 2% risk-free, so the adapter must pass a supported explicit policy and diagnose omitted inputs. These choices must not alter financial event ordering or risk semantics. Fills are not round trips.
|
||||
|
||||
## Exclusions
|
||||
|
||||
No accounting/fill recomputation in TypeScript, statistical library rewrite, forced native port, new service, or silent reinterpretation of historical results. Native analytics remain an option only if measured as a bottleneck.
|
||||
|
||||
## Likely files and ownership
|
||||
|
||||
- apps/stock/engine/src/backtest/simple_results.rs (authoritative projections, not new statistical formulas)
|
||||
- apps/stock/engine/src/financial/result.rs and replay reporting hooks (canonical outputs; legacy simple_results.rs remains separate)
|
||||
- apps/stock/orchestrator/src/backtest/native-result.ts
|
||||
- apps/stock/orchestrator/src/backtest/BacktestReport.ts
|
||||
- libs/calculations/src/analytics/return-statistics.ts
|
||||
|
|
@ -36,7 +40,7 @@ Write locks: result-contract. One agent owns this change. Lock names do not over
|
|||
|
||||
## Dependencies and blockers
|
||||
|
||||
Implementation requires [F06](F06.md) integrated.
|
||||
Implementation requires [F06](F06.md) and [F09](F09.md) integrated.
|
||||
|
||||
Architecture decisions: ADR-002, ADR-003. Agents may not independently amend their policies.
|
||||
|
||||
|
|
|
|||
48
docs/development/backlog/tasks/F09.md
Normal file
48
docs/development/backlog/tasks/F09.md
Normal file
|
|
@ -0,0 +1,48 @@
|
|||
# F09 — Return compact canonical replay projections
|
||||
|
||||
Parent epic: E2. Priority/severity: P1 / High. Complexity: M. Specialist: Rust/TypeScript financial integration.
|
||||
|
||||
Story: As a researcher, I can obtain authoritative terminal holdings, P&L and actual fills without serializing the complete nested execution journal, while retaining full diagnostics when needed.
|
||||
|
||||
Scheduling and ownership: [manifest F09](../manifest.json). This is the independently deliverable projection portion of F08, not a replacement for its historical metrics.
|
||||
|
||||
## Evidence and root cause
|
||||
|
||||
- **PER-01 / KEEP-02 — Verified:** [full native finalization](../../../../apps/stock/engine/src/api/replay.rs#L165) exports every nested matching receipt through a JSON value tree. The recorded F07 release workload emits 66.7MB/103.6MB at 10k total bars; finalization averages 0.963s/1.377s, approximately 35–39% of trial time. This is conformance output, not useful minimal research output.
|
||||
- **FIN-05 — Verified:** [Ledger::valuation](../../../../apps/stock/engine/src/financial/ledger.rs#L674), [FinancialEffect](../../../../apps/stock/engine/src/financial/contract.rs#L327) and existing ledger receipts already contain authoritative terminal values, realized basis/P&L, actual fees and ownership. Recomputing these in TypeScript would create competing financial authority.
|
||||
|
||||
## Scope and pinned contract
|
||||
|
||||
- Add a small Rust projection module. Emit the existing terminal snapshot/view, checked Ledger valuation and owner contributions, plus flattened actual fills copied from committed commands/effects in authoritative order. Retain IDs, event time, owner/decision/order/fill, side/quantity/price, fee, cash/quantity deltas, released basis and realized gross P&L. Fills are not completed round trips.
|
||||
- `cashDelta` preserves the ledger effect's gross notional movement; the fee is a separate posting, not an additional fee already included in that delta. Valuation owner contributions include reserve capital and can be negative. Schema coherence checks compare the returned cash/equity strings with the existing view without reproducing accounting arithmetic.
|
||||
- Iterate borrowed ledger receipts once, skipping replay-labelled aliases. A read-only ledger receipt accessor and serialization derives for existing valuation types are allowed. No checkpoint cloning, ledger reconstruction, replay or financial arithmetic duplication to produce output. Preserve internal receipts, idempotency indexes and restore behavior.
|
||||
- Add native `project(identityJson)` beside the unchanged full diagnostic `finalize(identityJson)`. Compact output has `format: "projection"`, `projectionVersion: 1`, `financialVersion: 1`, the same identity/status/manifest/policy/view/limitations, and `projection: { valuation, fills }`; it has no nested `receipts`. Use typed serialization with borrowed metadata where practical.
|
||||
- TS adds a strict projection parser and typed `NativeReplaySession.project()`. The existing conformance loop may select `resultFormat: "projection" | "trace"`; old omitted-format calls and the existing diagnostic parser retain their trace behavior. No second loop. New compact consumers explicitly select projection; active legacy/durable defaults do not change.
|
||||
- The existing fixed-trace worker request may carry the optional format; the parent captures expected format with identity/policy and rejects mismatched responses. Both formats share completion, failure, disposal and cancellation guards.
|
||||
- Extend observational metrics with finalization native-call time (including Rust work/serialization), JSON decode time, schema-validation time and disposal time. Keep these outside economic outputs and deterministic hashes; do not call them pure crossing measurements. Expose unavailable internal Rust/GC splits honestly.
|
||||
|
||||
## Exclusions
|
||||
|
||||
No session-close equity curve, return ratios, Sharpe/Sortino, exposure percentage, round-trip win rate, invented defaults or legacy DTO coercion: these remain F08. No journal deletion/compaction, new accounting, risk/timing changes, new persistence/service, pagination, DSL, cache or default engine/paper/live cutover.
|
||||
|
||||
## Files and ownership
|
||||
|
||||
- `apps/stock/engine/src/financial/result.rs` and tests; `ledger.rs` read-only accessor/valuation serialization; module registration.
|
||||
- `apps/stock/engine/src/api/replay.rs` and generated binding verification.
|
||||
- `apps/stock/orchestrator/src/contracts/native-replay.ts`, `backtest/native-replay.ts`, existing worker supervisor/dispatch as needed.
|
||||
- Focused native/projection/worker fixtures and tests. Benchmark files belong to P07; root coordinates final paired comparisons.
|
||||
|
||||
Write locks: financial-projection, native-public-api, worker-protocol, result-contract. One owner. Dependencies: F07; approved ADR-002/003/004. P07 baseline work is independent; benchmark integration uses the frozen projection contract, not concurrent reinterpretation.
|
||||
|
||||
## Acceptance and mandatory tests
|
||||
|
||||
1. `compact_full_financial_parity`: terminal snapshot/valuation/flattened fills agree with the retained full trace and independent hand-calculated fixtures; all amounts remain canonical decimal strings.
|
||||
2. `projection_aliases_once`, `partial_fill_projection`, `two_owner_projection`: duplicate command/fill aliases do not duplicate output, partial fills remain distinct, owner attribution and fees reconcile, including final residual basis. No-trade output has zero fills and honest terminal values.
|
||||
3. `projection_is_read_only`: repeated project/finalize calls preserve state/checkpoints and original diagnostic output; restored sessions produce the same projection. Full-trace fixture hashes remain unchanged.
|
||||
4. `projection_terminal_guard`, `projection_identity_policy_format`: incomplete/failed/disposed sessions cannot return successful compact output; malformed identities, policies and requested formats reject, including worker races/cancellation and post-result abort.
|
||||
5. Strict TS/schema/architecture/native gates pass. No receipt/future-data leakage into strategy contexts; no broadening of worker-only native reachability.
|
||||
6. Paired release measurements on the same frozen dataset/config/decisions show identical financial projection hashes and reduced output bytes/finalization cost. Preserve full trace as an explicit diagnostic oracle. Record actual before/after; no timing threshold in CI and no promised speedup. P07 supplies representative workload variants.
|
||||
|
||||
Regression risk: alias double counting, effect-to-fee mispairing, silently changed output semantics or a successful result from failed state. Review G1/G2 independently; retain existing F07 regressions and disposable worker/runner durability gates. Rollback is additive API deployment, not weaker financial policies.
|
||||
|
||||
Definition of done: reviewed source, exact integrated test/benchmark evidence and canonical manifest handoff. No commit/push/PR without separate authorization.
|
||||
42
docs/development/backlog/tasks/P07.md
Normal file
42
docs/development/backlog/tasks/P07.md
Normal file
|
|
@ -0,0 +1,42 @@
|
|||
# P07 — Profile representative canonical replay workloads
|
||||
|
||||
Parent epic: E7. Priority/severity: P1 / High. Complexity: M. Specialist: performance/test infrastructure.
|
||||
|
||||
Story: As a platform developer, I can distinguish replay, financial turnover, result transport and diagnostic overhead before choosing the next optimization.
|
||||
|
||||
Scheduling and ownership: [manifest P07](../manifest.json). Extend P01's existing harness; do not create another benchmark framework.
|
||||
|
||||
## Evidence and root cause
|
||||
|
||||
- **PER-01 — Verified:** the F07 [turnover profile](../../../../scripts/benchmark-replay.ts#L100) alternates positions at every barrier. At 10k total bars it creates 9,999/19,980 fills; 2.65–3.61s is not the cost of merely reading bars.
|
||||
- In the original F07 measurement, finalization consumed approximately 35–39%; fixture decisions less than 2%; native creation approximately 3%. Before F09, the [adapter](../../../../apps/stock/orchestrator/src/backtest/native-replay.ts#L184) combined native work and JSON validation, without a separate disposal timer. These measurements did not establish a pure NAPI overhead, Rust bottleneck, or need for a DSL.
|
||||
|
||||
## Scope
|
||||
|
||||
- Extend `scripts/benchmark-replay.ts`, `scripts/benchmark-research.ts` and their tests only. Reuse frozen fixture generation, source/addon/host/runtime hashes and cold-process/fresh-session structure.
|
||||
- Add `none` (same callbacks/cadence, no targets), `sparse` (one opening and one closing fill per owner/asset), and `turnover` (existing alternating unit targets) profiles. Preserve existing invocation behavior; expose explicit CLI profile/format selection and an opt-in 100k size. No new application input limits.
|
||||
- Measure verified dataset preparation, native load, actual advance/submit/decision/finalization/disposal phases, emitted bytes, observed fills/decisions/calls, wall time and process RSS. Consume optional finalization subphase metrics only after the contract owner publishes them. Do not infer internal Rust/GC time from an unexplained residual.
|
||||
- Independent integer-based fixture oracles remain test/benchmark-only. Repeated runs/reversed callback evaluation must preserve economic output. Full trace keeps exact normalized-result hash validation; compact/full comparisons use the same canonical financial projection, not unlike wire-envelope hashes.
|
||||
- Baseline profiles work against committed F07 independently. Paired compact runs are enabled only after F09's contract is frozen/accepted by root; do not edit adapter/schema/native files to make the benchmark fit. Record the exact source/artifact for each baseline/candidate.
|
||||
- Run selected 10k and explicitly requested 100k workloads sequentially. Report unavailable measurements/resource failures honestly rather than silently trimming data/traces. Full-history 100k diagnostic output can be large; no throughput claim for cases not run.
|
||||
|
||||
## Exclusions
|
||||
|
||||
No financial semantic change, arbitrary hot-loop refactor, native dataset cache, shared feature framework, worker pool, DSL, new service, web paging or journal deletion. Select a concrete next optimization from evidence; implementation beyond F09 requires a scoped follow-up.
|
||||
|
||||
## Dependencies, locks and parallelism
|
||||
|
||||
Code prerequisites: F07 and P01. No new economic policy or ADR-008 approval is needed for measurements alone. P03/P04/P06 remain gated. Write lock: benchmark-harness, with the three explicit files above. Safe parallel work with F09's separate core/adapter files. Compact comparison is a conditional integration gate requiring F09; baseline compilation/tests must not depend on unmerged native APIs.
|
||||
|
||||
## Acceptance and mandatory tests
|
||||
|
||||
1. `profile_none`, `profile_sparse`, `profile_turnover` pin deterministic call/fill/fee/basis/terminal-equity expectations, including multiple owners/assets and retained session gaps.
|
||||
2. `benchmark_profile_arguments` rejects unsupported flags/combinations; existing P01/F07 invocation and tiny tests still work.
|
||||
3. `profile_identity_mismatch` rejects changed dataset/policy/strategy/native result identity; profile/result format is included in provenance. Different profiles are never compared as equivalent economics.
|
||||
4. `compact_trace_projection_parity` and reversed callback order agree on authoritative projection; diagnostics remain complete and independently testable.
|
||||
5. No fake zero/unavailable timings, no timing-flaky assertions. Print raw repeated rows and a concise breakdown with timing boundaries/build profile. Distinguish first process/setup from reused prepared JS inputs and fresh native sessions.
|
||||
6. Integrated evidence documents measured candidate effects, remaining unattributed costs and the smallest justified next action. No unsupported 10x/100x claim.
|
||||
|
||||
Regression risk: benchmark oracle mistakes, comparing different policies/profiles, or profiling work inside a purported engine-only timer. Mandatory focused tooling/native fixtures, strict TypeScript and scoped lint; financial/result owner reviews oracle/parity independently. No native rebuild concurrent with another agent's artifact review.
|
||||
|
||||
Definition of done: reproducible script/tests, baseline and accepted-candidate measurements, independent review and root manifest handoff. Missing resource-dependent large runs must be explicit; not a pass. No commits/pushes/PRs without authorization.
|
||||
Loading…
Add table
Add a link
Reference in a new issue