66 lines
5.3 KiB
Markdown
66 lines
5.3 KiB
Markdown
# D04 — Provide prefix-safe shared feature calculation
|
||
|
||
Parent epic: E3. Priority/severity: P1 / High. Relative complexity: M. Recommended specialization: Quantitative feature engineering.
|
||
|
||
Scheduling source of truth: [manifest entry D04](../manifest.json). No task is authorized until the plan is approved. Dependencies and decision references below describe the design; the manifest controls current readiness.
|
||
|
||
## Evidence and root cause
|
||
|
||
- **STR-01 — Verified:** Registry is a useful small boundary, but its factories receive mode/execution services; BaseStrategy mixes author decisions, order submission and hidden signal filtering. [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).
|
||
- **RES-01 — Verified:** Experimental Python feature preprocessing uses full-sample medians/quantiles; shuffled returns preserve ordinary Sharpe. These routines must not silently become validation 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).
|
||
- **KEEP-02 — Verified:** Preserve frozen/hash-verified historical snapshots and fenced durable runner attempts; extend them instead of creating a second job engine. [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).
|
||
|
||
## Intended behavior and implementation scope
|
||
|
||
Add a small feature request/result contract keyed by dataset hash, instrument, timeframe, parameters and implementation version. Reuse reviewed calculations; one experiment-local calculation per identical feature request. Prefix-gate precomputed outputs; no distributed feature service or persistent cache framework. Fitted/model features also key by artifact hash, fit-window identity and availability policy; they must not reuse a transform fitted on another partition.
|
||
|
||
Measurable benefit: Avoids duplicate work and feature leakage without a framework.
|
||
|
||
## Exclusions
|
||
|
||
No unrelated refactor, new service or broker activation.
|
||
|
||
## Likely files and ownership
|
||
|
||
- libs/calculations/
|
||
- apps/stock/engine/src/indicators/
|
||
- apps/stock/orchestrator/src/data/
|
||
- test/integration/strategy-contracts.test.ts
|
||
|
||
Write locks: feature-contract. One agent owns this change. Lock names do not override actual overlapping files.
|
||
|
||
## Dependencies and blockers
|
||
|
||
Implementation requires [S01](S01.md), [P01](P01.md) integrated.
|
||
|
||
No additional economic-policy approval is needed for this narrowly scoped task.
|
||
|
||
Deferred: Only after profiling demonstrates repeated identical feature work; use reviewed incremental calculations directly first.
|
||
|
||
Parallel eligibility: only with disjoint actual files and reserved write locks; read FIRST-WAVE.md for the initial exact ownership boundaries.
|
||
|
||
## Acceptance criteria
|
||
|
||
- Regime and strategy consumers requesting the same SMA/volatility share results within a run.
|
||
- Batch and incremental values match reviewed warmup/NaN semantics; a future data mutation cannot affect earlier features.
|
||
- Float feature outputs never become authoritative monetary calculations.
|
||
|
||
## Mandatory tests
|
||
|
||
- batch_incremental_parity, prefix_equivalence, shared_request_counter, warmup_alignment.
|
||
- Run calculations migration-preservation and numerical suites.
|
||
|
||
Apply the relevant [quality gates](../../QUALITY-GATES.md); submit exact commands, outcomes and skipped checks. Named cases above are required regression scenarios, not claims that those tests already exist.
|
||
|
||
## Regression risks and rollback
|
||
|
||
Compatibility or lifecycle regression; preserve frozen inputs, old results and existing failure tests.
|
||
Keep migrations additive and previous results readable. Do not add a switch that restores a correctness defect. Versioned cutover/migration is required only when persisted contracts or active engines change; never silently fall back to old economics.
|
||
|
||
## Handoff
|
||
|
||
Report scope changes (if any), fixture expectations, API/schema changes, measurements, remaining limitations and commit/PR references once authorized. Request independent review; only the integration/planning owner may mark the manifest done.
|
||
|
||
## Conditional review — October 28, 2026
|
||
|
||
No-go for now: in the instrumented 15/252 baseline, reviewed SMA calculation took 7–10 ms across three sessions; copying/freezing took roughly 2.0–2.3 seconds. A shared feature cache does not address the measured cost. Reopen only for measured repeated identical feature work across actual consumers, preserving prefix and fit-window identity. Status remains **deferred**, not implemented or silently cancelled. The owner authorized judgment on all remaining conditions and explicitly resumed performance work. [Current review](../../conditional-review.md). Earlier audit findings above are historical evidence: F02–F07/S06 already resolved competing financial cores and the old insertion queue; they are not reasons to implement this extension now.
|