stock-bot/design/m2-completion-audit.md

20 KiB
Raw Blame History

Milestone M2 Completion Audit & M3 Readiness Report (T-204)

Verdict: HOLD M3 — M2 is ~70% complete on master, with 7 concrete wiring/contract gaps remaining before M2 closure.

All sandbox-runnable TypeScript, ESLint, contract, and Rust native gates pass (0 errors, 0 warnings, 1,548 Rust tests and 1,848 targeted Bun tests green). Core M2 building blocks — send-ilp (T-190), the 6-tool MCP copilot server, file-mode PIT fundamentals/ceoPosts/teData curaters, QuestDB 10.2.0 schemas, and the TypeScript Feature Library — are landed and tested. However, desktop Claude Code cannot launch the MCP server end-to-end (T-196 entrypoint is absent on master), ceoPosts writes "post" instead of "ceo_post", MarketDataStore rejects crossSection/macroAsOf/fx('1m'), curate-qm-bars-1m has no CLI subcommand, Python stockbot lacks register_signal and M2 store methods, and the live quant QuestDB 10.2.0 ILP v2 + latency gates remain unverified.

Scope & Provenance Notes

  • Audit-only: Zero production code, build config, or CI changes (project CI is off).
  • Documentation path drift: Milestone and contract docs moved from docs/ to design/, while AGENTS.md (lines 43–48), CLAUDE.md (lines 3, 7–11), and README.md (lines 7, 9, 11–13, 142, 264, 435) still reference docs/*.md.
  • Sandbox boundary: Worktree .git metadata lives outside the agent sandbox, so every deliverable below was verified directly from source files, exports, CLI parsers, and test execution rather than git history. Host-only gates (bun run check, audit:secrets, worktree-git tests in scripts/test/, and PIPELINE_TEST_DATABASE_URL PostgreSQL suites) are verified by Studio's unsandboxed runner.
  • Prior M1 deferral: Per settled director decision (d52aa20), M1 equity eligibility classification and cutoff-separated Parquet benchmarking stay deferred in the backlog and do not block M2.

1. Sandbox-Safe Verification Gate Results

Executed inside the task worktree sandbox (network disabled; zero contact with QA MongoDB 27017/stock or QA PostgreSQL 5432/trading_bot):

Gate / Suite Command Exit Outcome & Counts
Typecheck bun run typecheck 0 PASS — 0 errors (tsc --project tsconfig.check.json --noEmit)
Contracts bun run test:contracts 0 PASS — 0 errors (tsc --project tsconfig.contracts.json --noEmit)
Lint bun run lint:check 0 PASS — 0 errors, 0 warnings (--max-warnings 0)
Utils bun run test:utils 0 PASS — 32 pass, 0 fail (59 expects, 3 files)
Calculations bun run test:calculations 0 PASS — 144 pass, 0 fail (76,602 expects, 12 files)
Native Rust CARGO_BUILD_JOBS=2 bun run test:native 0 PASS — 1,548 passed, 0 failed, 4 ignored across 57 suites (engine + curate-etl, incl. tcp_sends_separate_shards_and_half_closes, restatement_of_q1_after_q2_updates_q1_and_ttm_without_overwriting_q2, split_boundary_nvda_and_nexm_match_raw_bars_1d_closes)
M2 Research, DuckDB, QuestDB & Scripts bun test libs/research/ libs/data/duckdb/ libs/data/questdb/ scripts/test/security.test.ts scripts/test/workspace.test.ts 0 PASS — 1,032 pass, 0 fail (80,869 expects, 63 files; includes real-DuckDB fundamentalsAsOf restatement fixture and MCP Vault-fence suite)
Postgres Copilot Executor & Unit Suites bun test libs/data/postgres/test/research-copilot-executor.test.ts libs/data/postgres/test/research-copilot-executor-edge.test.ts test/unit/ 0 PASS — 640 pass, 0 fail (734,988 expects, 44 files)
Python SDK (python/tests/) python3 -m pytest N/A SKIPPED (env) — pytest / python/.venv not installed in the sandbox
Host-Only Gates CARGO_BUILD_JOBS=2 bun run check / bun --env-file=... test N/A HOST-ONLY — covered by Studio unsandboxed verification (.git metadata & 127.0.0.1:5432 PostgreSQL outside sandbox)

Research & Financial Invariants Verified Across Passing Suites

  • Economic ownership & durable inputs: Quant data curation owns immutable Zstd Parquet partitions (bars_1d, adj_factors, events, shorts, fx_1d, fundamentals_pit, macro) and QuestDB ILP v2 shards; PostgreSQL owns append-only trial_ledger, findings, and provider_caveats (database/postgres/init/37-research-findings.sql:81-99).
  • Holdout Vault fence: createQueryDataTool (libs/research/src/mcp/tools/query-data.ts) and openResearchCopilotStore (libs/data/duckdb/src/research-copilot-store.ts:40) hardcode vaultOperatorAuthorized: false, reject scope/vault_evaluation_only keys, clamp bounds strictly below vaultCutoffTs, and drop post-cutoff rows (libs/research/test/mcp-query-data.test.ts).
  • PIT & split conservation: Both Rust (tools/curate-etl/src/fundamentals_tests.rs:104) and real-DuckDB TypeScript (libs/data/duckdb/test/duckdb-market-data-store.test.ts:251,601-626) prove known_at <= asOf and Q1-after-Q2 restatement non-overwrite; tools/curate-etl/src/bars_1m_tests.rs:107,220 and run_curate_bars_1m_tests.rs prove NEXM.V (1:20) and NVDA.US (10:1) split price/volume un-adjustment within 0.5%.
  • Database & execution safety: Read-only MongoDB/Postgres adapters verified; zero paper/live execution write access in research/MCP surfaces.

2. M2 Deliverables & Exit Criteria Matrix

2.1 Deliverables (design/MILESTONES.md lines 87–98)

Area Status Landed on master (Exact Evidence) Concrete Gaps Remaining
M2.1 Research Copilot MCP & Notebook Snapshots PARTIAL All 6 tools wired in createResearchCopilotMcpServer (libs/research/src/mcp/copilot-server.ts:13-20,48); stdio host (libs/research/src/mcp/host/stdio-host.ts); Postgres adapters (libs/research/src/mcp/adapters/postgres-copilot.ts, postgres-trial-ref.ts, library-cards.ts, exchange-calendars.ts, bar-session-dates.ts); openResearchCopilotExecutor (libs/data/postgres/src/research-copilot-executor.ts); openResearchCopilotStore (libs/data/duckdb/src/research-copilot-store.ts:33); SQL schema (database/postgres/init/37-research-findings.sql); exportNotebookSnapshot (libs/research/src/notebook-snapshot.ts:594, notebook-snapshot-node.ts:67). (1) T-196 desktop entrypoint scripts/research-copilot-mcp.ts and "mcp:research-copilot" in package.json are missing; apps/stock/web-api/src/ has no optional SSE wrapper. (2) openResearchCopilotStore (libs/data/duckdb/src/research-copilot-store.ts:37) opens daily DuckDB only instead of composing createRoutedMarketDataStore + createQuestDbIntradayBarsReader for 1m queries. (3) analyze_signal (libs/research/src/mcp/tools/analyze-signal.ts:121-123) restricts signal.source to 'shorts' | 'fundamentals' (no ceoPosts, macro, or materialized features). (4) exportNotebookSnapshot has no CLI or MCP entrypoint and no end-to-end MCP study + marimo check-clean HTML + file_finding verification test.
M2.2 PIT Fundamentals, ceoPosts & Lagged teData PARTIAL File-mode CLIs curate-fundamentals, curate-posts, and curate-macro wired in tools/curate-etl/src/cli.rs:99-101,1295,1573,1684 and main.rs:228,238,250; Rust Q1-after-Q2 restatement test (tools/curate-etl/src/fundamentals_tests.rs:104); real-DuckDB TS fundamentalsAsOf implementation & restatement test (libs/research/src/market-data-store-duckdb.ts:2287, libs/data/duckdb/test/duckdb-market-data-store.test.ts:251). (1) EVENT_KIND_POST = "post" (tools/curate-etl/src/parquet_posts.rs:22) mismatches 'ceo_post' required by libs/research/src/market-data-store-duckdb.ts:108, libs/research/src/event-panel.ts:63, and python/stockbot/data.py:21, and run_curate_posts fails closed (EventsDatasetExists, tools/curate-etl/src/run_curate_posts.rs:133,389) if <out>/events already exists from curate-events. (2) createDuckDbMarketDataStore().macroAsOf (libs/research/src/market-data-store-duckdb.ts:2294-2296) throws MarketDataStoreNotImplementedError, blocking read-back of macro/part.parquet. (3) SourceCollection (tools/curate-etl/src/mongo_stream.rs:53-62) allowlists only the 8 M1 collections — no --from-mongo streaming for qmFinancials, qmFinancials-old, ceoPosts, or teData, and curate-fundamentals lacks --qm-financials-old merging. (4) Python stockbot.data.MarketDataStore (python/stockbot/data.py) lacks fundamentals_as_of and macro_as_of.
M2.3 QuestDB 10.2.0 Intraday & send-ilp (T-190) PARTIAL T-190 send-ilp CLI landed (tools/curate-etl/src/cli.rs:102,2290, main.rs:260, ilp_send.rs, ilp_send_tests.rs loopback TcpListener tests); curate-bars-1m and curate-fx-1m CLIs wired (cli.rs:97-98, main.rs:208,218); M2_INTRADAY_SCHEMAS (libs/data/questdb/src/schema.ts:13-63) with PARTITION BY MONTH, WAL, SYMBOL CAPACITY 65536 NOCACHE, DEDUP UPSERT KEYS; docker-compose.quant.yml:35-39,52-53 (nofile: 1048576, QDB_RAM_USAGE_LIMIT_BYTES=21474836480); NEXM.V (1:20) and NVDA.US (10:1) split tests (bars_1m_tests.rs:107,220, run_curate_bars_1m_tests.rs). (1) run_curate_qm_bars_1m (tools/curate-etl/src/run_curate_qm_bars_1m.rs, T-185) is not wired into cli.rs/main.rs (no curate-qm-bars-1m subcommand). (2) MarketDataStore.fx({ timeframe: '1m' }) throws MarketDataStoreNotImplementedError in TS (libs/research/src/market-data-store-duckdb.ts:1529-1530, delegated unchanged by createRoutedMarketDataStore at libs/research/src/market-data-store-routed.ts:184-186) and NotImplementedError in Python (python/stockbot/data.py:259). (3) No --from-mongo streaming for eodIntraday1M (3.40B docs) or qmIntraday (173.3M docs). (4) Live quant QuestDB 10.2.0 binary-double (0x10) TCP ILP v2 acceptance (tools/curate-etl/src/ilp_send.rs:15-21) and < 250 ms warm / < 1 s cold query latency are unverified.
M2.4 Versioned Feature Library (D04 / D11) PARTIAL TS registerSignal, runFeatureBatch, and Zstd Parquet writer landed (libs/research/src/feature-library.ts); built-in RET_1D_V1 (feature-library.ts:2166). (1) createDuckDbMarketDataStore().crossSection (libs/research/src/market-data-store-duckdb.ts:2283-2285) throws MarketDataStoreNotImplementedError, blocking read-back of materialized features/<name>/v<version>/ Parquet. (2) FEATURE_INPUT_DATASETS (libs/research/src/feature-library.ts:61-68) omits 'macro' and 'corporate_actions' and registers only 'RET_1D_V1'. (3) Python stockbot (python/stockbot/__init__.py, data.py, signals.py) lacks cross_section and register_signal (D04/D11).

2.2 Exit Criteria (design/MILESTONES.md lines 100–103)

Exit Criterion Status Evidence & Remaining Blocker
EC-1: Desktop Claude Code via MCP runs a fundamental + alt-data signal study and event study end-to-end, exports a marimo check-clean static HTML snapshot, and files a finding. OPEN All 6 MCP tools and exportNotebookSnapshot exist as libraries, but scripts/research-copilot-mcp.ts / "mcp:research-copilot" (T-196) is missing, ceoPosts cannot be read via event_study ("post" vs "ceo_post"), and no end-to-end MCP → HTML snapshot → file_finding verification exists.
EC-2: Restatement fixture test proves a restated Q1 (known_at > Q2) never overwrites Q2 in fundamentalsAsOf. SATISFIED (Offline Fixture) Proven in both Rust (tools/curate-etl/src/fundamentals_tests.rs:104) and real-DuckDB TypeScript (libs/data/duckdb/test/duckdb-market-data-store.test.ts:251,601-626), both passing in sandbox.
EC-3: Split-boundary test on NEXM.V (1:20) and NVDA.US (10:1) confirms bars_1m session closes match raw bars_1d closes within 0.5%, and 1y of 1m bars loads in < 250 ms warm / < 1 s cold. PARTIAL Split-boundary 0.5% fixture PASSES (tools/curate-etl/src/bars_1m_tests.rs:107,220, run_curate_bars_1m_tests.rs:split_boundary_nvda_and_nexm_match_raw_bars_1d_closes). Live quant QuestDB 10.2.0 binary-double (0x10) TCP ILP v2 load and < 250 ms warm / < 1 s cold benchmark remain UNVERIFIED.

3. Root-Cause Breakdown: Why M2 Auto Mode Parked 3 Consecutive Tasks

Four compounding operational issues explain why the prior M2 Auto Mode run stalled:

  1. studio/auto-* branch-reset drift left T-196 unported on master: Although T-190 (send-ilp) and T-194/T-202 (curate-macro) landed on master, the desktop MCP CLI wiring (T-196: scripts/research-copilot-mcp.ts and "mcp:research-copilot" in package.json) is absent on master. Downstream tasks assuming a runnable desktop MCP server hit an immediate missing-entrypoint blocker.
  2. docs/* → design/* path drift across agent instructions: AGENTS.md (L43–48), CLAUDE.md (L3, L7–11), README.md (L7, L9, L11–13, L142, L264, L435), and task prompts still point to docs/*.md, causing agents to waste turns or fail path checks against the renamed design/ directory.
  3. Sandbox boundary friction (.git & PostgreSQL): Running bun run check, audit:secrets, worktree-git tests (scripts/test/), or PIPELINE_TEST_DATABASE_URL (127.0.0.1:5432) suites inside the agent sandbox fails by design; tasks that treat those expected sandbox errors as code regressions or try to run live quant QuestDB checks from inside the sandbox park prematurely.
  4. Unqueued director-gated Option B --from-mongo extension for M2: The 2026-11-30 addendum in design/data-pipeline/rust-migration-evaluation.md (lines 253–294) locked Option B (tools/curate-etl --from-mongo) for M1 and scoped M2's 6 collections (qmFinancials, qmFinancials-old, ceoPosts, teData, eodIntraday1M, qmIntraday) to M2, but SourceCollection (tools/curate-etl/src/mongo_stream.rs:53-62) still allowlists only the 8 M1 collections, leaving M2 curation stuck in file-mode .bson staging.

4. Concrete Blockers Needing Director Decisions

  1. Option B --from-mongo for M2 collections vs. .bson staging: Should we extend tools/curate-etl SourceCollection with --from-mongo streaming for the 6 M2 collections (qmFinancials, qmFinancials-old, ceoPosts, teData, eodIntraday1M, qmIntraday), or close M2 in file-mode .bson staging?
    • Recommended: Extend --from-mongo to the 6 M2 collections (reusing the M1 ReadOnlyMongoClient + ChunkedMongoRawDocumentSource pattern) so 3.40B eodIntraday1M docs never require ~500–832 GiB of intermediate .bson scratch files.
  2. Canonical ceoPosts event kind & <out>/events co-publishing: Should tools/curate-etl/src/parquet_posts.rs switch EVENT_KIND_POST from "post" to "ceo_post" and co-publish alongside curate-events under <out>/events/year=YYYY/ (e.g. distinct filename part-posts.parquet or merged event partition), or keep posts in a separate curated root?
    • Recommended: Change EVENT_KIND_POST to "ceo_post" (matching TS EVENT_KINDS, event-panel.ts, and Python EventKind) and write a non-colliding file (events/year=YYYY/part-posts.parquet) so a single curated root serves filings, earnings, and ceoPosts together.
  3. Live quant QuestDB 10.2.0 ILP v2 & latency benchmark gate for M2 closure: Should M2 closure require an operator-run quant QuestDB 10.2.0 load verifying binary-double (0x10) TCP ILP v2 acceptance and the < 250 ms warm / < 1 s cold Exit Criterion 3 benchmark, or accept fixture-level closure and defer the live quant load/benchmark to an ops follow-up (matching the M1 d52aa20 precedent)?
    • Recommended: Require a small-slice (NEXM.V + NVDA.US, 1 year) operator verification on quant to confirm QuestDB 10.2.0 TCP ILP v2 binary-double acceptance and < 250 ms / < 1 s latency before closing M2, while deferring full 3.40B-row backfill to an ops runbook.

Verdict: Do not start M3 yet. M3's Exit Criterion 3 requires a real M2 signal promoted via register_signal to flow through Tier 1 Screen → Tier 2 Rust Engine → CPCV/DSR/PBO/Recency → Human 6m Vault Gate, and M3's starting baselines are untouched on master:

  • apps/stock/engine/Cargo.toml has no parquet or arrow crates yet (M3 Task 1 prerequisite: retire JSON-over-Postgres/IPC/N-API bar path).
  • libs/calculations/src/index.ts exports deflatedSharpeRatio, effectiveIndependentTrials, analyzeSignalPanel, eventStudy, and evaluateRecencyGate, but has no CSCV PBO (S = 16) or Purged Walk-Forward/CPCV yet.

5.1 Ordered Task List to Finish M2 (8 Tasks)

  1. Restore T-196 desktop MCP entrypoint & wire routed intraday store: Add scripts/research-copilot-mcp.ts + "mcp:research-copilot" in package.json, and update openResearchCopilotStore (libs/data/duckdb/src/research-copilot-store.ts) to compose createRoutedMarketDataStore + createQuestDbIntradayBarsReader when QuestDB config is present.
  2. Fix ceoPosts kind = 'ceo_post' & <out>/events co-publishing: Change EVENT_KIND_POST in tools/curate-etl/src/parquet_posts.rs to "ceo_post" and allow run_curate_posts to co-publish into <out>/events/year=YYYY/ without colliding with curate-events.
  3. Implement MarketDataStore.macroAsOf, crossSection, and fx('1m'): Implement DuckDB read-back for macro/part.parquet (macroAsOf) and versioned features/<name>/v<version>/ (crossSection) in libs/research/src/market-data-store-duckdb.ts, and route fx({ timeframe: '1m' }) to QuestDB fx_1m in libs/research/src/market-data-store-routed.ts.
  4. Wire curate-qm-bars-1m CLI & expand Feature Library inputs: Expose curate-qm-bars-1m in tools/curate-etl/src/{cli,main}.rs, add 'macro' and 'corporate_actions' to FEATURE_INPUT_DATASETS in libs/research/src/feature-library.ts, and extend MCP analyze_signal to support materialized features (and macro/ceoPosts as needed).
  5. Add Python stockbot M2 parity & register_signal (D04/D11): Expose fundamentals_as_of, macro_as_of, cross_section, fx(..., timeframe='1m'), and register_signal(...) in python/stockbot/ with offline pytest coverage.
  6. Extend curate-etl --from-mongo to the 6 M2 collections (subject to Director Decision 1): Add qmFinancials, qmFinancials-old (with --qm-financials-old merge), ceoPosts, teData, eodIntraday1M, and qmIntraday to SourceCollection in tools/curate-etl/src/mongo_stream.rs.
  7. Add M2 Exit Criterion 1 end-to-end verification & doc path cleanup: Add a CLI/MCP wrapper + end-to-end test covering MCP study → marimo check-clean HTML snapshot (exportNotebookSnapshot) → file_finding, and update stale docs/ links in AGENTS.md, CLAUDE.md, and README.md to design/.
  8. Operator quant QuestDB 10.2.0 ILP v2 & latency verification (Exit Criterion 3): Apply getM2IntradayDDL(), run send-ilp on a NEXM.V + NVDA.US 1-year slice against quant QuestDB 10.2.0 (verifying 0x10 binary-double acceptance via PGWire), and record warm (< 250 ms) and cold (< 1 s) 1-year 1m read timings.

5.2 Initial M3 Prerequisite Sequence (Once M2 Closes)

  1. Retire JSON-over-Postgres/IPC/N-API bar path (M3 Task 1): Add parquet/arrow-rs to apps/stock/engine/Cargo.toml, store (hash, manifest, parquet_paths) in backtest_datasets, and lift single-series TS gates in native-worker.ts.
  2. Tier 1 Columnar Screener & CSCV PBO (S = 16): Implement CSCV PBO and Purged Walk-Forward/CPCV in libs/calculations, plus vectorized Polars/DuckDB portfolio sweeps logging M_{T \times N} matrices to trial_ledger.
  3. Tier 2 Rust financial/ multi-asset upgrades: Atomic timestamp-slice marks (F06), simultaneous Target sell-netting, feature side-channel (features map into Replay/StrategyContext), and USD/CAD Margin + corporate-action/delisting accounting.