stock-bot/docs/development/backlog/findings.md

224 lines
16 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# Revalidated audit findings
Baseline: `b7aeca4`, inspected 2026-10-22. No standalone structured audit/backlog was found in existing docs; this matrix reconciles the supplied audit concerns against current code. Existing informal docs remain historical context, not a second task tracker.
**Verified** means the cited implementation establishes the behavior or gap. **Likely** would mean an inference not yet reproduced; none is promoted to a confirmed defect here. **Needs Investigation** marks runtime/coverage questions that source alone cannot certify. No full application test suite or new performance benchmark was run during this planning-only task. Numeric acceptance examples are new test requirements, not fabricated passing tests.
## FIN-01 — Critical / Verified
Both execution paths can act on a completed bar and fill against its current close; this is not a defensible default bar-close policy.
Evidence: [apps/stock/engine/src/backtest/engine.rs:249](../../../apps/stock/engine/src/backtest/engine.rs#L249); [apps/stock/orchestrator/src/services/ExecutionService.ts:224](../../../apps/stock/orchestrator/src/services/ExecutionService.ts#L224).
Disposition: [F01](tasks/F01.md), [F05](tasks/F05.md), [F06](tasks/F06.md), [W02](tasks/W02.md).
## FIN-02 — Critical / Verified
Native forced liquidation occurs after the last equity mark; reported final value reads that earlier mark, omitting terminal costs.
Evidence: [apps/stock/engine/src/backtest/engine.rs:135](../../../apps/stock/engine/src/backtest/engine.rs#L135); [apps/stock/engine/src/backtest/simple_results.rs:308](../../../apps/stock/engine/src/backtest/simple_results.rs#L308).
Disposition: [C01](tasks/C01.md), [F01](tasks/F01.md), [F02](tasks/F02.md).
## FIN-03 — Critical / Verified
Native order risk lacks a cash/fee reservation check. TypeScript compares gross exposure with pre-fee equity, so a fully funded buy can leave negative cash.
Evidence: [apps/stock/engine/src/risk/mod.rs:89](../../../apps/stock/engine/src/risk/mod.rs#L89); [apps/stock/orchestrator/src/execution/model.ts:234](../../../apps/stock/orchestrator/src/execution/model.ts#L234).
Disposition: [C03](tasks/C03.md), [F01](tasks/F01.md), [F02](tasks/F02.md), [F04](tasks/F04.md).
## FIN-04 — Critical / Verified
Native fills notify every strategy. TypeScript realized P&L uses aggregate symbol cost basis, not per-strategy cost basis.
Evidence: [apps/stock/engine/src/backtest/engine.rs:489](../../../apps/stock/engine/src/backtest/engine.rs#L489); [apps/stock/orchestrator/src/execution/model.ts:108](../../../apps/stock/orchestrator/src/execution/model.ts#L108).
Disposition: [F01](tasks/F01.md), [F02](tasks/F02.md), [S02](tasks/S02.md), [S05](tasks/S05.md).
## FIN-05 — Critical / Verified
Rust and TypeScript separately implement fill/accounting behavior; the exposed native TypeScript callback method explicitly rejects callbacks.
Evidence: [apps/stock/engine/src/api/backtest.rs:63](../../../apps/stock/engine/src/api/backtest.rs#L63); [apps/stock/orchestrator/src/execution/SimulationExecution.ts:114](../../../apps/stock/orchestrator/src/execution/SimulationExecution.ts#L114).
Disposition: [F01](tasks/F01.md), [F02](tasks/F02.md), [F05](tasks/F05.md), [F07](tasks/F07.md), [S01](tasks/S01.md), [S03](tasks/S03.md), [S06](tasks/S06.md), [R05](tasks/R05.md), [P01](tasks/P01.md), [P06](tasks/P06.md).
## FIN-06 — High / Verified
Native simulation fills complete requested quantities at the latest price without bar-volume participation; current risk must be enforced at acceptance and fill, including pending exposure.
Evidence: [apps/stock/engine/src/backtest/engine.rs:374](../../../apps/stock/engine/src/backtest/engine.rs#L374); [apps/stock/engine/src/backtest/engine.rs:414](../../../apps/stock/engine/src/backtest/engine.rs#L414).
Disposition: [F01](tasks/F01.md), [F04](tasks/F04.md), [F05](tasks/F05.md), [S04](tasks/S04.md).
## FIN-07 — High / Verified
Daily return grouping, Sharpe/Sortino conventions and placeholder exposure/VaR produce incomparable or misleading native metrics.
Evidence: [apps/stock/engine/src/backtest/simple_results.rs:374](../../../apps/stock/engine/src/backtest/simple_results.rs#L374); [apps/stock/engine/src/backtest/simple_results.rs:542](../../../apps/stock/engine/src/backtest/simple_results.rs#L542).
Disposition: [F08](tasks/F08.md), [W02](tasks/W02.md), [R07](tasks/R07.md), [R08](tasks/R08.md).
## DAT-01 — Critical / Verified
Dataset v1 has one bar timestamp and interval in the manifest, without explicit bar-end/availability semantics. Session dates cannot safely be treated as observation times.
Evidence: [libs/core/types/src/historical-data.ts:90](../../../libs/core/types/src/historical-data.ts#L90); [apps/stock/orchestrator/src/services/StorageService.ts:177](../../../apps/stock/orchestrator/src/services/StorageService.ts#L177).
Disposition: [F06](tasks/F06.md), [D01](tasks/D01.md), [R08](tasks/R08.md), [R11](tasks/R11.md).
## DAT-02 — High / Verified
Native input parsing silently discards malformed rows and truncates timestamps to seconds.
Evidence: [apps/stock/engine/src/api/backtest.rs:217](../../../apps/stock/engine/src/api/backtest.rs#L217); [apps/stock/engine/src/api/backtest.rs:290](../../../apps/stock/engine/src/api/backtest.rs#L290).
Disposition: [C02](tasks/C02.md).
## DAT-03 — High / Verified
Missing VWAP is replaced with typical price; reported volume and provider-adjusted prices are not a complete corporate-action execution model.
Evidence: [apps/stock/orchestrator/src/data/historical-dataset.ts:230](../../../apps/stock/orchestrator/src/data/historical-dataset.ts#L230); [libs/core/types/src/historical-data.ts:98](../../../libs/core/types/src/historical-data.ts#L98).
Disposition: [D01](tasks/D01.md).
## DAT-04 — High / Verified
Historical storage selects QuestDB or daily MongoDB; the Mongo path explicitly rejects intraday requests. Ingestion-to-research routing requires an executable provider/interval capability check.
Evidence: [apps/stock/orchestrator/src/services/StorageService.ts:287](../../../apps/stock/orchestrator/src/services/StorageService.ts#L287); [apps/stock/orchestrator/src/services/StorageService.ts:299](../../../apps/stock/orchestrator/src/services/StorageService.ts#L299).
Disposition: [D02](tasks/D02.md).
## RUN-01 — Critical / Verified
TypeScript research preparation calls the shared mode manager, which shuts down the current mode, so a research job can interfere with paper runtime.
Evidence: [apps/stock/orchestrator/src/container.ts:101](../../../apps/stock/orchestrator/src/container.ts#L101); [apps/stock/orchestrator/src/core/ModeManager.ts:47](../../../apps/stock/orchestrator/src/core/ModeManager.ts#L47).
Disposition: [C06](tasks/C06.md).
## RUN-02 — High / Verified
Partial initialization can allocate services before isInitialized becomes true; shutdown exits early on that failure path.
Evidence: [apps/stock/orchestrator/src/core/ModeManager.ts:55](../../../apps/stock/orchestrator/src/core/ModeManager.ts#L55); [apps/stock/orchestrator/src/core/ModeManager.ts:157](../../../apps/stock/orchestrator/src/core/ModeManager.ts#L157).
Disposition: [C04](tasks/C04.md).
## KEEP-01 — High / Verified
Preserve transaction-scoped account locking, idempotent fills/event fingerprints, durable decisions and recovery checkpoints; these are real behavior, not interfaces alone.
Evidence: [apps/stock/orchestrator/src/execution/PostgresExecutionRepository.ts:46](../../../apps/stock/orchestrator/src/execution/PostgresExecutionRepository.ts#L46); [apps/stock/orchestrator/src/execution/StrategyRecovery.ts:151](../../../apps/stock/orchestrator/src/execution/StrategyRecovery.ts#L151).
Disposition: [F01](tasks/F01.md), [C06](tasks/C06.md), [F02](tasks/F02.md), [F05](tasks/F05.md), [S01](tasks/S01.md), [S03](tasks/S03.md), [S06](tasks/S06.md), [A04](tasks/A04.md).
## KEEP-02 — High / Verified
Preserve frozen/hash-verified historical snapshots and fenced durable runner attempts; extend them instead of creating a second job engine.
Evidence: [apps/stock/orchestrator/src/data/historical-dataset.ts:98](../../../apps/stock/orchestrator/src/data/historical-dataset.ts#L98); [apps/stock/orchestrator/src/backtest/BacktestRunner.ts:190](../../../apps/stock/orchestrator/src/backtest/BacktestRunner.ts#L190).
Disposition: [F07](tasks/F07.md), [D01](tasks/D01.md), [D04](tasks/D04.md), [W04](tasks/W04.md), [R05](tasks/R05.md), [R06](tasks/R06.md), [R11](tasks/R11.md), [R12](tasks/R12.md), [P01](tasks/P01.md), [P03](tasks/P03.md), [P04](tasks/P04.md), [O02](tasks/O02.md).
## STR-01 — High / Verified
Registry is a useful small boundary, but its factories receive mode/execution services; BaseStrategy mixes author decisions, order submission and hidden signal filtering.
Evidence: [apps/stock/orchestrator/src/strategies/StrategyRegistry.ts:7](../../../apps/stock/orchestrator/src/strategies/StrategyRegistry.ts#L7); [apps/stock/orchestrator/src/strategies/BaseStrategy.ts:315](../../../apps/stock/orchestrator/src/strategies/BaseStrategy.ts#L315).
Disposition: [F02](tasks/F02.md), [D04](tasks/D04.md), [S01](tasks/S01.md), [S02](tasks/S02.md), [S05](tasks/S05.md), [S06](tasks/S06.md), [R01](tasks/R01.md), [R02](tasks/R02.md), [A02](tasks/A02.md).
## WEB-01 — High / Verified
The real backtest list/detail/API/SQL flow already exists. Strategy/project/experiment work should extend it; App strategy/analytics views are placeholders.
Evidence: [apps/stock/web-app/src/app/App.tsx:24](../../../apps/stock/web-app/src/app/App.tsx#L24); [apps/stock/web-api/src/services/backtest-v2.service.ts:211](../../../apps/stock/web-api/src/services/backtest-v2.service.ts#L211).
Disposition: [W01](tasks/W01.md), [W03](tasks/W03.md), [W04](tasks/W04.md), [R01](tasks/R01.md), [R02](tasks/R02.md), [R03](tasks/R03.md), [R04](tasks/R04.md), [R06](tasks/R06.md), [R07](tasks/R07.md), [R09](tasks/R09.md), [P05](tasks/P05.md), [A01](tasks/A01.md).
## WEB-02 — High / Verified
Detail exposes native-unsupported pause/resume controls, omits cancel wiring, and overlapping polling/selection can apply stale responses.
Evidence: [apps/stock/web-app/src/features/backtest/BacktestDetailPageV2.tsx:379](../../../apps/stock/web-app/src/features/backtest/BacktestDetailPageV2.tsx#L379); [apps/stock/orchestrator/src/backtest/RustBacktestAdapter.ts:160](../../../apps/stock/orchestrator/src/backtest/RustBacktestAdapter.ts#L160).
Disposition: [W01](tasks/W01.md), [W04](tasks/W04.md), [O02](tasks/O02.md).
## WEB-03 — High / Verified
Definition creation auto-starts by default and catches submission failure; run creation has no client submission key. Re-run uses current definition rather than immutable original input.
Evidence: [apps/stock/web-api/src/services/backtest-v2.service.ts:105](../../../apps/stock/web-api/src/services/backtest-v2.service.ts#L105); [apps/stock/web-app/src/features/backtest/BacktestDetailPageV2.tsx:173](../../../apps/stock/web-app/src/features/backtest/BacktestDetailPageV2.tsx#L173).
Disposition: [W03](tasks/W03.md), [R12](tasks/R12.md).
## WEB-04 — High / Verified
Existing results snapshot configuration and datasets but do not capture an immutable strategy artifact/engine build/model/seed bundle. Legacy projection can fall back to mutable definition fields.
Evidence: [libs/core/types/src/backtest-run.ts:4](../../../libs/core/types/src/backtest-run.ts#L4); [apps/stock/web-api/src/services/backtest-result.ts:107](../../../apps/stock/web-api/src/services/backtest-result.ts#L107).
Disposition: [F08](tasks/F08.md), [W02](tasks/W02.md), [R01](tasks/R01.md), [R03](tasks/R03.md), [R04](tasks/R04.md), [R05](tasks/R05.md), [R06](tasks/R06.md), [R07](tasks/R07.md), [R10](tasks/R10.md), [R11](tasks/R11.md), [R12](tasks/R12.md), [A03](tasks/A03.md).
## WEB-05 — High / Verified
SQL deletion cascades from definitions to runs/results; evidence retention must be defined before research findings reference those results.
Evidence: [database/postgres/init/08-create-runs-table.sql:13](../../../database/postgres/init/08-create-runs-table.sql#L13); [database/postgres/init/06-create-backtest-tables.sql:25](../../../database/postgres/init/06-create-backtest-tables.sql#L25).
Disposition: [R03](tasks/R03.md), [R10](tasks/R10.md).
## OPS-01 — High / Verified
Migration runner uses an explicit safe allowlist; adding SQL alone will not run it. Concurrent migration admission lacks an advisory lock.
Evidence: [apps/stock/web-api/src/migrations/migration-runner.ts:42](../../../apps/stock/web-api/src/migrations/migration-runner.ts#L42); [apps/stock/web-api/src/migrations/migration-runner.ts:57](../../../apps/stock/web-api/src/migrations/migration-runner.ts#L57).
Disposition: [O01](tasks/O01.md).
## PER-01 — Medium / Verified
EventQueue insertion scans prior events; native run is synchronous/one-shot and returns full JSON. Actual end-to-end bottleneck distribution still needs controlled measurements.
Evidence: [apps/stock/engine/src/backtest/mod.rs:138](../../../apps/stock/engine/src/backtest/mod.rs#L138); [apps/stock/engine/src/api/backtest.rs:194](../../../apps/stock/engine/src/api/backtest.rs#L194).
Disposition: [F06](tasks/F06.md), [F07](tasks/F07.md), [P01](tasks/P01.md), [P03](tasks/P03.md), [P04](tasks/P04.md), [P05](tasks/P05.md), [P06](tasks/P06.md).
## AI-01 — High / Verified
Existing small operator auth has read/admin/service roles, not a research-only principal or arbitrary-code isolation boundary.
Evidence: [libs/core/di/src/http/security.ts:4](../../../libs/core/di/src/http/security.ts#L4); [libs/core/di/src/http/security.ts:144](../../../libs/core/di/src/http/security.ts#L144).
Disposition: [A01](tasks/A01.md), [A02](tasks/A02.md), [A03](tasks/A03.md), [A04](tasks/A04.md).
## RES-01 — High / Verified
Experimental Python feature preprocessing uses full-sample medians/quantiles; shuffled returns preserve ordinary Sharpe. These routines must not silently become validation evidence.
Evidence: [apps/stock/analytics/src/ml/feature_engineering.py:386](../../../apps/stock/analytics/src/ml/feature_engineering.py#L386); [apps/stock/analytics/src/analysis/statistical_validation.py:168](../../../apps/stock/analytics/src/analysis/statistical_validation.py#L168).
Disposition: [D04](tasks/D04.md), [S05](tasks/S05.md), [R08](tasks/R08.md), [R09](tasks/R09.md), [A03](tasks/A03.md).
## OPS-02 — High / Needs Investigation
Paper/live operational readiness is not demonstrated end-to-end. Live is deliberately disabled; preserve that gate until feed, reconciliation and broker-specific recovery are verified.
Evidence: [apps/stock/orchestrator/src/core/ModeManager.ts:33](../../../apps/stock/orchestrator/src/core/ModeManager.ts#L33); [apps/stock/orchestrator/src/container.ts:152](../../../apps/stock/orchestrator/src/container.ts#L152).
Disposition: [S04](tasks/S04.md), [A04](tasks/A04.md), [O02](tasks/O02.md).
## Corrections to over-broad audit conclusions
- The first web workflow is not missing: real list/detail/routes, transactional dispatch and committed-state websocket updates exist. W01–W04 repair and verify it.
- Durable recovery and frozen data are implemented, not planned placeholders. Preserve them through S03; do not replace them for language uniformity.
- Native callback support is explicitly unavailable; NAPI types alone do not imply TS strategies already run in Rust replay.
- Future/native/experimental strategy files and Python research routines are not project-gated runtime capabilities. Do not enable them simply because names appear in a dropdown.
- Provider-adjusted data is not automatically executable corporate-action accounting. Hashing a dataset does not establish point-in-time correctness.
- No runtime evidence here establishes real broker reliability. Live-disabled guards remain intact.
- Exact hardware throughput, storage hot spots, memory limits and sandbox availability require P01/A02 measurements, not architectural confidence.
- Preservation rules in [cleanup audit](../../cleanup-audit.md) remain: reviewed calculations, restored helpers and useful research prototypes are not disposable dead code.