docs: plan orchestrator and engine cleanup tasks

This commit is contained in:
Boki 2026-10-26 19:05:24 -04:00
parent 700ee09c4c
commit 7481d02c6c
13 changed files with 869 additions and 4 deletions

View file

@ -0,0 +1,61 @@
# CL14 — Require canonical capabilities in durable research contracts
Parent epic: E11. Priority/severity: P1 / High. Complexity: M. Specialist: TypeScript contracts and durable research.
Scheduling and commit evidence: [manifest](../manifest.json). Scope baseline: `700ee09c`. Owner authorized planning, implementation and one commit per completed task on 2026-10-26; CL21 remains conditional. Follow [quality gates](../../QUALITY-GATES.md) and [agent instructions](../../agents/implementation.md).
## Outcome and evidence
execution-engine.ts:13 requires retired execution/playback but makes runCanonical optional. run-repository.ts:25 does the same for canonical claim/load/complete. BacktestRunner.ts:225,287,327 probes mandatory capabilities at runtime. RustBacktestAdapter.ts:35 storage and BacktestRunner.ts:60 engineName are unused.
The concrete benefit is a smaller supported execution surface with unchanged financial behavior. Findings are verified at the baseline; recheck caller/module evidence before edits. This does not imply active financial corruption.
## Scope
- Define required canonical engine/repository capabilities for the current runner. Preserve legacy interfaces where retained consumers actually need them.
- Remove unused storage and engineName constructor requirements and their caller/fixture plumbing.
- Remove only redundant optional-capability probes; preserve parsing of untrusted input, explicit unavailable-store errors, retired queue/HTTP rejection, and every lease/terminal-write rule.
- Keep legacy repository methods in place unless a tiny interface separation suffices; physical relocation is not required.
Likely files/modules:
- `apps/stock/orchestrator/src/backtest/execution-engine.ts`
- `apps/stock/orchestrator/src/backtest/run-repository.ts`
- `apps/stock/orchestrator/src/backtest/BacktestRunner.ts`
- `apps/stock/orchestrator/src/backtest/RustBacktestAdapter.ts`
- `apps/stock/orchestrator/src/backtest/PostgresBacktestRunRepository.ts`
- `apps/stock/orchestrator/src/container.ts`
- `test/fixtures/canonical-runner.ts`
## Exclusions
No changes to financial semantics, SQL schema, lease policy, historical readers, native exports or persisted request/result shapes. Preserve retained strategy packages/datasets/results, useful algorithms, reviewed calculations, durable recovery and the existing .env files. No pushes, PRs or paper/live activation.
## Dependencies and ownership
Prerequisites: None; inspect existing integrated baseline rather than reopening earlier cleanup tasks.
Write locks: `canonical-runner-contract`, `orchestrator-composition`.
Parallelism: May run alongside CL15. Serialize actual container.ts edits with CL16; this is a file lock, not a semantic prerequisite.
## Acceptance criteria
1. Current runner cannot type-check against an engine/repository lacking required canonical methods.
2. Canonical success, cancellation, lease loss and unavailable storage retain their behavior; old queued requests cannot execute.
3. Existing historical writers/readers and retirement diagnostics remain available to their existing consumers.
## Mandatory verification
- bun run typecheck
- bun test test/integration/canonical-durable-runner.test.ts test/integration/backtest-workflow.test.ts test/integration/canonical-worker-lifecycle.test.ts test/integration/research-pool.test.ts test/integration/research-runtime-isolation.test.ts scripts/test/architecture.test.ts
- Disposable PostgreSQL: test/postgres/canonical-durable-backtest.test.ts
Use isolated worktrees/build outputs and disposable safety databases/Redis only. Never rebaseline financial fixtures to hide changed behavior. Integrator runs repository checks on the combined source. Performance work remains deferred; no speed claims are part of acceptance.
## Risks and definition of done
Weakening fail-closed boundaries or dropping compatibility methods while narrowing types.
Done requires scoped tests, independent reviewer acceptance, integration verification, and a focused commit. The manifest owns status and evidence; implementers do not edit it. Root records each completed commit in the next bookkeeping update; the task completion commit includes its tests/reviewer evidence, avoiding self-referential hashes. Unrelated prior CL01–CL13 review status remains unchanged.

