# Restart chaos harness (Phase 1 MVP) Plan: [`doc/plans/2026-11-06-control-plane-restart-chaos.md`](../../doc/plans/2026-11-06-control-plane-restart-chaos.md). A script, not an LLM. It starts an isolated Paperclip control plane (temporary `PAPERCLIP_HOME`, wrapper-owned embedded Postgres, its own port), seeds a "Chaos Lab" company, launches real agent tasks, kills or restarts the control plane during those tasks, and grades every task on R1–R6 plus a deterministic T-oracle. This file covers running the harness, its modes, how tasks are graded, and its output. Each workload and fault scenario, with its command and oracle, is in [SCENARIOS.md](SCENARIOS.md). Add a note about one scenario there, not here. ## Run ```sh pnpm install --frozen-lockfile pnpm --filter @paperclipai/paperclip-runner run build:runner-binaries # native runner (debug) set -a; source ~/.secrets; set +a # provider keys, process env only node cli/node_modules/tsx/dist/cli.mjs tests/restart-chaos/main.ts --env local \ --adapters codex,claude,opencode --concurrency 4 --tasks 8 --faults K1,K2,K4 --seed 42 node cli/node_modules/tsx/dist/cli.mjs tests/restart-chaos/main.ts --replay w-20261106T101112-s42/t03 pnpm exec vitest run --config tests/restart-chaos/vitest.config.ts # credential-free unit tests node scripts/typecheck-test-projects.mjs tests/restart-chaos # typecheck ``` Options: `--triggers time,comment,retry,queued,tool,result` (fault timing, below), `--workloads A1,B1,B5,C1` (opt-in: G1, H1, L1, R1, S1, W2, W2Q, W2C), `--db-pressure ` ([SCENARIOS.md](SCENARIOS.md#database-contention-l1---db-pressure)), `--budget-cents` (company hard cap, default 3000), `--poll-ms` (2000–5000), `--keep` (keep the temporary instance), `--k4-hold-max-seconds` (raise the seeded K4 hold upper end from 300 s, up to the 600 s outage cap). `--faults K0` plans cells with no fault, for workloads whose shape is the fault (W2, in [SCENARIOS.md](SCENARIOS.md#re-wake-after-success-w2-w2q-w2c)). `--fail-recovery-step`, `--long-turn-minutes`, `--k15-overlap-seconds`, `--k15-fresh-home`, `--ephemeral-server`, `--runner-bind-fault`, `--workload staging-mix` and `--release-swap` are described in their own sections. `--fault-after-seconds ` fires every planned fault `n` seconds after its task launches (5–3600; with `--triggers time`), keeping the rest of the seeded plan, for example to restart a Daytona R1 task after its workspace preparation. `--matrix` crosses every selected workload with every fault kind ([SCENARIOS.md](SCENARIOS.md#journey--fault-matrix---matrix)), and `--server-from ` runs every server of the wave from another prepared checkout, for example a commit before a fix. Each wave's temporary instance (embedded Postgres, workspaces, often 5–13 GB) is deleted when the wave ends, pass or fail, including after an interrupt. Evidence is already copied into `results/`. Use `--keep` to inspect the instance itself. A kept instance, or one whose processes could not be stopped, gets a `.paperclip-runner-e2e-kept.json` marker; creating the next runner E2E or chaos instance removes marked instances older than 6 hours whose Postgres is no longer running and that no live process still references. An instance whose Daytona cleanup is still pending keeps its database as the owner of that cleanup and never expires. Unmarked directories are never removed. `--rc06-masked` keeps the company budget amount but disables its hard stop on the isolated Chaos Lab company, so one stuck accounting row (RC-06) cannot wedge every later task. Masked tasks are marked `rc06-masked` in the ledger and summary, and each wave still records its spend (`wave_spend` in the timeline). A replay inherits the masks saved in the source wave's `plan.json`; `--replay / --rc06-masked` adds the mask to a replay of an unmasked wave. Each fault receipt records the host 1-minute load average (`loadAvg1m`); treat timeout failures above about 16 as load-suspect. ## Fault timing (`--triggers`) Each task samples one trigger with its cell. `time` (default) fires at the seeded offset. The others fire relative to a user action or run state seen by the observer, after a seeded delay: | Trigger | Fires | Plan | | --- | --- | --- | | `comment` | 0–5 s after the C1 follow-up was posted to a live run (C1 only) | C1 + K1, B8 | | `result` | 0–3 s after the run that received the C1 follow-up proposed or accepted its result, only while that run is still `running` (C1 only) | C1 + K1, B8 | | `retry` | 0–2 s after an accepted Retry click, as an extra K1 after the planned fault | K8 | | `queued` | on the first poll whose run is still `queued` with no start | B1 | | `tool` | 15–60 s after `bench.sh` progress first appears (B5 only) | B6 | | `asked` | 0–3 s after the saved question or tool review is first seen pending (Q1–Q3) | journeys | | `answered` | 0–3 s after the board's answer or approval returned (Q1–Q3) | journeys | A trigger whose condition can no longer hold (comment posted at rest, run already started, no Retry offered) is recorded as `triggerMissed` in the ledger; the task is still graded. `--faults K6` is the crash loop: after the first kill, the replacement is killed again as soon as `/api/ready` reports `recovering` (or `ready`, if recovery was too quick to see), and once more just after `ready`. The receipt's `crashLoop` lists the phase each kill hit. A replay re-arms the task's own triggered faults instead of using their offsets. ## Daytona (`--env daytona`) The control plane stays local; agent runs execute in Daytona sandboxes from an immutable runner image. No Docker is needed. ```sh set -a; source ~/.secrets; set +a # DAYTONA_API_KEY plus provider keys, process env only node cli/node_modules/tsx/dist/cli.mjs tests/restart-chaos/main.ts --env daytona \ --daytona-image ghcr.io/paperclipai/paperclip-daytona-runner@sha256: \ --adapters codex,claude --tasks 3 --concurrency 2 --faults K1 --seed 11 ``` `PAPERCLIP_E2E_DAYTONA_IMAGE` can replace `--daytona-image`. B5 is local-only (its oracle reads the live workspace, which is inside the sandbox). **vCPU budget.** The Daytona org is shared with the live Cloud fleet. Chaos sandboxes use `--daytona-cpu` vCPU (default 4, with 4 GiB memory and 10 GiB disk), and `--concurrency × --daytona-cpu` must stay within 40 vCPU (`RESTART_CHAOS_DAYTONA_VCPU_BUDGET`). On a small org, set the budget below the org limit with room for verification probes: a 10 vCPU org fails creates with HTTP 400 "Total CPU limit exceeded", so use 8 there and `--daytona-cpu 2`. **Fleet safety.** The Daytona org is shared with the live Cloud fleet, and every plugin-created sandbox, the fleet's included, is named `paperclip-create-*`. The name therefore says nothing about who owns a sandbox; the labels do. Each wave's isolated instance mints a fresh company and environment UUID, and the Daytona plugin labels every sandbox it creates with both. Cleanup first deletes the wave's own environment through Paperclip. Then it deletes every sandbox that still carries both of this wave's labels (archived setup sandboxes included, since Daytona does not delete archived sandboxes on its own), and nothing else: the listing is filtered by both labels on the server and checked again on every row, and `assertHarnessMayMutate` refuses any sandbox without both labels and any `fleet-sbx-*` snapshot. The only delete is `DELETE /sandbox/` for a row that passed those checks. A wave sandbox still there after the settle window fails the wave (`undeletedSandboxes`, and the warm-shutdown verdict). **Image matching.** The controller needs the image's own Linux amd64 `/usr/local/bin/paperclip-runnerd` (`PAPERCLIP_RUNNER_REMOTE_BINARY_PATH`) and `/opt/paperclip-runner/provider-pack/` (`PAPERCLIP_RUNNER_REMOTE_PROVIDER_PACK_PATH`). `daytona-image.ts` gets them without a daemon: `skopeo copy --override-os linux --override-arch amd64 docker:// dir:`, then walks the layers from top to bottom (honouring `.wh.` and `.wh..wh..opq` whiteouts), extracts only those two paths, checks the ELF header, the pack manifest and the image labels, records their digests in `receipt.json`, and deletes the layer blobs. The result is cached in `tests/restart-chaos/results/daytona-images//` (or `$RESTART_CHAOS_IMAGE_CACHE`), shared by every wave and crash-point run, so it runs once per image. A copy that fails part-way, or stalls past its 20-minute bound (`RESTART_CHAOS_SKOPEO_ATTEMPT_TIMEOUT_MS`), retries from an empty directory. Run it alone with `node cli/node_modules/tsx/dist/cli.mjs tests/restart-chaos/daytona-image.ts `. **Provider-pack mismatch.** Because the controller takes its pack from the same image the sandboxes start from, the preinstalled pack always verifies and the upload path (`provider_pack.select` with `stateSource: uploaded`, reason `cached_packs_unverified`) and its session admission never run. Staging runs there whenever a deploy is newer than the sandbox image. `--daytona-pack-mismatch ` starts every sandbox from that other image (an older runner image) while the controller keeps `--daytona-image`'s runnerd and pack. Every fresh sandbox then uploads and verifies the controller's pack, and the session must record its admission before artifact retention. Pass: every task finishes with no Retry and no run ends with `native_provider_artifacts_admission_unverified`. The timeline records `daytona_pack_mismatch`. Before starting, the harness compares the image's `io.paperclip.runner.content-id` label with the content ID of this checkout (`pnpm test:e2e:runner:image-id`, which hashes every runner input) and refuses to run on a mismatch. For a local test of a branch that changes only controller-side TypeScript, set `PAPERCLIP_CHAOS_TEST_ACCEPT_IMAGE_CONTENT_ID` to the image's exact content ID to run against that existing image; the harness prints a `TEST OVERRIDE` warning and the timeline keeps both content IDs. Such a wave is not image qualification. To get an image for the current master, dispatch a narrow image build and reject its paid gate: ```sh gh workflow run runner-full-stack-e2e.yml --ref master -f cadence=manual -f all=false \ -f id=core-compatibility.runner-codex.daytona.message-marker # when the run waits on the paid environment: gh api -X POST repos/paperclipai/paperclip/actions/runs//pending_deployments \ -F "environment_ids[]=20786721735" -f state=rejected -f comment="Image build only" ``` The digest is in the "Publish verified Daytona image" job log (`pushing manifest for …@sha256:…`), or check out the image's `org.opencontainers.image.revision`. The harness also requires the image's provider pack to be the one a named commit built: the commit in the image's `io.paperclip.runner.source-revision` label, or, when the image has no such label, the image's own `org.opencontainers.image.revision`. An image that copied its Runner names the commit that built it in that label; an image that built its own Runner has none. An empty label counts as absent, because an image can empty a label of its base but cannot drop it. **Setup** reuses runner-e2e: the bundled Daytona plugin (`installFixtureDaytonaProvider`, prepared outside the root workspace as CI does), the `daytona` environment fixture from `catalog.ts`, and the native Codex platform-qualification probe. **R6 sweep.** After the wave, `daytona-sweep.ts` lists (read-only) the sandboxes whose `paperclip-company-id` and `paperclip-environment-id` labels both equal the UUIDs this wave's isolated instance minted, re-checks every row, and reconciles them with the environment's leases. It retries for the product's pending-cleanup backoff plus 90 seconds (6.5 minutes, capped at 8) before calling anything a leak. A sandbox archived after its lease was released is expected (the plugin archives on release and Daytona deletes it after 60 minutes). Any other live sandbox without a held lease, or an `active`/`pending_cleanup` lease, is a leak: it fails R6 for the task whose run owns it, or the wave when no task does. The harness then deletes the wave's environment through Paperclip and lists again: a wave sandbox that is still neither archived nor destroyed after 90 seconds fails the wave and is reported for a person to act on (the environment's 60-minute ttl also expires it). An environment DELETE that returns 409 because a sandbox cleanup is still pending is retried for the same settle window; if it is still blocked then, the wave fails (not as a harness error) and the instance is kept, because its database owns the cleanup work. The result is in `/sandbox-sweep.json`. **Clean warm shutdown.** Every warm wave (`--daytona-warm` or `--lifecycle warm`) also grades "no leaked sandboxes / clean warm shutdown" (`warm-shutdown.ts`). It fails the wave when the environment delete stayed blocked, when a wave sandbox is still running after cleanup, or when the server log shows a warm session that did not close on environment delete or controller shutdown. Idle closes that needed a forced Runner stop, or whose sandbox was already destroyed, are counted but do not fail. Both counts are distinct (run, reason) failures, not log lines: the harness's environment-delete retries re-log the same failed close every few seconds (one session logged 27 times in w-20261116T001158-s7106). Each failure keeps its line count. On a Daytona warm wave, the first idle-close failure in the server output triggers one sandbox capture (`daytona-runner/idle-close-failure-/`: processes, Runner state and logs), listed under `sandboxCaptures`. The result is in `/warm-shutdown.json` and in the wave's `SUMMARY.md`. ## Hosted mode (`--hosted-base-url`, `--hosted-allow`) ```sh set -a; source ~/.secrets; set +a H=.staging.paperclip.app # Read-only: watch one release of the instance (GET /api/health every 2 s) and report its shape. No writes. node cli/node_modules/tsx/dist/cli.mjs tests/restart-chaos/hosted.ts --hosted-base-url https://$H --hosted-allow $H --hosted-observe-only # Smoke: 2 tasks, no release wait, 1-minute settle, then cleanup. node cli/node_modules/tsx/dist/cli.mjs tests/restart-chaos/hosted.ts --hosted-base-url https://$H --hosted-allow $H \ --hosted-releases 0 --hosted-tasks 2 --hosted-turn-minutes 3 --hosted-label rc-hosted-smoke1 # A run across 3 real releases at 5 concurrent (default), then the same at 15. node cli/node_modules/tsx/dist/cli.mjs tests/restart-chaos/hosted.ts --hosted-base-url https://$H --hosted-allow $H --hosted-releases 3 --hosted-label rc-hosted-r3c5 node cli/node_modules/tsx/dist/cli.mjs tests/restart-chaos/hosted.ts --hosted-base-url https://$H --hosted-allow $H --hosted-releases 3 --hosted-concurrency 15 --hosted-label rc-hosted-r3c15 # Remove everything one run created (also run automatically at the end of every run unless --hosted-keep). node cli/node_modules/tsx/dist/cli.mjs tests/restart-chaos/hosted.ts --hosted-base-url https://$H --hosted-allow $H --hosted-cleanup-only --hosted-label rc-hosted-r3c5 ``` Hosted mode runs the release-swap proof against a real hosted instance that takes automatic releases, instead of servers the harness starts. It starts no server and injects no fault: each release the instance's own continuous deploy rolls out is a swap. **Target guard** (`hosted-guard.ts`). The harness refuses to start unless `--hosted-base-url` is a bare `https://` origin and `--hosted-allow` names the same host. The host must be one stack under `.staging.paperclip.app` or `.test.paperclip.app`. `paperclip.staging.paperclip.app`, production hosts, the fleet admin and Cloud hosts are refused even when allowed explicitly. Every request is checked against that one origin before it is sent. **Sign-in.** The harness uses a board token for the host: `PAPERCLIP_HOSTED_TOKEN`, or `credentials["https://"].token` in `~/.paperclip/auth.json` (the CLI's store). It never prints the token. Hosted stacks sit behind the Cloud tenant gateway, which answers every request without a session, including `/api/health` and the CLI's `POST /api/cli-auth/challenges`, with `401 tenant_session_required`. So `paperclipai auth login --api-base https://` cannot start there. A person who can sign in to the instance must create the challenge from a signed-in browser tab, approve it, and store the token. Without a token, hosted mode stops before any request. **Setup** (`hosted-setup.ts`). Company creation is managed by Cloud, so the run works inside the signed-in user's company (`--hosted-company ` when there are several). Everything it creates carries the run label (`--hosted-label`, default `rc-hosted-`): one project `Restart chaos