73 lines
6.3 KiB
Markdown
73 lines
6.3 KiB
Markdown
# A02 — Isolate untrusted TypeScript strategy builds and decisions
|
|
|
|
Parent epic: E8. Priority/severity: P1 / High. Relative complexity: L. Recommended specialization: Process isolation/security.
|
|
|
|
Scheduling source of truth: [manifest entry A02](../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
|
|
|
|
- **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).
|
|
- **STR-01 — Verified:** Registry is a useful small boundary, but its factories receive mode/execution services; BaseStrategy mixes author decisions, order submission and hidden signal filtering. [apps/stock/orchestrator/src/strategies/StrategyRegistry.ts:7](../../../../apps/stock/orchestrator/src/strategies/StrategyRegistry.ts#L7); [apps/stock/orchestrator/src/strategies/BaseStrategy.ts:315](../../../../apps/stock/orchestrator/src/strategies/BaseStrategy.ts#L315).
|
|
|
|
## Intended behavior and implementation scope
|
|
|
|
Compile/import AI artifacts only in an OS-restricted process/container without network, secrets, DB, broker access or full future dataset. Engine supervisor sends prefix-only context and receives intents through a small IPC protocol. Apply wall/CPU/memory limits; pin artifact dependencies. node:vm alone is not a security boundary.
|
|
|
|
Measurable benefit: Makes arbitrary AI code execution a contained research capability.
|
|
|
|
## Exclusions
|
|
|
|
No speculative distributed infrastructure or weakened correctness gates.
|
|
|
|
## Likely files and ownership
|
|
|
|
- apps/stock/orchestrator/src/backtest/ (isolated strategy host)
|
|
- apps/stock/web-api/src/services/ (artifact registration)
|
|
- scripts/ (sandbox launch profile)
|
|
|
|
Write locks: sandbox-contract, worker-protocol. One agent owns this change. Lock names do not override actual overlapping files.
|
|
|
|
## Dependencies and blockers
|
|
|
|
Implementation requires [A01](A01.md), [S01](S01.md), [P01](P01.md) integrated.
|
|
|
|
Architecture decisions: ADR-007. 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
|
|
|
|
- Malicious imports, filesystem/network/env probing and infinite loops fail safely without affecting the API/paper process.
|
|
- Candidate cannot access future bars through files/native handles; only the supervisor owns financial engine and data.
|
|
- Trusted reviewed artifact fast path is an explicit human promotion, never self-selected by code.
|
|
|
|
## Mandatory tests
|
|
|
|
- deny_network_secret_read_child_spawn, infinite_loop_kill, malformed_intent, future_context_exfiltration, worker_cleanup.
|
|
- Sandbox availability check fails closed; benchmark IPC overhead separately from trusted NAPI path.
|
|
|
|
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
|
|
|
|
Native runtime/process privileges can invalidate the sandbox; independent security review required.
|
|
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.
|
|
|
|
## 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.
|
|
|
|
|
|
## Pinned implementation contract — 2026-10-24
|
|
|
|
Preserve built-in request bytes and the canonical Rust engine. Add an origin-discriminated candidate branch retaining nullable review only for candidates, server-bound baselineVersionId, generic target selection and exact sandbox execution descriptor. Package execution declares fixed warmupBars. Candidate overrides change version/derived owner identities and parameters only; the original frozen template financial grant remains exact. Explicit operator own-candidate grants authorize owned unreviewed versions in isolation. Revocation blocks new work; ordinary approval never selects a trusted research import.
|
|
|
|
Use the existing durable runner and shared async replay lifecycle. One isolated container receives only published observations/context and returns strictly validated owner/barrier/sequence/decision intents; Rust owns every economic result. The Linux x64 local scratch image contains pinned installed Bun, required runtime libraries, trusted host and a small independent guardian; no external downloads or host/data/secret mounts. Fixed profile:512MiB,1CPU,64PIDs,16MiB tmp,300s wall,8MiB protocol frame and64KiB captured stderr. Shorter agent attempt deadline wins. Missing enforcement fails closed. Test process/namespace/network/filesystem denial, resource exhaustion, malformed/forged messages, cancellation and supervisor death through actual container removal.
|
|
|
|
A small same-sandbox CLI may transpile self-contained TypeScript without importing it or installing dependencies; no remote build service. Candidate code is not automatically deterministic or unfitted: retain an unverified-candidate chronology policy, author-declared warmup and actual reproduction comparison. Preserve all built-in chronology bytes. A04's separate human promotion receipt controls trusted paper imports.
|
|
|
|
Root owns browser/response integration; A02 owns SQL29 and worker/contracts. Runtime registry/bootstrap merges are serialized by root. Full acceptance still requires native/SQL/browser and independent isolation review; feasibility probes alone do not close A02.
|
|
|
|
## 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.
|