View file

@ -0,0 +1,67 @@
# CL15 — Retire abandoned Rust architecture scaffolding
Parent epic: E11. Priority/severity: P1 / High. Complexity: M. Specialist: Rust module graph and compatibility.
Scheduling and commit evidence: [manifest](../manifest.json). Scope baseline: `700ee09c`. Owner authorized planning, implementation and one commit per completed task on 2026-10-26; CL21 remains conditional. Follow [quality gates](../../QUALITY-GATES.md) and [agent instructions](../../agents/implementation.md).
## Outcome and evidence
lib.rs:5 compiles adapters; adapters/mod.rs:32 fabricates price-100 fills without calling its wrapped handler, :80 reports arbitrary orders Filled. Repository references are confined to scaffold and stale MIGRATION.md. Cargo/lib.rs and module declarations do not include the alternate architecture files.
The concrete benefit is a smaller supported execution surface with unchanged financial behavior. Findings are verified at the baseline; recheck caller/module evidence before edits. This does not imply active financial corruption.
## Scope
- Recheck module graph and repository callers; record a concise deletion/preservation inventory.
- Remove unused placeholder adapter framework and truly obsolete duplicate architecture entrypoints/backups.
- Inspect uncompiled metrics/results/framework for unique useful algorithms; preserve any such code in an explicitly retained location with honest status rather than silently deleting capability.
- Replace misleading migration guidance with current canonical versus retained-compatibility map. Keep compiled legacy constructors, indicators, analytics and meaningful regression tests.
Likely files/modules:
- `apps/stock/engine/src/lib.rs`
- `apps/stock/engine/src/adapters/`
- `apps/stock/engine/src/lib_new.rs`
- `apps/stock/engine/src/lib_simplified.rs`
- `apps/stock/engine/src/test_lib.rs`
- `apps/stock/engine/src/api_new/`
- `apps/stock/engine/src/domain.bak/`
- `apps/stock/engine/src/events.bak/`
- `apps/stock/engine/src/modes.bak/`
- `apps/stock/engine/src/backtest/results.rs`
- `apps/stock/engine/src/backtest/metrics_calculator.rs`
- `apps/stock/engine/src/strategies/framework/`
- `apps/stock/engine/MIGRATION.md`
## Exclusions
No blanket legacy API deletion, rewriting algorithms, adding a new framework, loader/provenance changes or financial-core edits. Preserve retained strategy packages/datasets/results, useful algorithms, reviewed calculations, durable recovery and the existing .env files. No pushes, PRs or paper/live activation.
## Dependencies and ownership
Prerequisites: None; inspect existing integrated baseline rather than reopening earlier cleanup tasks.
Write locks: `native-module-graph`.
Parallelism: Independent of TS contract/lifecycle work. Serialize Rust module and native build output with CL18.
## Acceptance criteria
1. No compiled adapter can manufacture placeholder fills; no repository consumers lose supported APIs.
2. Every removed file is classified by module/caller evidence; unique useful calculations remain discoverable.
3. Native ESM/CJS constructors and canonical reports retain existing behavior; current docs no longer recommend abandoned scaffolding.
## Mandatory verification
- cargo test -p engine --lib --offline
- Build native addon from this checkout; bun test scripts/test/native-bindings.test.ts test/integration/native-terminal-equity.test.ts test/integration/native-market-data.test.ts
- bun test scripts/test/architecture.test.ts
Use isolated worktrees/build outputs and disposable safety databases/Redis only. Never rebaseline financial fixtures to hide changed behavior. Integrator runs repository checks on the combined source. Performance work remains deferred; no speed claims are part of acceptance.
## Risks and definition of done
Mistaking retained algorithms/public compatibility APIs for dead scaffolding; native rebuild/provenance required.
Done requires scoped tests, independent reviewer acceptance, integration verification, and a focused commit. The manifest owns status and evidence; implementers do not edit it. Root records each completed commit in the next bookkeeping update; the task completion commit includes its tests/reviewer evidence, avoiding self-referential hashes. Unrelated prior CL01–CL13 review status remains unchanged.

