feat(research): retain immutable strategy versions and review history

This commit is contained in:
Boki 2026-10-23 19:35:56 -04:00
parent b106c1ca85
commit 4a2e5ad362
36 changed files with 3236 additions and 148 deletions

View file

@ -30,7 +30,7 @@ No general workflow framework, browser IDE, multi-tenant identity platform or se
- 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.
Write locks: sql-migrations, strategy-catalog-api. Root coordinates shared contracts; backend and packaging agents reserve disjoint actual files. Lock names do not override actual overlapping files.
## Dependencies and blockers
@ -42,7 +42,7 @@ Parallel eligibility: only with disjoint actual files and reserved write locks;
## Acceptance criteria
- Invalid versioned parameters reject before enqueue; only registered/reviewed supported artifacts run.
- Version parameters reject through the catalog validation API using the retained schema and exact registered built-in validators. R01 exposes no enqueue path: every catalog version is explicitly non-runnable until R05 (trusted built-ins) or A02 (arbitrary candidates). Existing legacy requests carrying catalog version IDs reject rather than silently execute current name-based code.
- 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.
@ -68,3 +68,26 @@ Keep migrations additive and previous results readable. Do not add a switch that
## 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.
## Execution contract — 2026-10-23
- Three additive tables only: editable/archiveable strategies, immutable strategy_versions with retained package JSONB and numbered lineage, append-only operator review events. No R03 placeholders, artifact store or delete cascade. SQL rejects version/review UPDATE/DELETE.
- Package v1 retains self-contained bundled JavaScript, exact Bun lock bytes, SHA256 hashes, source revision/dirty state, compiler identity, parameter schema and API/checkpoint identity. The bundle is authoritative executable content; source metadata does not imply original TS retention or full experiment reproducibility.
- Canonical SMA/MR schemas and aliases move to the existing pure stock-config subpath with compatibility reexports. JSON form schema is a small scalar subset; exact Zod cross-field validation remains authoritative. No uploaded validator or code executes in API.
- Offline packaging builds the two reviewed repository programs with workspace source resolution and no external runtime imports. A separate explicit local seed command registers these built-ins; HTTP publication always creates candidate origin. New/cloned versions start unreviewed. Operator approval/revocation appends audited events, never modifies executable content or enables execution.
- Publish and clone use actor/key receipts plus canonical content fingerprints. Read receipt before mutable parent state, lock parent for ordinal/archive decisions, recheck receipt, insert atomically; changed payload with same key conflicts. New key yields intentional new identity even for identical bytes. Clone retains parent lineage and clears registration/review.
- Catalog mutations require credential-backed operator/service identity; reviews require operator. The development bypass is not authorship proof. Existing routes preserve their prior authentication behavior.
- Metadata list/detail omits artifact/lock content; explicit artifact retrieval retains exact bytes. Version validation returns normalized parameters and `runnable:false`. No UI (R02), retained-artifact execution (R05), untrusted execution (A02), strategy financial changes or performance work.
## Validated handoff — 2026-10-23
Catalog APIs, additive migration 16, pure version/parameter contracts, offline built-in packaging and explicit local seeding are integrated and independently reviewed. Metadata is editable/archiveable; versions/reviews are immutable. Publish/clone receipts, stable built-in families, parent lineage, role checks and exact artifact checksums have real PostgreSQL coverage. New/cloned/rebuilt versions start unreviewed, and all versions remain non-runnable.
Local commands (not run against development data in this wave):
- `bun run scripts/package-builtin-strategies.ts --out /tmp/builtin-strategies.json` packages both trusted repository programs without database access.
- After normal migration startup has applied 16, set `STRATEGY_CATALOG_DATABASE_URL` explicitly and run `bun run scripts/seed-builtin-strategies.ts --seed`. It compiles the local built-ins itself, reuses their catalog families, retains package/lock bytes and leaves new versions pending review. It accepts no arbitrary artifact input and performs no schema migration or strategy execution.
HTTP metadata: `/api/v2/strategies`, `/strategies/:id/versions`, `/strategy-versions/:id`; full bytes use `/:id/artifact`; clone/review/parameter validation use `/:id/clone`, `/:id/reviews`, `/:id/validate`. Publication/clone require `Idempotency-Key`. Catalog mutations require actual operator/service credentials, even when other development routes permit loopback bypass; only operator may review. API-supplied names/flags cannot self-register trusted code.
Validation: 93 tooling, 509 integration, 150 Rust (four manual ignored), 122 PostgreSQL/Redis and six browser workflows passed, plus source/contracts/build/lint/strict changed-test types. Final release native regressions passed 65 tests. Exact sequencing, hashes, commands and raw logs are canonical in `manifest.json` → `twentieth_wave_validation`. R10 and R02 follow; no current engine switch, candidate execution, trading activation or performance work.