stock-bot/docs/development/backlog/tasks/A04.md

68 lines
5.2 KiB
Markdown

# A04 — Add human-reviewed promotion to paper deployment
Parent epic: E8. Priority/severity: P2 / Medium. Relative complexity: M. Recommended specialization: Full-stack paper trading integration.
Scheduling source of truth: [manifest entry A04](../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
- **OPS-02 — 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. [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).
- **AI-01 — Verified:** Existing small operator auth has read/admin/service roles, not a research-only principal or arbitrary-code isolation boundary. [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).
- **KEEP-01 — Verified:** Preserve transaction-scoped account locking, idempotent fills/event fingerprints, durable decisions and recovery checkpoints; these are real behavior, not interfaces alone. [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).
## Intended behavior and implementation scope
Human-only paper deployment of a frozen version requires S04 readiness, research-only permission separation and explicit evidence. It must work for human-authored as well as AI-originated strategies; the A03 AI client is not a prerequisite. Reuse version/evidence APIs and add a deployment record only when this flow is implemented.
## Exclusions
No speculative distributed infrastructure or weakened correctness gates.
## Likely files and ownership
- apps/stock/web-app/src/features/strategies/
- apps/stock/web-api/src/routes/ (paper promotion)
- apps/stock/orchestrator/src/paper/PaperTradingManager.ts
- database/postgres/init/ (optional deployment table)
Write locks: paper-runtime, web-strategies, sql-migrations. One agent owns this change. Lock names do not override actual overlapping files.
## Dependencies and blockers
Implementation requires [S04](S04.md), [R09](R09.md), [A01](A01.md), [R01](R01.md) integrated.
Architecture decisions: ADR-007, ADR-005. Agents may not independently amend their policies.
Parallel eligibility: only with disjoint actual files and reserved write locks; read FIRST-WAVE.md for the initial exact ownership boundaries.
## Acceptance criteria
- Research-only token cannot create/activate a deployment; operator must review OOS/cost evidence and limitations.
- Only paper deployment is offered; live remains explicitly unavailable.
- Promotion never overwrites existing account capital/checkpoints or silently upgrades strategy state.
## Mandatory tests
- human_only_promotion, immutable_deployment_version, incompatible_checkpoint_block, no_live_option.
- Browser AI candidate -> evidence review -> paper status workflow.
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
Performance measurements can hide semantic changes; require economic hash equivalence.
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.
## Web/API contract and user states
- API: POST paper-deployments and explicit activate/halt operations for operator only; read-only history for research clients.
- Backend/data dependencies: Optional deployments table with version/account/evidence FKs, existing durable paper state.
- Loading/error/empty behavior: Not-ready reasons, approval pending, active/halted/failed; no cosmetic success before backend confirmation.
- User-facing completion is demonstrated by the acceptance criteria and interaction tests above; a backend-only implementation is insufficient where a UI is in scope.
## 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.
## Accepted implementation — 2026-10-24
Completed and independently reviewed. The [final wave record](../../ROADMAP.md#thirty-eighth-wave-final-acceptance--2026-10-24) and canonical manifest contain the implementation commit, actual regression/SQL/browser proofs, measurement identities and remaining limitations. Completion does not activate real trading or waive conditional architecture gates.