View file

@ -0,0 +1,60 @@
# CL16 — Give orchestrator composition an explicit shutdown owner
Parent epic: E11. Priority/severity: P1 / High. Complexity: M. Specialist: TypeScript lifecycle and failure recovery.
Scheduling and commit evidence: [manifest](../manifest.json). Scope baseline: `700ee09c`. Owner authorized planning, implementation and one commit per completed task on 2026-10-26; CL21 remains conditional. Follow [quality gates](../../QUALITY-GATES.md) and [agent instructions](../../agents/implementation.md).
## Outcome and evidence
simple-container.ts:46 initializes DB clients then :58 registers app services without enclosing rollback and returns only services at :68. index.ts:159 drains app work but not database/cache clients; termination uses process.exit. builder.ts:76 keeps lifecycle owner only locally.
The concrete benefit is a smaller supported execution surface with unchanged financial behavior. Findings are verified at the baseline; recheck caller/module evidence before edits. This does not imply active financial corruption.
## Scope
- Expose an explicit owned runtime/shutdown handle while preserving compatible createContainer callers where needed.
- Reuse existing lifecycle cleanup to roll back application-registration and HTTP-bind failures after successful shared-service startup.
- Stop admission, drain durable runner/paper/queue work, then close borrowed adapters exactly once. Preserve initiating errors and attempt cleanup even if another closer fails.
- Remove now-irrelevant ModeManager cleanup from the canonical entrypoint; avoid broad app lifecycle migration.
Likely files/modules:
- `apps/stock/orchestrator/src/simple-container.ts`
- `apps/stock/orchestrator/src/container.ts`
- `apps/stock/orchestrator/src/index.ts`
- `libs/core/di/src/container/builder.ts`
- `libs/core/di/src/utils/lifecycle.ts`
- `test/integration/service-startup-rollback.test.ts`
## Exclusions
No changes to paper activation, account recovery, financial semantics, job lease policy, other application startup flows or readiness feature O02. Preserve retained strategy packages/datasets/results, useful algorithms, reviewed calculations, durable recovery and the existing .env files. No pushes, PRs or paper/live activation.
## Dependencies and ownership
Prerequisites: None; inspect existing integrated baseline rather than reopening earlier cleanup tasks.
Write locks: `orchestrator-composition`, `di-container`, `di-service-lifecycle`.
Parallelism: Can be prepared independently; serialize container.ts with CL14 and shared DI edits with any other owner.
## Acceptance criteria
1. Registration failure, HTTP bind failure, normal shutdown and repeated shutdown each close every owned resource once.
2. Runner terminal writes finish before PostgreSQL closure; one cleanup failure cannot skip remaining resources or mask original startup error.
3. Successful startup behavior, explicit paper composition and research isolation remain unchanged.
## Mandatory verification
- bun test libs/core/di/test/lifecycle.test.ts test/integration/service-startup-rollback.test.ts test/integration/paper-composition.test.ts test/integration/research-runtime-isolation.test.ts test/integration/canonical-worker-lifecycle.test.ts
- Add controlled orchestrator composition/startup tests for all acceptance failures; no development DB
- Build changed DI workspace; bun run typecheck
Use isolated worktrees/build outputs and disposable safety databases/Redis only. Never rebaseline financial fixtures to hide changed behavior. Integrator runs repository checks on the combined source. Performance work remains deferred; no speed claims are part of acceptance.
## Risks and definition of done
Double shutdown, early database closure, swallowed failures, unowned late initialization.
Done requires scoped tests, independent reviewer acceptance, integration verification, and a focused commit. The manifest owns status and evidence; implementers do not edit it. Root records each completed commit in the next bookkeeping update; the task completion commit includes its tests/reviewer evidence, avoiding self-referential hashes. Unrelated prior CL01–CL13 review status remains unchanged.

View file

