stock-bot/design/development/architecture/decisions/007-ai-boundary.md
2026-11-27 00:12:48 -05:00

3.2 KiB

ADR-007 — AI authorization, code isolation and promotion

Status: implementation authorized by owner, 2026-10-24, through the instruction to complete all remaining scheduled tasks. Research-only quotas, OS isolation and no autonomous live access remain mandatory. Actual paper activation still requires a deliberate human action; no trading is activated by development or task closure.

Selected approach

Use existing operator authentication plus explicit research-agent identity/scope. AI may create hypotheses/candidate artifacts and submit bounded experiments, but cannot loosen account risk, choose its own privileges or invoke paper/live administration.

Unreviewed code is built/imported/evaluated in an OS-restricted process or container with no network, secrets, database, broker credentials, shared writable paper state or full future dataset. The financial supervisor sends prefix-only contexts over IPC. Require CPU/wall/memory/process limits and safe cancellation. A JS vm or a separate unrestricted process alone is insufficient.

Trusted registered/reviewed artifacts can run beside NAPI in a worker for speed. Moving an artifact into that tier requires an explicit operator action, never an AI-supplied trust flag. If the sandbox is unavailable, reject untrusted execution; do not silently downgrade.

Implementation clarification (A02/A04): the trusted research path is limited to server-registered built-ins. Catalog approval never changes a candidate's isolated research execution. A separate immutable human paper-promotion receipt may authorize the exact candidate factory in the paper host after held-out/cost evidence and financial-build parity checks. That action is a deliberate trust decision; paper starts unbound/halted, and live remains unavailable.

The first isolation profile is a local Linux x86_64 Docker scratch image containing the installed Bun runtime, trusted protocol host and independent Rust PID1 guardian. It has no host/data mounts or network, uses cgroup limits and a restricted unprivileged child, and dies on supervisor disconnect or a monotonic deadline. Version the image, host, guardian, runtime and policy in retained requests. A standalone restricted transpiler accepts self-contained TypeScript; no dependency installation, remote build service, JavaScript VM security claim or second simulator is introduced.

Evidence

Current role model is a small operator boundary, not research isolation. Historical StrategyRegistry.ts (retired in pre-M0 cleanup) exposed execution services that the new decision API must not expose.

Alternatives / tradeoffs

Running all AI code in the API/engine process is fast but not a meaningful protection against future-data reads or credential access. Sandboxing all reviewed code unnecessarily penalizes the trusted fast path. IPC has a cost; P01/A02 measure it separately.

Migration

A01 adds actor/budget admission; A02 adds isolation; A03 composes existing research APIs; A04 permits only human-reviewed paper promotion after paper gates. Limits apply to autonomous job budgets and resource use, not arbitrary truncation of the owner's datasets. Local dev .env policy is not changed by this plan, but sandboxed code must never receive its contents.