refactor: pre-M0 cleanup, core library hardening, and isolated dev/QA Docker stack

- Remove ~44k LOC of dead code, legacy v1 TS simulator/strategy stack, event-bus, analytics FastAPI prototype, legacy calculation archives, and unused deps (data-ingestion provider API handlers untouched)
- Extract @stock-bot/di/http-security and isolate @stock-bot/browser to data-ingestion via ServiceContainerBuilder.withRegistrations()
- Harden @stock-bot/mongodb read-only proxies, flatten @stock-bot/postgres with unified master+research migrations, and fix @stock-bot/config EnvLoader, ServiceApplication worker lifecycle, NamespacedCache.clear(), and BatchProcessor error propagation
- Flatten workspace root (remove apps/stock/package.json) and collapse orchestrator re-export shims
- Pin all Docker image versions, add shm_size/nofile/RAM caps and docker-compose.quant.yml, fix 05-add-visible-column.sql view recreation, and decouple dev/QA Compose project names for side-by-side execution
- Update PLATFORM-PLAN, DATA-CONTRACTS (bars_1m PARTITION BY MONTH, Rust bulk ETL, DuckDB limits), MILESTONES, and servers docs
This commit is contained in:
Boki 2026-11-27 00:11:50 -05:00
parent ce9e2df67c
commit 4cd6038063
432 changed files with 1247 additions and 44469 deletions

View file