@ -0,0 +1,58 @@
# CL17 — Separate historical reads from unused storage writes
Parent epic: E11. Priority/severity: P2 / Medium. Complexity: M. Specialist: TypeScript market data and provider normalization.
Scheduling and commit evidence: [manifest](../manifest.json). Scope baseline: `700ee09c`. Owner authorized planning, implementation and one commit per completed task on 2026-10-26; CL21 remains conditional. Follow [quality gates](../../QUALITY-GATES.md) and [agent instructions](../../agents/implementation.md).
## Outcome and evidence
StorageService.ts:71-193 combines mode initialization, DDL and two writers with no repository callers; historical capabilities/read/normalization start at :196/:250/:373. Current web dataset preparation uses only historical read capability.
The concrete benefit is a smaller supported execution surface with unchanged financial behavior. Findings are verified at the baseline; recheck caller/module evidence before edits. This does not imply active financial corruption.
## Scope
- Recheck callers; remove unused writers or explicitly isolate required compatibility behavior.
- Keep the existing historical facade and move concrete provider decoding/common validation into small cohesive functions only where it improves the data flow.
- Remove unnecessary PostgreSQL/mode ownership from the current historical reader; adapt retained examples only as necessary.
- Preserve provider selection, no fallback on missing/error, explicit synthetic opt-in, date semantics and all data-quality gates.
Likely files/modules:
- `apps/stock/orchestrator/src/services/StorageService.ts`
- `apps/stock/orchestrator/src/data/`
- `apps/stock/web-api/src/services/stored-dataset-preparation.ts`
- `test/integration/intraday-storage.test.ts`
## Exclusions
No new provider framework, source cleansing, null-volume coercion, cache, throughput optimization, DB migration or changes to adjustment/calendar policy. Preserve retained strategy packages/datasets/results, useful algorithms, reviewed calculations, durable recovery and the existing .env files. No pushes, PRs or paper/live activation.
## Dependencies and ownership
Prerequisites: [CL14](CL14.md)
Write locks: `historical-storage`.
Parallelism: After CL14; independent of native boundary and strategy diagnostic cleanup.
## Acceptance criteria
1. Current historical reader has no unused market/performance writes or ad hoc DDL responsibilities.
2. Existing provider routing, cancellation, malformed-row rejection and duplicate/timestamp/identity handling remain unchanged.
3. Frozen V1/V2 fixtures retain exact hashes and result eligibility; useful synthetic/legacy examples still work.
## Mandatory verification
- bun test test/integration/intraday-storage.test.ts test/integration/historical-dataset-v2.test.ts test/integration/ingestion-backtest.test.ts test/integration/stored-dataset-preparation.test.ts
- bun run typecheck
- Disposable PostgreSQL: test/postgres/stored-dataset-preparation.test.ts if persistence-facing behavior/imports change
Use isolated worktrees/build outputs and disposable safety databases/Redis only. Never rebaseline financial fixtures to hide changed behavior. Integrator runs repository checks on the combined source. Performance work remains deferred; no speed claims are part of acceptance.
## Risks and definition of done
Accidentally changing normalization, hash inputs, explicit provider precedence or legacy initialization.
Done requires scoped tests, independent reviewer acceptance, integration verification, and a focused commit. The manifest owns status and evidence; implementers do not edit it. Root records each completed commit in the next bookkeeping update; the task completion commit includes its tests/reviewer evidence, avoiding self-referential hashes. Unrelated prior CL01–CL13 review status remains unchanged.

View file

