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

@ -1,16 +1,16 @@
{
"schema_version": 1,
"plan_revision": "2026-10-23.42",
"plan_revision": "2026-10-23.44",
"repository_base": "b7aeca4",
"plan_status": "nineteenth_wave_review",
"plan_status": "twentieth_wave_review",
"execution_authorized": true,
"execution_scope": {
"authorized_by": "User: commit and continue after validated S05 handoff explicitly linked ADR-006 as next research product direction (2026-10-23). S05 accepted and committed 6a67ae868327eebc46872ab58e492933f582b7fd. ADR-006 direction approved by continuation; R11 chosen as next scoped vertical slice. Performance remains deferred.",
"authorized_by": "User: comit all and continue after validated R11 handoff named R01 next (2026-10-23). R11 accepted and committed b106c1ca85e853c7fbcd65fc54c83b9f1024f2ed.",
"tasks": [
"R11"
"R01"
],
"permissions": [
"R11 isolated implementation, correctness/browser tests, independent review and planning updates; prior S05 commit authorized/completed"
"R01 isolated implementation, correctness tests, independent review and planning updates; prior R11 commit authorized and completed"
],
"excluded": [
"performance_profiling_or_optimization",
@ -1390,7 +1390,7 @@
"epic": "E6",
"priority": "P1",
"severity": "High",
"status": "ready",
"status": "review",
"dependencies": [
"O01"
],
@ -1409,13 +1409,32 @@
"sql-migrations",
"strategy-catalog-api"
],
"parallel_policy": "Allowed only with satisfied dependencies/approvals and disjoint write locks AND actual files; see agents/integration.md.",
"assignment": null,
"parallel_policy": "Root owns pure shared contracts, credential helper, mounts/migration allowlist, trusted seeding and integration. Backend owns additive SQL, catalog service/routes/tests; packaging owns offline build/tests in disjoint worktrees; independent read-only review.",
"assignment": "/root",
"branch": null,
"pull_request": null,
"completed_commit": null,
"blocker": null,
"release_gates": []
"release_gates": [],
"integration_base": "b106c1ca85e853c7fbcd65fc54c83b9f1024f2ed",
"integration_state": "validated_uncommitted",
"worktree": "/home/boki/repos/stock-bot",
"implementation_slices": [
{
"owner": "/root/s04_controls_audit",
"scope": "Three-table additive migration, catalog API/service, PostgreSQL/HTTP tests",
"worktree": "/tmp/stock-bot-wave20.XIW6lx/backend"
},
{
"owner": "/root/s04_feed_audit",
"scope": "Offline built-in packaging and artifact conformance tests",
"worktree": "/tmp/stock-bot-wave20.XIW6lx/packaging"
},
{
"owner": "/root",
"scope": "Pure schemas/contracts, credential proof, legacy version rejection, composition, seed CLI, integration/planning"
}
]
},
{
"id": "R02",
@ -1745,7 +1764,7 @@
"epic": "E6",
"priority": "P1",
"severity": "High",
"status": "review",
"status": "done",
"dependencies": [
"D01",
"O01"
@ -1771,13 +1790,13 @@
"assignment": "/root",
"branch": null,
"pull_request": null,
"completed_commit": null,
"completed_commit": "b106c1ca85e853c7fbcd65fc54c83b9f1024f2ed",
"blocker": null,
"release_gates": [
"W04"
],
"integration_base": "6a67ae868327eebc46872ab58e492933f582b7fd",
"integration_state": "validated_uncommitted",
"integration_state": "accepted_committed",
"worktree": "/home/boki/repos/stock-bot",
"implementation_slices": [
{
@ -2509,6 +2528,32 @@
"Other backlog tasks"
]
}
},
{
"wave": "nineteenth_wave",
"scope": {
"authorized_by": "User: commit and continue after validated S05 handoff explicitly linked ADR-006 as next research product direction (2026-10-23). S05 accepted and committed 6a67ae868327eebc46872ab58e492933f582b7fd. ADR-006 direction approved by continuation; R11 chosen as next scoped vertical slice. Performance remains deferred.",
"tasks": [
"R11"
],
"permissions": [
"R11 isolated implementation, correctness/browser tests, independent review and planning updates; prior S05 commit authorized/completed"
],
"excluded": [
"performance_profiling_or_optimization",
"performance_benchmarks",
"new_wave_commits_without_further_approval",
"push",
"pull_requests",
"live_or_paper_operations",
"default_engine_cutover",
"other_backlog_tasks"
],
"pending_policy_decisions": [
"ADR-007",
"ADR-008"
]
}
}
],
"second_wave": [
@ -6561,5 +6606,138 @@
"b90c3964498805a5d69bc68540c53b85cef5b9729010d0681a2292d1aff679f8"
],
"next": "R01 immutable strategy versions is ADR/code-ready; performance remains deferred."
},
"twentieth_wave": [
"R01"
],
"twentieth_wave_base": "b106c1ca85e853c7fbcd65fc54c83b9f1024f2ed",
"twentieth_wave_notes": [
"Catalog versions are retained/validated/reviewable but all explicitly non-runnable until R05 (trusted built-ins) or A02 (arbitrary candidates). No canonical-to-legacy alias fallback.",
"R02 catalog/forms may land before R05; actual version-based execution requires R05. R01 does not change active legacy execution beyond rejecting unsupported catalog version references.",
"Trusted source packaging and seeding run offline, never in API. Retained bundles are authoritative executable bytes, not a claim of retaining original TypeScript source or whole-run reproducibility.",
"Catalog write/review identity requires credentials; existing loopback development bypass behavior remains unchanged elsewhere.",
"Performance remains deferred."
],
"twentieth_wave_validation": {
"state": "validated_uncommitted",
"task": "R01",
"base": "b106c1ca85e853c7fbcd65fc54c83b9f1024f2ed",
"evidence_directory": "/tmp/stock-bot-wave20.XIW6lx",
"source_archive": "/tmp/stock-bot-wave20.XIW6lx/r01-integrated-source.tar",
"source_archive_sha256": "e66dc7778506b7031e133096dae60d85f51a41f302847a5623636c3c9c87143f",
"source_hashes": {
"apps/stock/config/package.json": "2d333adc9382747be0165f89bcf9a505ca0f96348881275d160d58f26052a8fc",
"apps/stock/config/src/contracts/backtest.ts": "7d5319ae1e7ff036516b7c9d765768280c5283e342ce670167e4cd5f83c9b508",
"apps/stock/config/src/contracts/builtin-strategy.ts": "4550b956486ed592602ae54b1d9da3ceaa70d30eae7e4782ea580cf4f4c840ae",
"apps/stock/config/src/contracts/strategy-names.ts": "e0a2d4df53e0e25a6a628bbfc3a99e637a3fc0168b5ae284364e670d1f0140c0",
"apps/stock/config/src/contracts/strategy.ts": "0bbf9d1031de735027217d1abf928a33cc231619cb7380f481b88d5e36e35f4f",
"apps/stock/orchestrator/src/contracts/builtin-strategy.ts": "90111ec562227a8a6683eca82d136f39e70c78515594ad051dd089e6009bb3ef",
"apps/stock/orchestrator/src/contracts/strategies.ts": "4e3b65e6f085029b15b0ba40c04ff98c90fbf9ad51399a27feca4221e3480e40",
"apps/stock/orchestrator/src/contracts/strategy-names.ts": "a8cae1080a1adc96af8e75d54c7dfd11bac783482144544d212a81a250455102",
"apps/stock/web-api/package.json": "a7b6195ae6d85c6f6e8f71c95966b679ddaa96bedcab9755ee59669abb0c5a05",
"apps/stock/web-api/src/migrations/migration-runner.ts": "d4082b767d2cfa46cdd2c94e8b532409703a026e8ee289bd7d93374537152ede",
"apps/stock/web-api/src/routes/backtests-v2.routes.ts": "9c15ed3edc98c1ca2a96501b1a0bc8253365f3d2cd3013f6c363fdc960ac13d4",
"apps/stock/web-api/src/routes/create-routes.ts": "86021b72409fd6d9de1118afac966ba84c157de6f2a77f988db141cc1bc6eded",
"apps/stock/web-api/src/routes/strategies.routes.ts": "17e1ec0d908157e29deaa63d0852c82b4cb28268e92fcc7693e431d0c0a5f115",
"apps/stock/web-api/src/services/strategy-catalog.service.ts": "524aa623e2487418da3bf09c8465f7a69e1262812c9e0a3c19f4ed19159174dd",
"bun.lock": "5a45fe3ab33deb5cf8a6a7268072d05d5532e6251d31985430c3d1d900fa36ea",
"database/postgres/init/16-strategy-catalog.sql": "b4aefd6defc8d5b3ea54eb42106d894eab431ef50d10616ad58cf8a2d11c7b07",
"libs/core/di/src/http/security.ts": "50aaa48f93a1388ecff9d7ece8a11b96cab2a2f4d238ae85097849101a2aacaf",
"libs/core/di/src/index.ts": "0c54996e95f27d877d82e5d60df926371b07c26a32bca6839a56f363f31c06fc",
"libs/core/types/src/index.ts": "b0d5aff5444fc58812f05e21597de215e3e40b670c971ae1303a1fe1b1b9e6de",
"libs/core/types/src/strategy-version.ts": "defe9b9a72229fa95490201965c03602bb6b83f6f5e7c624260cc0857362b22f",
"scripts/package-builtin-strategies.ts": "6dd950e808cd43303e9cf8647712e799a9540cd87b24ca9868b31ff138298996",
"scripts/seed-builtin-strategies.ts": "f8a53726994aa07c549586857483b266b5ec18ab6306ab1ca4d4f3e2dad15153",
"scripts/test/architecture.test.ts": "4c95143f1c237155051b872004b3454851863019fbf8177d9db7094d79b6e0f3",
"scripts/test/strategy-packaging.test.ts": "20fd06d300691bb1f6914d100270b4e10a475dd9270ab6a42c19b2da8c70ab9c",
"test/integration/strategy-catalog-api.test.ts": "7d41f852a9ed6dba60bd28b0d4e0790af1f6c751b8ae9119848aeb2463f95f04",
"test/integration/strategy-version-contract.test.ts": "f0ea588b0dbd8c0793d5e5768fef676161da90fbee0d77b5c683d6fb0afaaf90",
"test/postgres/migration-runner.test.ts": "d2473c534e5eaeac5d7813b719dd4a58d1c9234d7db57c78b195b5fc428b66ed",
"test/postgres/strategy-catalog-seed.test.ts": "f0326abdb81865a9981fe2fd1a183c4fbf3e8f673a52ef6a1514567c05eed78a",
"test/postgres/strategy-catalog.test.ts": "094d0920f5c2abafa96d0d4d0da7b8d30bdef5b8067d645f2a1cd74aa4377c53",
"tsconfig.check.json": "dc301eb7a89afd838afdcb09c1fc32cfee898d3fb26913fb3ff2be01c09bd19a"
},
"independent_review": {
"owner": "/root/s03_review",
"outcome": "G1/G2 and catalog security accepted; no remaining must-fix findings. Retained bundles, SQL custody, actor receipts, lineage and review/execution separation verified by source review. Reviewer did not run tests.",
"backend_archive_sha256": "5603c18b6f7b34b1a5a0210ce8ff731cbf538f60c177ac8ad2010646da453ff2",
"packaging_archive_sha256": "bdea404390eda37131983ae10bd13f30507a2cb8bbb0dee780d1936fe2d4f42d",
"root_final_adjustments": "Formatting braces in packaging/root tests; architecture allowlist expanded only for pure strategy contract plus explicit source-based browser bundle check; strict root mock types and reserved metadata-key regression."
},
"checks": [
{
"command": "CARGO_BUILD_JOBS=2 bun run check",
"log": "/tmp/stock-bot-wave20.XIW6lx/check.log",
"outcome": "Build/source/contracts, 43 utility, 44 calculation, 509 integration and 150 Rust tests (4 manual ignored) passed. Initial tooling allowlist and root curly lint failed and were corrected; failed gates rerun below."
},
{
"command": "bun run test:tooling",
"log": "/tmp/stock-bot-wave20.XIW6lx/tooling-final-source.log",
"outcome": "93 tests / 12140 assertions passed. Pure strategy subpath explicitly allowed and independently checked. New browser-bundle test resolves current type source rather than generated dist; prior full-suite attempt hit Bun generated-file read errors, isolated test had passed."
},
{
"command": "bun run lint:check",
"log": "/tmp/stock-bot-wave20.XIW6lx/lint-final.log",
"outcome": "Passed all application/library/tool source lint."
},
{
"command": "PIPELINE_TEST_DATABASE_URL=postgres://fixture:fixture@127.0.0.1:32823/stock_bot_safety BACKTEST_TEST_REDIS_URL=redis://127.0.0.1:32824/15 bun run test:postgres",
"log": "/tmp/stock-bot-wave20.XIW6lx/postgres.log",
"outcome": "122 tests / 903 assertions passed. Includes additive migration repeat/concurrency, immutable versions/reviews, publication races, archive/clone/seed lineage, UTF-8/hash validation, real builtin seed-to-mounted HTTP workflow, existing durable recovery."
},
{
"command": "CARGO_BUILD_JOBS=2 bun run --cwd apps/stock/engine build:release",
"log": "/tmp/stock-bot-wave20.XIW6lx/native-release.log",
"outcome": "Release addon restored; SHA256 equals checkout release library."
},
{
"command": "bun test test/integration/strategy-version-contract.test.ts test/integration/canonical-builtins.test.ts test/integration/canonical-sma.test.ts test/integration/canonical-mean-reversion.test.ts test/integration/canonical-strategy-worker.test.ts test/integration/strategy-catalog-api.test.ts",
"log": "/tmp/stock-bot-wave20.XIW6lx/release-focused.log",
"outcome": "65 tests / 377 assertions passed with release addon. Final additional reserved-key assertion passed in contract rerun below."
},
{
"command": "bun test test/integration/strategy-version-contract.test.ts",
"log": "/tmp/stock-bot-wave20.XIW6lx/final-contract-tests.log",
"outcome": "5 tests / 40 assertions passed, including reserved-key rejection before metadata can be stripped."
},
{
"command": "PIPELINE_TEST_DATABASE_URL=postgres://fixture:fixture@127.0.0.1:32823/stock_bot_safety BACKTEST_TEST_REDIS_URL=redis://127.0.0.1:32824/15 bun run test:e2e",
"log": "/tmp/stock-bot-wave20.XIW6lx/e2e.log",
"outcome": "6 browser workflows / 66 assertions passed against final routes/security and release addon; legacy web functionality preserved."
},
{
"command": "bunx tsc --project /tmp/stock-bot-wave20.XIW6lx/tests-tsconfig.json --noEmit",
"log": "/tmp/stock-bot-wave20.XIW6lx/strict-tests-final.log",
"outcome": "Passed strict types for new APIs/contracts/packaging/seed scripts and integration/PostgreSQL tests."
},
{
"command": "bunx eslint --no-ignore <changed TS except existing ignored architecture-test style> --max-warnings 0; bunx prettier --check <changed TS/JSON>; git diff --check",
"logs": [
"/tmp/stock-bot-wave20.XIW6lx/scoped-lint-final.log",
"/tmp/stock-bot-wave20.XIW6lx/scoped-format-final.log"
],
"outcome": "Passed. Existing architecture test style remains covered by tooling tests, not an unrelated formatting rewrite."
}
],
"native_release_sha256": "ef00eed556f5c32332d36a9a00ef710682e90deb00b54552e4b5c8bfdfbe8103",
"scope": "30 source/config/migration/test files. One additive migration; existing Zod dependency explicitly declared for web-api. No Rust financial code, browser catalog implementation or engine activation.",
"limitations": [
"All catalog versions are non-runnable; R05 must verify/load retained built-in artifacts, A02 gates arbitrary candidate execution.",
"Retained bundled JavaScript is authoritative content. Original TypeScript source and whole-run provenance are not claimed to be retained by R01.",
"Operator/service credentials identify the existing single-owner roles, not individual human identities. Development auth bypass is excluded from catalog mutations.",
"Only explicit local seed command compiles repository built-ins. No production/development catalog was seeded during this wave.",
"R10 still must protect existing template/run/result/dataset evidence from deletion; strategy version/review retention and checksums already exist."
],
"environment_notes": [
"Offline bun install required escalation after tempdir write restriction; added only the API direct Zod declaration and matching lock entry, no new dependency version.",
"Initial declaration-generation private-brand error was fixed with explicit Zod shape/effect aliases, preserving input/output types and runtime validation.",
"Initial architecture browser bundle read of generated types failed only in combined tooling suite; source resolution made the assertion deterministic and checks current source.",
"Only exact disposable fixture containers stopped; worktrees/logs retained. No performance work, benchmark measurements, live/paper operations, push, PR or R01 commit."
],
"stopped_fixture_ids": [
"ca8a880ef81bbace95ca5fae84328a086f7f68580b0bdc754c507732989df943",
"51c5b994f16c6c2bc7f095d6d9946457cb62a0ac2df5f1a3a8f2be0516f4be78"
],
"next": "After acceptance/commit, R10 retained research evidence is the next foundation; R02 catalog UI can proceed in parallel only with disjoint files. Performance remains deferred."
}
}

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.

View file

@ -46,7 +46,7 @@ Parallel eligibility: only with disjoint actual files and reserved write locks;
- User can create/clone metadata, choose immutable version and schema-valid parameters, then open the existing run flow.
- Unavailable native/custom strategy choices are not offered as runnable.
- Version detail links deployment/backtest history when available; absent histories show empty states.
- During legacy migration only registered artifacts matching the current supported build are runnable; version selection is persisted, but legacy runs remain unproject-gated until R05.
- Catalog browsing, metadata, version comparison and parameter forms can ship after R01. Persist version selection, but disable version-based submission until R05 verifies and executes retained artifacts. Never map canonical catalog versions to legacy name-based strategies. Existing independent legacy runs remain visibly qualified.
## Mandatory tests

View file

@ -63,3 +63,7 @@ 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.
## Predecessor capability — R01
R01 already protects strategy versions/review events from update/delete and verifies retained artifact/lock checksums on retrieval. Reuse those paths. R10's remaining work is existing template/run/result/dataset retention and compatibility; do not create a second artifact store or repeat the catalog implementation. R01 currently has no run-to-version link; add references only with the task that introduces them.