@ -26,7 +26,7 @@ Timing/risk policy regressions also include adjacent_open_zero_latency, positive
## G2 — Durability and recovery
Existing [order execution](../../test/postgres/order-execution.test.ts), [strategy recovery](../../test/postgres/strategy-recovery.test.ts) and [durable backtest](../../test/postgres/durable-backtest.test.ts) cases are mandatory for touching those boundaries. Inject failures before/after decision, intent, fill, snapshot, result commits and publication. Verify stale attempt fencing, duplicate IDs, pending inputs, cancellation and restore-before-each-decision. Recovery must preserve per-effect context, not just final balances.
Existing [canonical paper](../../test/postgres/canonical-paper.test.ts), [canonical paper crash](../../test/postgres/canonical-paper-crash.test.ts) and [durable backtest](../../test/postgres/durable-backtest.test.ts) cases are mandatory for touching those boundaries. Inject failures before/after decision, intent, fill, snapshot, result commits and publication. Verify stale attempt fencing, duplicate IDs, pending inputs, cancellation and restore-before-each-decision. Recovery must preserve per-effect context, not just final balances.
No tests against a development trading account/database. `bun run test:postgres` requires a disposable `stock_bot_safety*` database and dedicated Redis DB15 via `PIPELINE_TEST_DATABASE_URL` and `BACKTEST_TEST_REDIS_URL`. Provision/start containers only when execution and resource use are authorized.
@ -56,7 +56,7 @@ bun run check
bun run test:postgres
```
`bun run check` runs build/types/contracts/tooling/utils/calculations/integration/native/lint and secret audit; it **does not include** disposable PostgreSQL, browser E2E or Python analytics. Run `bun run test:e2e` separately for the web workbench and `bun run test:analytics-api` if Python API behavior is touched. Native command is `cargo test -p engine --lib --offline`; missing dependencies are a reported blocker, not a pass.
`bun run check` runs build/types/contracts/tooling/utils/calculations/integration/native/lint and secret audit; it **does not include** disposable PostgreSQL or browser E2E. Run `bun run test:e2e` separately for the web workbench. Native command is `cargo test -p engine --lib --offline`; missing dependencies are a reported blocker, not a pass.
The browser gate requires a built checkout, explicit `PIPELINE_TEST_DATABASE_URL` pointing to a disposable `stock_bot_safety*` database, dedicated Redis DB15 in `BACKTEST_TEST_REDIS_URL`, and Chromium. Install the pinned browser explicitly with `bun run test:e2e:install` if missing; do not install browsers implicitly during checks. The command rebuilds the frontend for same-origin production use. It exercises authenticated HTTP/WebSocket routes, durable dispatch and SQL persistence with deterministic UI fixtures plus an actual native smoke run. Fixture results are not financial-correctness evidence. Never use a development trading database or queue.

View file

@ -8,7 +8,7 @@ TypeScript owns product/application logic, strategy authoring, signal/regime com
## Rationale and evidence
Current TypeScript [applyFill](../../../../apps/stock/orchestrator/src/execution/model.ts#L108) and Rust [process_fill](../../../../apps/stock/engine/src/backtest/engine.rs#L426) are competing authorities. Consolidation removes behavioral drift; moving all authoring to Rust would reduce flexibility without proving a throughput benefit.
Historical TypeScript `applyFill` (`orchestrator/src/execution/model.ts`, retired in pre-M0 cleanup) and Rust [process_fill](../../../../apps/stock/engine/src/backtest/engine.rs#L426) were competing authorities. Consolidation removes behavioral drift; moving all authoring to Rust would reduce flexibility without proving a throughput benefit.
## Alternatives and tradeoffs

View file

@ -18,7 +18,7 @@ C03 only adds unpaid-fee liability to the **existing non-reducing gross-capital
## Evidence / alternative costs
[TS amount/cost basis](../../../../apps/stock/orchestrator/src/execution/model.ts#L81), [aggregate owner attribution problem](../../../../apps/stock/orchestrator/src/execution/model.ts#L108), [native fill broadcast](../../../../apps/stock/engine/src/backtest/engine.rs#L489). Exact postings fix arithmetic, not market modeling. A full multicurrency double-entry/margin/borrow engine is not required for v1.
Historical TS amount/cost basis and aggregate owner attribution (`orchestrator/src/execution/model.ts`, retired in pre-M0 cleanup), [native fill broadcast](../../../../apps/stock/engine/src/backtest/engine.rs#L489). Exact postings fix arithmetic, not market modeling. A full multicurrency double-entry/margin/borrow engine is not required for v1.
## Migration and tests

View file

@ -18,7 +18,7 @@ Status: **approved by owner, 2026-10-22** (explicit “yes” to ADR-002/003/004
## Evidence and rationale
[Current same-event execution](../../../../apps/stock/engine/src/backtest/engine.rs#L249), [bar-close bid/ask](../../../../apps/stock/orchestrator/src/services/ExecutionService.ts#L224), [v1 timestamp contract](../../../../libs/core/types/src/historical-data.ts#L90), [invented VWAP](../../../../apps/stock/orchestrator/src/data/historical-dataset.ts#L230).
[Current same-event execution](../../../../apps/stock/engine/src/backtest/engine.rs#L249), historical bar-close bid/ask (`orchestrator/src/services/ExecutionService.ts`, retired in pre-M0 cleanup), [v1 timestamp contract](../../../../libs/core/types/src/historical-data.ts#L90), [invented VWAP](../../../../apps/stock/orchestrator/src/data/historical-dataset.ts#L230).
## Alternatives / tradeoffs

View file

@ -14,7 +14,7 @@ TS owns SQL custody, not independent accounting. No native/DB two-phase commit a
## Decision durability
Preserve [restore-before-each-step and intent transactions](../../../../apps/stock/orchestrator/src/execution/StrategyRecovery.ts#L151), [account locks and duplicate/conflict handling](../../../../apps/stock/orchestrator/src/execution/PostgresExecutionRepository.ts#L46), and existing failure tests. Paper strategy contexts use committed event views; never substitute a later account state. Restore RNG/decision cursors along with checkpoint state.
Preserve durable step recovery, account locks, and duplicate/conflict handling in [canonical paper execution custody](../../../../apps/stock/orchestrator/src/execution/canonical-paper.ts), along with existing failure tests. Paper strategy contexts use committed event views; never substitute a later account state. Restore RNG/decision cursors along with checkpoint state.
All currently supported paper order policies must be preserved or a migration explicitly refused. F05 covers market/limit and DAY/GTC/IOC/FOK; do not silently drop IOC/FOK at cutover.

View file

@ -16,7 +16,7 @@ The first isolation profile is a local Linux x86_64 Docker scratch image contain
## Evidence
[Current role model](../../../../libs/core/di/src/http/security.ts#L4) is a small operator boundary, not research isolation. [Current registry dependencies](../../../../apps/stock/orchestrator/src/strategies/StrategyRegistry.ts#L7) expose execution services that the new decision API must not expose.
[Current role model](../../../../libs/core/di/src/http/security.ts#L4) is a small operator boundary, not research isolation. Historical `StrategyRegistry.ts` (retired in pre-M0 cleanup) exposed execution services that the new decision API must not expose.
## Alternatives / tradeoffs

View file

@ -31,7 +31,7 @@ flowchart LR
WS --> UI
```
Evidence: [transactional submission](../../../apps/stock/web-api/src/services/backtest-v2.service.ts#L211), [dataset freeze](../../../apps/stock/orchestrator/src/backtest/BacktestRunner.ts#L190), [recovery](../../../apps/stock/orchestrator/src/execution/StrategyRecovery.ts#L151), [shared mode mutation](../../../apps/stock/orchestrator/src/container.ts#L101).
Evidence: [transactional submission](../../../apps/stock/web-api/src/services/backtest-v2.service.ts#L211), [dataset freeze](../../../apps/stock/orchestrator/src/backtest/BacktestRunner.ts#L190), legacy `StrategyRecovery.ts` (retired in pre-M0 cleanup), [container composition](../../../apps/stock/orchestrator/src/container.ts).
## Target: one product, one financial core