@ -0,0 +1,59 @@
# CL18 — Share strict native parsing and financial view projection
Parent epic: E11. Priority/severity: P2 / Medium. Complexity: M. Specialist: Rust canonical transport contracts.
Scheduling and commit evidence: [manifest](../manifest.json). Scope baseline: `700ee09c`. Owner authorized planning, implementation and one commit per completed task on 2026-10-26; CL21 remains conditional. Follow [quality gates](../../QUALITY-GATES.md) and [agent instructions](../../agents/implementation.md).
## Outcome and evidence
api/replay.rs:78 and api/paper.rs:53 duplicate keys_match; replay.rs:297 and paper.rs:66 duplicate the canonical financial view.
The concrete benefit is a smaller supported execution surface with unchanged financial behavior. Findings are verified at the baseline; recheck caller/module evidence before edits. This does not imply active financial corruption.
## Scope
- Extract small pure helpers shared by native replay and paper adapters; keep host identities/envelopes separate.
- Preserve strict recursive unknown/missing field checks including explicit required null fields.
- Preserve paper intermediate journal pre-transaction admissionRevision and final post-transaction revision.
- Retain one financial kernel; no new serializer framework or TS arithmetic.
Likely files/modules:
- `apps/stock/engine/src/api/replay.rs`
- `apps/stock/engine/src/api/paper.rs`
- `apps/stock/engine/src/api/mod.rs`
- `apps/stock/engine/src/financial/mod.rs`
- `scripts/test/native-bindings.test.ts`
## Exclusions
No wire shape/version/checkpoint changes, event order changes, economic policy or generic API framework. Preserve retained strategy packages/datasets/results, useful algorithms, reviewed calculations, durable recovery and the existing .env files. No pushes, PRs or paper/live activation.
## Dependencies and ownership
Prerequisites: [CL15](CL15.md)
Write locks: `native-canonical-api`.
Parallelism: After CL15; no simultaneous native build or canonical Rust contract owner.
## Acceptance criteria
1. Equivalent canonical states expose identical financial-view fields through both hosts.
2. Nested unknown/missing/null contract negatives remain rejected identically.
3. Paper retry journals and every intermediate/final revision are unchanged; existing exact replay/checkpoint fixtures pass.
## Mandatory verification
- cargo test -p engine --lib --offline
- Build native addon; bun test scripts/test/native-bindings.test.ts test/integration/native-replay.test.ts test/integration/native-replay-report.test.ts
- Add focused view parity and strict nested/null fixtures where existing tests do not establish parity
Use isolated worktrees/build outputs and disposable safety databases/Redis only. Never rebaseline financial fixtures to hide changed behavior. Integrator runs repository checks on the combined source. Performance work remains deferred; no speed claims are part of acceptance.
## Risks and definition of done
Weakening required nullable fields or changing journal projection revision/order.
Done requires scoped tests, independent reviewer acceptance, integration verification, and a focused commit. The manifest owns status and evidence; implementers do not edit it. Root records each completed commit in the next bookkeeping update; the task completion commit includes its tests/reviewer evidence, avoiding self-referential hashes. Unrelated prior CL01–CL13 review status remains unchanged.

View file

@ -0,0 +1,61 @@
# CL19 — Share pure strategy bookkeeping and event ordering
Parent epic: E11. Priority/severity: P2 / Medium. Complexity: M. Specialist: TypeScript strategy and durable paper parity.
Scheduling and commit evidence: [manifest](../manifest.json). Scope baseline: `700ee09c`. Owner authorized planning, implementation and one commit per completed task on 2026-10-26; CL21 remains conditional. Follow [quality gates](../../QUALITY-GATES.md) and [agent instructions](../../agents/implementation.md).
## Outcome and evidence
strategy-controller.ts:60/:186 and CanonicalPaperExecution.ts:74/:330 duplicate diagnostics/feedback. feed.ts:48 and canonical-paper.ts:199 duplicate event comparator. Canonical paper imports canonicalJson from legacy strategy-recovery.ts:6.
The concrete benefit is a smaller supported execution surface with unchanged financial behavior. Findings are verified at the baseline; recheck caller/module evidence before edits. This does not imply active financial corruption.
## Scope
- Share pure initial-diagnostic and owner-scoped admission-feedback helpers without combining controllers.
- Use one event-key comparator with existing timestamp/phase/UTF-8/source ordering.
- Move canonicalJson unchanged to a neutral local module with compatibility re-export; preserve exact historical bytes.
- Keep research state confirmation and paper SQL transaction/recovery rules separate.
Likely files/modules:
- `apps/stock/orchestrator/src/strategies/strategy-controller.ts`
- `apps/stock/orchestrator/src/strategies/strategy-decision.ts`
- `apps/stock/orchestrator/src/execution/CanonicalPaperExecution.ts`
- `apps/stock/orchestrator/src/execution/canonical-paper.ts`
- `apps/stock/orchestrator/src/execution/strategy-recovery.ts`
- `apps/stock/orchestrator/src/paper/feed.ts`
## Exclusions
No generic state-machine framework, state serialization policy changes, checkpoint/schema version changes or replacement of canonicalJson with stricter stateCopy. Preserve retained strategy packages/datasets/results, useful algorithms, reviewed calculations, durable recovery and the existing .env files. No pushes, PRs or paper/live activation.
## Dependencies and ownership
Prerequisites: None; inspect existing integrated baseline rather than reopening earlier cleanup tasks.
Write locks: `strategy-decision-helpers`, `canonical-paper-contract`.
Parallelism: Independent of CL14/CL15/CL16; reserve paper and strategy helper files.
## Acceptance criteria
1. Equivalent research/paper inputs retain identical state/RNG/owner feedback; malformed ownership fails before state commit.
2. Unicode and phase ties keep Rust-compatible ordering.
3. Historical canonicalJson fixtures remain byte identical; crash/retry/partial failures retain committed state.
## Mandatory verification
- bun test test/integration/strategy-runtime.test.ts test/integration/paper-feed.test.ts scripts/test/architecture.test.ts
- bun run typecheck
- Disposable PostgreSQL: test/postgres/canonical-paper.test.ts test/postgres/canonical-paper-crash.test.ts test/postgres/strategy-recovery.test.ts
- Add parity/order/serialization fixtures that exercise public behavior
Use isolated worktrees/build outputs and disposable safety databases/Redis only. Never rebaseline financial fixtures to hide changed behavior. Integrator runs repository checks on the combined source. Performance work remains deferred; no speed claims are part of acceptance.
## Risks and definition of done
Moving commit boundaries, changing ordering or fingerprint serialization, sharing mutable diagnostic objects.
Done requires scoped tests, independent reviewer acceptance, integration verification, and a focused commit. The manifest owns status and evidence; implementers do not edit it. Root records each completed commit in the next bookkeeping update; the task completion commit includes its tests/reviewer evidence, avoiding self-referential hashes. Unrelated prior CL01–CL13 review status remains unchanged.

View file

@ -0,0 +1,58 @@
# CL20 — Return validated retained results from the worker supervisor
Parent epic: E11. Priority/severity: P2 / Medium. Complexity: M. Specialist: TypeScript IPC and native worker lifecycle.
Scheduling and commit evidence: [manifest](../manifest.json). Scope baseline: `700ee09c`. Owner authorized planning, implementation and one commit per completed task on 2026-10-26; CL21 remains conditional. Follow [quality gates](../../QUALITY-GATES.md) and [agent instructions](../../agents/implementation.md).
## Outcome and evidence
NativeBacktestWorker.ts:132 parses a retained result but returns the untyped string at :161; RustBacktestAdapter.ts:85 parses it again.
The concrete benefit is a smaller supported execution surface with unchanged financial behavior. Findings are verified at the baseline; recheck caller/module evidence before edits. This does not imply active financial corruption.
## Scope
- Add a narrow typed retained execution entry or precise overload using the existing parser.
- Retain parsed result only after identity/policy/artifact checks and resolve only after successful close and candidate cleanup.
- Preserve trace callers/raw transport compatibility without a broad protocol redesign.
- Keep separate trust-boundary and persistence validations.
Likely files/modules:
- `apps/stock/orchestrator/src/backtest/NativeBacktestWorker.ts`
- `apps/stock/orchestrator/src/backtest/RustBacktestAdapter.ts`
- `apps/stock/orchestrator/src/backtest/native-worker-protocol.ts`
- `test/integration/retained-strategy-worker.test.ts`
## Exclusions
No serialization optimization, sandbox redesign, extra process/service, removal of boundary validation or premature success before worker exit. Preserve retained strategy packages/datasets/results, useful algorithms, reviewed calculations, durable recovery and the existing .env files. No pushes, PRs or paper/live activation.
## Dependencies and ownership
Prerequisites: [CL14](CL14.md)
Write locks: `native-worker-protocol`, `canonical-adapter`.
Parallelism: After CL14; separate from native Rust and historical storage edits.
## Acceptance criteria
1. Canonical adapter receives the already-validated typed envelope without reparsing.
2. Wrong identity/policy/artifact/analytics, nonzero exit after result, abort and cleanup failure cannot succeed.
3. Caller mutation cannot alter submitted/expected identity; trace/strategy callers retain their existing contracts.
## Mandatory verification
- bun test test/integration/retained-strategy-worker.test.ts test/integration/canonical-worker-lifecycle.test.ts test/integration/canonical-strategy-worker.test.ts test/integration/native-replay-report.test.ts
- bun run typecheck
- Existing result-before-error/close, malformed envelope, mutation, cancellation and candidate cleanup regressions; add only missing cases
Use isolated worktrees/build outputs and disposable safety databases/Redis only. Never rebaseline financial fixtures to hide changed behavior. Integrator runs repository checks on the combined source. Performance work remains deferred; no speed claims are part of acceptance.
## Risks and definition of done
Returning before child cleanup, accepting mutated expected input, dropping validation for another request kind.
Done requires scoped tests, independent reviewer acceptance, integration verification, and a focused commit. The manifest owns status and evidence; implementers do not edit it. Root records each completed commit in the next bookkeeping update; the task completion commit includes its tests/reviewer evidence, avoiding self-referential hashes. Unrelated prior CL01–CL13 review status remains unchanged.

View file

@ -0,0 +1,55 @@
# CL21 — Extract private deterministic replay preparation when needed
Parent epic: E11. Priority/severity: P3 / Low. Complexity: M. Specialist: Rust deterministic replay.
Scheduling and commit evidence: [manifest](../manifest.json). Scope baseline: `700ee09c`. Owner authorized planning, implementation and one commit per completed task on 2026-10-26; CL21 remains conditional. Follow [quality gates](../../QUALITY-GATES.md) and [agent instructions](../../agents/implementation.md).
## Outcome and evidence
financial/replay.rs:262-641 combines canonicalization, validation and schedule creation with stateful advance/submit/restore at :642 onward.
The concrete benefit is a smaller supported execution surface with unchanged financial behavior. Findings are verified at the baseline; recheck caller/module evidence before edits. This does not imply active financial corruption.
## Scope
- Only activate when an upcoming calendar/timeframe change benefits from this split and the owner resumes it.
- Extract private preparation/schedule functions; keep existing public types and one Replay state owner.
- Preserve exact event order, input binding, barriers, financial trace and checkpoint bytes.
Likely files/modules:
- `apps/stock/engine/src/financial/replay.rs`
- `apps/stock/engine/src/financial/replay_tests.rs`
## Exclusions
No immediate implementation, new traits/managers, event framework, algorithm changes or performance work. Preserve retained strategy packages/datasets/results, useful algorithms, reviewed calculations, durable recovery and the existing .env files. No pushes, PRs or paper/live activation.
## Dependencies and ownership
Prerequisites: None; inspect existing integrated baseline rather than reopening earlier cleanup tasks.
Write locks: `native-replay`.
Parallelism: Deferred; sole replay owner when activated.
## Acceptance criteria
1. Private extraction leaves all public contracts/economic traces/checkpoints unchanged.
2. Future-suffix, equal-time permutation and restore-before/after-every-event regressions pass.
3. No additional mutable financial handle or module dependency cycle.
## Mandatory verification
- cargo test -p engine --lib --offline
- Build native addon; bun test test/integration/native-replay.test.ts test/integration/native-replay-report.test.ts
- Exact event-order/checkpoint equality fixtures
Use isolated worktrees/build outputs and disposable safety databases/Redis only. Never rebaseline financial fixtures to hide changed behavior. Integrator runs repository checks on the combined source. Performance work remains deferred; no speed claims are part of acceptance.
## Risks and definition of done
Changing economic event ordering during a cosmetic move; intentionally deferred until there is practical need.
Done requires scoped tests, independent reviewer acceptance, integration verification, and a focused commit. The manifest owns status and evidence; implementers do not edit it. Root records each completed commit in the next bookkeeping update; the task completion commit includes its tests/reviewer evidence, avoiding self-referential hashes. Unrelated prior CL01–CL13 review status remains unchanged.