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

5.4 KiB

R01 — Persist immutable strategy versions and parameter schemas

Parent epic: E6. Priority/severity: P1 / High. Relative complexity: M. Recommended specialization: Full-stack research product.

Scheduling source of truth: manifest entry R01. 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

Intended behavior and implementation scope

Add strategies and append-only strategy_versions; seed registered built-ins with source/bundle hash, parameter schema, checkpoint contract and review status. Store executable artifact bytes or an immutable retained artifact reference, dependency lock and source revision. Draft metadata can change; published executable versions cannot.

Measurable benefit: Pins executable strategy identity before adding experiments.

Project/hypothesis linkage is optional and must not require R03 tables or placeholder records. Add nullable foreign-key links only when both entity tables exist, in a coordinated additive migration; standalone versions/experiments work first.

Exclusions

No general workflow framework, browser IDE, multi-tenant identity platform or second simulator.

Likely files and ownership

  • database/postgres/init/ (new migration)
  • apps/stock/web-api/src/routes/ (strategy endpoints)
  • apps/stock/web-api/src/services/ (strategy service)
  • apps/stock/orchestrator/src/strategies/StrategyRegistry.ts
  • libs/core/types/src/strategy-version.ts (new)

Write locks: sql-migrations, strategy-catalog-api. One agent owns this change. Lock names do not override actual overlapping files.

Dependencies and blockers

Implementation requires O01 integrated.

Architecture decisions: ADR-006. 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

  • Invalid versioned parameters reject before enqueue; only registered/reviewed supported artifacts run.
  • An idempotency key plus content fingerprint makes identical publish retries return the same version; changed content with the same key returns409. An intentional new revision gets a new ID and lineage even if content matches.
  • Published source/schema/checkpoint/dependency content is immutable and retained. Review/approval is separately audited metadata, not a mutation of executable content.
  • Registration never executes candidate code in the API; arbitrary untrusted execution stays unavailable until A02.

Mandatory tests

  • strategy_version_immutability_postgres, schema_validation, artifact_hash_mismatch, clone_lineage.
  • Registry aliases and old definition compatibility.

Apply the relevant quality gates; 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

Schema/API backward compatibility, historical provenance and UI state regression. 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: GET/POST /api/v2/strategies; GET/POST /strategies/:id/versions; GET /strategy-versions/:id; POST clone. Parameters use a versioned JSON schema subset.
  • Backend/data dependencies: New strategy/version tables; existing strategy registry; source-artifact storage retained with version.
  • Loading/error/empty behavior: API typed validation errors,404 and409; UI arrives in R02.
  • 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.