feat(research): isolate candidates and add reviewed paper promotion
This commit is contained in:
parent
26b97265c6
commit
25b5cbf481
128 changed files with 13038 additions and 1388 deletions
78
README.md
78
README.md
|
|
@ -4,6 +4,84 @@ Bun/TypeScript workspaces for market-data collection, processing, APIs, and a Re
|
|||
with a Rust native trading engine. `apps/wcag-ada` is an independent project and is not part of
|
||||
the root workspace checks.
|
||||
|
||||
## Current research workflow
|
||||
|
||||
The web workbench is the primary interface: Strategies → Backtests → Experiments →
|
||||
Research findings. New runs use retained inputs and the canonical Rust financial engine.
|
||||
The supported default is one asset and one execution series, long-only, with explicit
|
||||
cash, fee, slippage and risk policies. Previous results and legacy execution code remain
|
||||
readable; the historical architecture sections below do not enable legacy execution for
|
||||
new research. Multi-asset default policy and live trading remain gated.
|
||||
|
||||
Built-in reviewed strategies use the trusted TypeScript callback path. Arbitrary retained
|
||||
TypeScript candidates always use the isolated path, including after ordinary catalog
|
||||
approval. Both send target intents to the same Rust engine. Neither the browser nor a
|
||||
strategy implements account or fill accounting. `ownerBudget` is a strategy sizing input;
|
||||
the engine's portfolio constraints are the actual financial limits.
|
||||
|
||||
`services.orchestrator.backtesting.maxConcurrent` selects 1, 2 or 4 independent durable
|
||||
workers (default 1). It parallelizes trials, never concurrent transitions within one account.
|
||||
|
||||
### Prepare an isolated candidate
|
||||
|
||||
After the normal repository build, explicitly build the trusted local sandbox image:
|
||||
|
||||
```sh
|
||||
bun run scripts/build-candidate-sandbox.ts
|
||||
bun run scripts/package-candidate-strategy.ts metadata.json strategy.ts > candidate-package.json
|
||||
```
|
||||
|
||||
The sandbox currently requires Linux x86_64, local Docker with cgroup v2, memory/swap/CPU/PID
|
||||
limits, seccomp and AppArmor, plus `rustc` and the pinned Bun runtime. The image is built
|
||||
from installed trusted runtime files without pulling a base image. The descriptor and
|
||||
image ID are frozen into each request; a missing or different installation fails closed.
|
||||
Preserve the matching image and descriptor when retaining runs for reproduction.
|
||||
|
||||
`metadata.json` supplies `program`, `parameterSchema`, `source`, `entryExport` and
|
||||
`execution: { "kind": "isolated-candidate/v1", "warmupBars": 0 }`. Set the warmup to the
|
||||
maximum required by all intended parameter combinations. Use the
|
||||
[retained package contract](libs/core/types/src/strategy-version.ts) and
|
||||
[strategy decision API](apps/stock/orchestrator/src/contracts/canonical-strategy.ts).
|
||||
The entry export is a synchronous factory receiving the retained selection and returning
|
||||
a target-mode strategy with explicit JSON state. The CLI transpiles self-contained
|
||||
TypeScript inside isolation; it does not evaluate the source or install dependencies.
|
||||
|
||||
Upload the package on the strategy page, validate parameters, then select its immutable
|
||||
version in a saved backtest or experiment. Publication never starts a run. Candidates
|
||||
receive only published observation/context prefixes, with no host filesystem, network,
|
||||
credentials, broker or database access. The frozen sandbox policy limits each attempt to
|
||||
512 MiB, one CPU, 64 PIDs and at most 300 seconds; a shorter agent deadline wins. Author
|
||||
warmup declarations and seeded helpers do not prove that arbitrary JavaScript is free of
|
||||
leakage or nondeterminism. Inspect diagnostics and reproduce the actual result.
|
||||
|
||||
### Run an AI research cycle
|
||||
|
||||
An operator creates a research-only agent on the Research agents page, grants the project
|
||||
and saved template, explicitly allows its own candidates, and sets bounded job budgets.
|
||||
Give that research token to the client, never an operator or brokerage credential.
|
||||
|
||||
```sh
|
||||
RESEARCH_API_ORIGIN=http://127.0.0.1:3001 RESEARCH_API_TOKEN=sb-research.… \
|
||||
bun run scripts/examples/research-cycle.ts --plan prepared-plan.json --receipts new-receipts.jsonl
|
||||
```
|
||||
|
||||
[ResearchCyclePlan](scripts/examples/research-cycle.ts) defines the input. Supply prepared
|
||||
packages, parameters, bounded grids, chronological windows and cost scenarios before
|
||||
reading results. The example runs training first, freezes the server-selected candidate,
|
||||
then evaluates holdouts and costs, retaining failed trials and exact evidence citations.
|
||||
Findings remain explicitly AI-authored and unvalidated narratives. Use
|
||||
[ResearchClient](scripts/research-client.ts) for individual APIs, including walk-forward.
|
||||
|
||||
The receipt journal is mandatory and created exclusively. On interruption, inspect its
|
||||
intents and accepted IDs, reopen durable resources, and retry only the exact idempotent
|
||||
request. Do not blindly restart a cycle: hypothesis, family and finding creation do not
|
||||
have replay keys. The client cannot promote or activate paper/live trading.
|
||||
|
||||
Human paper promotion uses the separate `/paper` workflow and a configured, initially
|
||||
halted paper host. See [paper setup and evidence requirements](docs/development/architecture/research-product.md).
|
||||
Creating a deployment is distinct from binding and activating it; development tests use
|
||||
disposable accounts only.
|
||||
|
||||
## Build and verify
|
||||
|
||||
Use Bun 1.2.17, Node.js 18 or newer, and a Rust toolchain with a native linker. CI uses Rust
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue