80 lines
12 KiB
Markdown
80 lines
12 KiB
Markdown
# Independent skeptical backlog review
|
||
|
||
Reviewed against repository baseline `b7aeca4`, 2026-10-22. **Planning changes only.** Evidence below is code inspection, not a claim that tests/benchmarks ran. Verified = directly visible code/plan behavior; Likely = engineering consequence not benchmarked; Needs investigation = requires execution or product approval.
|
||
|
||
## Verdict
|
||
|
||
The direction is sound, but the original backlog made several optional optimizations prerequisites, sequenced financial ownership after the ledger, and left agents to resolve monetary/timing semantics. Those are more important than adding abstractions or increasing task count.
|
||
|
||
Keep the modular monolith, TypeScript authoring and current product/durability infrastructure. Establish one small Rust financial kernel with two adapters: resident research sessions and transactional paper transitions. Do not force statistical reports, orchestration or every indicator into Rust.
|
||
|
||
## Ranked findings and dispositions
|
||
|
||
| Severity / evidence | Problem | Revision and acceptance consequence |
|
||
| --- | --- | --- |
|
||
| Critical / Verified contract gap | Rounded average price was insufficient as authoritative cost basis; partial disposals could create residual money | ADR-002/F02 store remaining cost amount; partial proportional allocation, exact final residual. Fixture cost5/quantity3 must release5 exactly |
|
||
| Critical / Verified plan contradiction | F02 built aggregate positions before F03 introduced ownership | Merge F03 into F02. Owner books exist at first fill; A/B attribution and aggregate reconciliation are initial ledger tests |
|
||
| Critical / Verified boundary gap | Paper pure snapshot API could imply full serialization/cloning per research event | ADR-005 specifies one internal apply kernel. Resident research mutates private state directly; paper stages and persists within existing SQL transactions. Preserve ordered effects/checkpoints |
|
||
| Critical / Verified ambiguity | Arbitrary TS callback determinism was treated too broadly; barrier state/RNG/intent semantics were incomplete | ADR-004/F07/S01 use progress/decisionBatch/complete, same ledger revision for all callbacks, staged state and per-strategy RNG; exceptions fail the attempt; no target/order mixing in v1. Trace replay is not proof of arbitrary-code determinism |
|
||
| High / Verified scope conflict | C03 mixed a narrow fee bug with a new financing policy | Keep legacy nonreducing gross-capital model/reducing exemption; add unpaid remaining fees only. Canonical cash reservations belong to F04 |
|
||
| High / Verified dependency contradiction | F05 acceptance needed F06 replay, while F06 depended on F05 completion | Matcher tests complete F05; replay-dependent release assertions belong to F06. Release gates are separate from implementation prerequisites |
|
||
| High / Verified timing gaps | Multi-timeframe feeds could duplicate execution liquidity; DAY targets and account risk-session clock were ambiguous | ADR-003/F04–F06 require one execution series per instrument, feature-only additional frames, explicit DAY/target expiry and account calendar; next-open and persistent halt fixtures |
|
||
| High / Verified avoidable work | A new legacy research runtime would be replaced again after Rust cutover | Narrow C06 to fail-closed composition: shared paper accepts existing isolated native research only; standalone legacy TS research cannot initialize/activate paper. Preserve current busy guard |
|
||
| High / Verified artificial prerequisites | Shared cache, all builtins, resident dataset reuse and reporting blocked useful strategy/paper/batch work | Remove D04→S01, F08→S03, P03→P04; S02 ports one SMA first. Actual isolation and provenance gates remain |
|
||
| High / Verified repeated work | F06 introduced replay then P02 replaced its queue | Merge P02 into F06: sorted immutable event cursor once; deterministic ties and scaling evidence |
|
||
| High / Verified product sequencing | Workspace/catalog/picker completion blocked independent experiment/backend/AI work | Remove unrelated UI prerequisites. Keep W04 browser coverage as release gates; R06 offers summary projections, R09 only gates regime panels on S05 |
|
||
| High / Verified missing dependency | Validation artifacts/findings referenced R03 despite experiments no longer depending on research metadata | R08 persists immutable experiment-owned reports; R09 save/link-finding requires R03 only when enabled. Basic validation remains independent |
|
||
| Medium / Verified ambiguous evidence | Publishing, retrying and walk-forward semantics allowed inconsistent interpretations | R01 distinguishes idempotent publish from intentional revision; R06 retries use fenced attempts; R08 declares reset-segment capital/state and excludes warmup from performance |
|
||
| Medium / Verified excess infrastructure | Generic capabilities, metric-validation store, migrations framework and blanket bug toggles could grow from vague criteria | W01 uses existing APIs; R03 references retained metric paths; O01 locks existing migration transaction; no toggles restoring known defects |
|
||
| Medium / Likely optimization overreach | Universal caching/native analytics and arbitrary DSL speed thresholds increased work before measurement | F08 reuses reviewed TS statistics; five optional tasks stay conditional; P01 measures existing paths only |
|
||
| Needs investigation | Actual callback cost, resident-cache benefit, decimal throughput, platform bitwise feature reproducibility | Measure P01 then instrument F06/F07/S01/P04; no invented speedup/throughput claims |
|
||
|
||
## Repository anchors behind the decisions
|
||
|
||
- Terminal liquidation follows the last mark: [engine.rs:135](../../apps/stock/engine/src/backtest/engine.rs#L135); result reads the curve: [simple_results.rs:308](../../apps/stock/engine/src/backtest/simple_results.rs#L308). C01 remains a narrow current defect fix.
|
||
- Legacy financing checks gross exposure without unpaid fees: [model.ts:234](../../apps/stock/orchestrator/src/execution/model.ts#L234). Fill-time policy and existing TIF handling: [SimulationExecution.ts:92](../../apps/stock/orchestrator/src/execution/SimulationExecution.ts#L92), [line168](../../apps/stock/orchestrator/src/execution/SimulationExecution.ts#L168). C03 must not replace that entire model.
|
||
- Initialization readiness precedes a shutdown early return: [ModeManager.ts:33](../../apps/stock/orchestrator/src/core/ModeManager.ts#L33), [line157](../../apps/stock/orchestrator/src/core/ModeManager.ts#L157). C04 owns lifecycle, C06 owns composition.
|
||
- Shared TS research preparation changes ModeManager: [container.ts:101](../../apps/stock/orchestrator/src/container.ts#L101). The existing [NativeBacktestWorker](../../apps/stock/orchestrator/src/backtest/NativeBacktestWorker.ts) and [fenced dataset runner](../../apps/stock/orchestrator/src/backtest/BacktestRunner.ts#L190) are reusable.
|
||
- Historical events use repeated queue insertion: [backtest/mod.rs:138](../../apps/stock/engine/src/backtest/mod.rs#L138). Implement efficient traversal during replay replacement, not in a later task.
|
||
- Reviewed reporting math already exists: [return-statistics.ts:24](../../libs/calculations/src/analytics/return-statistics.ts#L24). Reuse it over authoritative ledger/session projections instead of rewriting statistics in Rust.
|
||
- Websocket close clears the reference before a reconnect equality check: [useWebSocket.ts:124](../../apps/stock/web-app/src/hooks/useWebSocket.ts#L124). Existing [detail controls](../../apps/stock/web-app/src/features/backtest/BacktestDetailPageV2.tsx#L379) and [durable submission](../../apps/stock/web-api/src/services/backtest-v2.service.ts#L211) need focused repair, not replacement.
|
||
- Migration checking is outside the application transaction: [migration-runner.ts:59](../../apps/stock/web-api/src/migrations/migration-runner.ts#L59). O01 must acquire the lock and check/apply on the same client.
|
||
- Preserve transaction/recovery behavior: [StrategyRecovery.ts:151](../../apps/stock/orchestrator/src/execution/StrategyRecovery.ts#L151), [Postgres execution tests](../../test/postgres/order-execution.test.ts), [strategy recovery tests](../../test/postgres/strategy-recovery.test.ts).
|
||
|
||
## Scope accounting
|
||
|
||
| Disposition | IDs | Rationale |
|
||
| --- | --- | --- |
|
||
| Merge into financial contract | C05 → F01 | Economic fixture corpus and protocol evolve together; no separate expected-failure harness project |
|
||
| Merge into owner-aware ledger | F03 → F02 | Avoid migrating a ledger immediately after writing it |
|
||
| Merge into dataset v2 | D03 → D01 | Availability, coverage and eligibility are one schema migration |
|
||
| Merge into replay | P02 → F06 | Implement traversal once |
|
||
| Conditional after measurements | D04, P03, P05, P06 | Shared features, cross-trial reuse, large details, DSL respectively |
|
||
| Conditional after real operational need | O02 | Mandatory run/paper diagnostics already belong to W01/F07/S04 |
|
||
|
||
Result: **43 scheduled + 5 conditional work items**, with four merged traceability records. This does not promise a percentage reduction in engineering time: larger surviving tasks still contain the essential tests. Eliminated work is duplicated migration, needless porting, optional framework scope and artificial waiting.
|
||
|
||
## Financial/strategy boundary that agents must not reinterpret
|
||
|
||
1. Rust accepts validated intent envelopes, applies risk/matching/ledger transitions and emits owned effects.
|
||
2. TS chooses strategy logic and allocation preferences, not cash/P&L/fill calculations.
|
||
3. All due callbacks see one immutable account revision; admission order is stable and declared.
|
||
4. Strategy state and RNG are staged at barriers. A risk rejection is a committed decision outcome; a thrown callback is an attempt failure.
|
||
5. Paper SQL remains durability authority; Rust remains financial authority. Do not publish uncommitted staged effects.
|
||
6. One execution source per instrument; higher-timeframe observations are features, not extra liquidity.
|
||
7. Deterministic financial replay uses fixed inputs/decisions. Strategy recomputation additionally requires controlled APIs and pinned runtime/artifacts; same-process arbitrary JS is not a sandbox.
|
||
8. Statistical analytics can remain TS without being a competing simulator. Reports must consume canonical ledger/session values, never reconstruct a second account.
|
||
|
||
## Revised ordering
|
||
|
||
Critical path: F01 → F02 → F04 → F05 → F06 → F07 → S01 → S02 → R05 → R06. D01/P01 join replay, C02 joins NAPI, F08 and immutable retained artifacts join R05. S03 branches from S01/C06 without waiting for report/UI work. Parallel trials P04 need canonical sessions/experiments and measurement, not caches. AI A01/A02/A03 need bounded APIs/isolation/validation, not a browser IDE.
|
||
|
||
First wave: **C01, C03, C04, W01**. See [exact prompts and definitions of done](FIRST-WAVE.md). Use three implementation slots and a separate review/integration role. All four can be assigned independently; rotate the fourth to preserve review capacity.
|
||
|
||
## Remaining decisions and limitations
|
||
|
||
Approve monetary rounding/long-only scope, execution timing/terminal policy and AI trust model before dependent tasks. First-wave fixes do not settle those policies and do not make the legacy backtester suitable for performance claims.
|
||
|
||
No application tests or benchmarks were run for this review. Source inspection establishes the cited control-flow issues; numerical acceptance fixtures are specifications for implementation. The plan must be revalidated if source/contracts change before execution.
|
||
|
||
Planning validation passed: 75 planning files; 52 unique task IDs (43 scheduled, 5 conditional, 4 merged); 77 implementation edges with no cycle; no scheduled dependency on deferred/merged work; first-wave readiness; task/manifest dependency consistency; 749 relative link references and source line bounds; whitespace checks. Git changes remain confined to docs/development, HEAD remains b7aeca4, and execution_authorized remains false. Independent read-only core/product reviews found no remaining first-wave blocker; the product review's report-storage dependency gap was corrected as described above.
|