# CL20 — Return validated retained results from the worker supervisor Parent epic: E11. Priority/severity: P2 / Medium. Complexity: M. Specialist: TypeScript IPC and native worker lifecycle. Scheduling and commit evidence: [manifest](../manifest.json). Scope baseline: `700ee09c`. Owner authorized planning, implementation and one commit per completed task on 2026-10-26; CL21 remains conditional. Follow [quality gates](../../QUALITY-GATES.md) and [agent instructions](../../agents/implementation.md). ## Outcome and evidence NativeBacktestWorker.ts:132 parses a retained result but returns the untyped string at :161; RustBacktestAdapter.ts:85 parses it again. The concrete benefit is a smaller supported execution surface with unchanged financial behavior. Findings are verified at the baseline; recheck caller/module evidence before edits. This does not imply active financial corruption. ## Scope - Add a narrow typed retained execution entry or precise overload using the existing parser. - Retain parsed result only after identity/policy/artifact checks and resolve only after successful close and candidate cleanup. - Preserve trace callers/raw transport compatibility without a broad protocol redesign. - Keep separate trust-boundary and persistence validations. Likely files/modules: - `apps/stock/orchestrator/src/backtest/NativeBacktestWorker.ts` - `apps/stock/orchestrator/src/backtest/RustBacktestAdapter.ts` - `apps/stock/orchestrator/src/backtest/native-worker-protocol.ts` - `test/integration/retained-strategy-worker.test.ts` ## Exclusions No serialization optimization, sandbox redesign, extra process/service, removal of boundary validation or premature success before worker exit. Preserve retained strategy packages/datasets/results, useful algorithms, reviewed calculations, durable recovery and the existing .env files. No pushes, PRs or paper/live activation. ## Dependencies and ownership Prerequisites: [CL14](CL14.md) Write locks: `native-worker-protocol`, `canonical-adapter`. Parallelism: After CL14; separate from native Rust and historical storage edits. ## Acceptance criteria 1. Canonical adapter receives the already-validated typed envelope without reparsing. 2. Wrong identity/policy/artifact/analytics, nonzero exit after result, abort and cleanup failure cannot succeed. 3. Caller mutation cannot alter submitted/expected identity; trace/strategy callers retain their existing contracts. ## Mandatory verification - bun test test/integration/retained-strategy-worker.test.ts test/integration/canonical-worker-lifecycle.test.ts test/integration/canonical-strategy-worker.test.ts test/integration/native-replay-report.test.ts - bun run typecheck - Existing result-before-error/close, malformed envelope, mutation, cancellation and candidate cleanup regressions; add only missing cases Use isolated worktrees/build outputs and disposable safety databases/Redis only. Never rebaseline financial fixtures to hide changed behavior. Integrator runs repository checks on the combined source. Performance work remains deferred; no speed claims are part of acceptance. ## Risks and definition of done Returning before child cleanup, accepting mutated expected input, dropping validation for another request kind. Done requires scoped tests, independent reviewer acceptance, integration verification, and a focused commit. The manifest owns status and evidence; implementers do not edit it. Root records each completed commit in the next bookkeeping update; the task completion commit includes its tests/reviewer evidence, avoiding self-referential hashes. Unrelated prior CL01–CL13 review status remains unchanged.