# Restart chaos scenarios One section per workload or fault scenario: the command, what the fault does, and what the oracle checks. Running the harness, Daytona and hosted modes, grading, and output are in [README.md](README.md). ## Restart storm (K13, `--storm-minutes`) ```sh node cli/node_modules/tsx/dist/cli.mjs tests/restart-chaos/main.ts --env local \ --adapters codex,claude,opencode --concurrency 6 --storm-minutes 60 --seed 7 ``` A storm wave fires faults on its own seeded clock instead of one fault per task. Each fault is drawn from `--faults` (default K1, K2, K4, K6) and fires 2–4 minutes after the previous one settled (server ready), so a K4 hold never eats the next gap. Each fault hits every task in flight. While the storm lasts the harness launches a new task whenever one rests, keeping `--concurrency` in flight; `--tasks` (default 200) is only the pool. A pool that runs dry before the storm ends fails the wave as a harness error (`storm_pool_exhausted`). When the storm ends no new task or fault starts, the in-flight tasks drain to rest or their deadline, and only launched tasks are graded. Storm tasks show fault `K13` in the ledger; `storm_fault`, `storm_started` and `storm_ended` are in the timeline and the receipts are in `faults.json`. A replay of a storm task fires the faults that crossed it, without a new storm. `--triggers time,result` may join a storm: a `result` task (C1) also fires its own K1 or K2 (from `--faults`) just after its run accepts a result, the next storm gap runs from its settle, and no triggered fault fires during the drain. Other triggers do not combine with a storm. ## Governance across restarts (G1, H1) ```sh # Approval-gated action: the fault fires 0-3 s after the approval appears pending. node cli/node_modules/tsx/dist/cli.mjs tests/restart-chaos/main.ts --env local \ --adapters codex,claude --workloads G1 --faults K1,K2,K4 --triggers approval --concurrency 4 --tasks 6 --seed 31 # Budget hard stop: its own wave, one task at a time. node cli/node_modules/tsx/dist/cli.mjs tests/restart-chaos/main.ts --env local \ --adapters codex,claude --workloads H1 --faults K1,K2,K4 --triggers paused --concurrency 1 --tasks 3 --seed 32 ``` **G1.** The agent asks for board approval through its `call_api` tool (`POST /api/companies/{companyId}/approvals`, type `request_board_approval`, linked to its task), blocks the task and ends its turn. The `approval` trigger fires the planned fault once the observer sees the approval pending. After the restart, with the server ready, the harness acts as the board through the board's own routes. It either approves (`POST /api/approvals/:id/approve`), or rejects (`POST /api/approvals/:id/reject`) and cancels the task. The decision is fixed by the task's nonce, so about half approve and half reject. On approval, the woken agent creates exactly one backlog subtask named after the nonce and finishes. The oracle checks these points: - exactly one approval was requested (a restart that made the agent ask twice fails); - it was still pending when the board decided after the restart; - it reached the board's decision; - the subtask exists exactly once on approval, and never after a rejection. A rejected task rests `cancelled`; R1 and R3 grade against that status. **H1.** Before launch, the harness sets the company budget to its observed spend plus one cent through the board's budget route. The task's first priced usage then crosses the hard stop mid-run, which pauses the company. The `paused` trigger fires the fault once the observer sees `paused` with `pauseReason` `budget`. After the restart, the pause must hold for 30 s with the server ready. The harness records every run that started while paused (there must be none), then resolves the incident with `raise_budget_and_resume` (spend plus 3000 cents). The task must then finish its brief on its own. H1 pauses the whole company, so it runs alone (`--workloads H1 --concurrency 1`) and never with `--rc06-masked`. Neither G1 nor H1 is in the default workloads. The board's actions and what the observer saw are in the timeline (`governance_*`) and in each task's grade (`governance`). ## Stop while running, then continue (S1, `--triggers stop`) ```sh node cli/node_modules/tsx/dist/cli.mjs tests/restart-chaos/main.ts --env local \ --adapters codex,claude --workloads S1 --faults K1,K2,K4 --triggers stop --concurrency 4 --tasks 6 --seed 23 ``` S1 is the board's Stop button. While the task's run is running, the harness cancels it through `POST /api/heartbeat-runs/:id/cancel`. The `stop` trigger fires the fault 0–2 s later. At least 20 s after the stop, once no run is running or queued and no fault is in progress, the harness comments that it stopped the run on purpose and asks the agent to continue with an extra marker line. The oracle checks that the stopped run ended `cancelled`, that nothing started between the stop and the continue comment (recovery must not restart work the operator stopped), and that the finished brief has both markers. The Stop waits for a ready server with no fault in progress. If the run already finished when the stop window opens, the harness records a missed Stop (`task_stop_missed`), skips the stop-triggered fault, still posts the continue comment, and the oracle checks only the continue. S1 is not a default workload. ## Human-in-the-loop journeys (Q1, Q2, Q3) ```sh node cli/node_modules/tsx/dist/cli.mjs tests/restart-chaos/main.ts --env local \ --adapters codex,claude --workloads Q1,Q2,Q3 --faults K1,K2,K4 --triggers asked,answered --concurrency 2 --tasks 4 --seed 41 ``` Each journey starts from a user entry point in [`maps/feature-map/questions-and-approvals.md`](../../maps/feature-map/questions-and-approvals.md). The harness acts as the board through the routes the board UI uses. It acts only when the server is ready, no fault is in progress, and every fault the task planned before the response has fired. Two triggers fire at the journey's own boundaries: - `asked`: 0–3 s after the observer first sees the saved request pending. - `answered`: 0–3 s after the board's response returned. Until the board acts, the task waits on the board, as G1 does: this is not a rest, not a stall, and gets no Retry. The code lives in `journeys.ts` (definitions and oracles of Q2 and Q3), `journey-driver.ts` (their board) and `journey-oauth-app.ts` (Q3's app). **Q1, a question** (`questions`, `continuation`) is the saved question described under "Provider message faults" below (`question-handoff.ts`). With restart faults it takes the same two triggers: `asked` arms on its first pending poll and `answered` on the board's answer. The board answers before an `answered` fault fires and after every other planned fault. **Q2, a question on a blocked task** (#20363). The agent asks one single-select question with its native `request_human_input` tool and ends its turn. The board reads the card and answers with the option named by the task's nonce (`amber` or `cobalt`), on the task thread (`POST /api/issues/:id/interactions/:interactionId/respond`). Before it answers, the board adds an unassigned `backlog` prerequisite. It sets the task `blocked` by it (`blockedByIssueIds`), and then answers. The answer must reach the agent in the bounded answer mode, while the task stays blocked. The agent replies with the answer marker, in a comment or in that turn's accepted run result (a bounded turn may report through either). The board waits up to 6 minutes of ready server for that reply. Then it marks the prerequisite `done`. The blockers-resolved wake lets the agent write a brief that carries `ANSWER--` and finish. The oracle checks these points: - exactly one question was saved (a restart that made the agent ask twice fails); - the question was still pending when the board answered; - with `asked`, the board answered after the restart; - the brief carries the answer marker and the task rests `done`; - the reply came while the task was `blocked`; - the prerequisite relation was kept through the reply; - the reply came before the prerequisite was finished; - no run of the task carries `issue_dependencies_blocked`; - no stale Retry notice at rest. **Q3, an app action reviewed late** (`tool-review`, #20340). The harness starts its own OAuth 2.1 + MCP app on loopback. The app has discovery, dynamic client registration, PKCE, rotating refresh tokens, one-hour access tokens and one write tool, `create_page`. No third-party account is used. Before launch, the board connects the app (`POST /api/companies/:id/tools/apps/connect`). It follows the app's authorize redirect back to `/api/tools/oauth/callback`. Then it finishes setup for one scripted `process` agent with `create_page` set to Ask first. That agent is adapted from `tests/e2e/connection-reviews.spec.ts`. Q3 grades the review path, not a model, so `--adapters` only labels the cell. A process run records usage with no price, so Q3 setup also sets the company budget policy to allow unpriced usage (the amount and hard stop still apply). The agent's call waits for review. Then the board does three things: 1. It moves that review's saved timestamps and the grant's access-token expiry back by 61 minutes in the wave's own database (`shiftReviewClock`); a shared connection keeps that expiry on the connection. This is the `GRACE_SHIFT_MS` approach used by `invariants.ts`. 2. It runs **Check connection** (`POST /api/tool-connections/:id/health-check`). That check renews the now-expiring token through the app. 3. It approves (`POST /api/tool-gateway/action-requests/:id/approve`). The oracle checks these points: - exactly one review was requested; - the review aged more than an hour; - the app saw a refresh between the request and the decision; - the approval was accepted; - the app saw exactly one `tools/call` with the reviewed title; - the request ended `executed`; - the agent reported the provider's one-time receipt, which only the tool result carries; - the task rests `done`. ## Journey × fault matrix (`--matrix`) ```sh node cli/node_modules/tsx/dist/cli.mjs tests/restart-chaos/main.ts --env local \ --adapters codex --workloads Q1,Q2,Q3 --faults K1,K2,K4 --matrix --concurrency 2 --seed 43 ``` `--matrix` plans one task per cell, with a fixed order and a seeded nonce. The cells are workload × adapter × one of these: - `K0`: the same journey with no fault, as a baseline; - each restart fault in `--faults` at each of the workload's own triggers; - each provider message fault in `--faults` (PV1–PV3), armed once per workload. For a journey workload, those triggers are `asked` and `answered`. The example plans 3 × (1 + 3 × 2) = 21 tasks. Any workload can join the matrix, with its own boundary triggers: G1 at `approval`, H1 at `paused`, S1 at `stop`, C1 at `comment` and `result`, B5 at `tool`, and the rest at `time` (`WORKLOAD_TRIGGERS` in `journeys.ts`). G1 and H1 get no baseline, because their oracles grade a board decision made after a restart. `--fault-after-seconds` pins the time-fired cells. The matrix sets `--tasks` itself. It does not combine with `--tasks`, `--triggers`, `--storm-minutes`, `--crash-point` or K14. A restart hits every task in flight. So the baselines come first, and the wave never runs a baseline beside a fault cell: fault cells start only after the last baseline rests. To prove that a journey fails before a fix, prepare a checkout of the fix's parent. Then run the same wave against it with `--server-from`. The harness code stays the same; every server start and restart runs the older build: ```sh git worktree add --detach ../paperclip-pre20363 3cc1032f6a^ && (cd ../paperclip-pre20363 && node scripts/agent-preflight.mjs) node cli/node_modules/tsx/dist/cli.mjs tests/restart-chaos/main.ts --env local --adapters codex --workloads Q2 \ --faults K1 --triggers answered --concurrency 1 --tasks 1 --seed 44 --server-from ../paperclip-pre20363 ``` ## Code change in a real repository (R1, `--workspace-repo`) ```sh node cli/node_modules/tsx/dist/cli.mjs tests/restart-chaos/main.ts --env local \ --adapters codex,claude --workloads R1,C1 --workspace-repo /path/to/paperclip \ --faults K1,K2,K4 --concurrency 4 --tasks 8 --seed 22 ``` The harness clones the given git repository (shallow, from its committed HEAD) as the project's workspace, in place of the chaoscli fixture. R1 asks the agent to add a TypeScript module and a `node:test` file under `packages/shared/src/chaos/`, named with the task's nonce so concurrent tasks share the repository without colliding. The oracle runs the agent's test and a hidden case against its module. B1 and B5 need the chaoscli fixture, so they do not combine with `--workspace-repo`. Local only. ## Upgrade mid-run (K14, `--upgrade-from`) ```sh git worktree add ../paperclip-838e9bf3 838e9bf3d2 # an older master build (cd ../paperclip-838e9bf3 && node scripts/agent-preflight.mjs) node cli/node_modules/tsx/dist/cli.mjs tests/restart-chaos/main.ts --env local \ --adapters codex,claude --workloads A1,C1,M1 --faults K14 --upgrade-from ../paperclip-838e9bf3 \ --concurrency 4 --tasks 8 --seed 21 ``` The wave's server starts from the older checkout. The first K14 stops it gracefully (SIGTERM, as a deploy does) and starts this checkout against the same database, instance directory, port and secrets, so the new build applies its migrations to the old build's data and resumes what the old build saved. Each task is graded as usual. Pass means: - no task needed Retry (R3); - C1's follow-up comment reached the work (T); - the wave-end sweep finds no stuck records (R6). A later K14 in the same wave restarts the current build, like K2. Every K14 receipt names both commits (`upgrade` in `faults.json`, `upgrade_switched` in the timeline). K14 is local-only, because a Daytona runner must match its image, and it is never part of a storm's default faults. ## Redeploy (K15, `redeploy.ts`) ```sh node cli/node_modules/tsx/dist/cli.mjs tests/restart-chaos/main.ts --env daytona --daytona-image $IMG --daytona-cpu 3 \ --adapters opencode,claude --workloads A1,C1 --faults K15 --daytona-reuse-lease --concurrency 3 --tasks 6 --seed 9301 ``` The hosted staging stack deploys about every 40 minutes. Each deploy replaces the server's container. The replacement has the same database and volume, but it runs in another process space (host name, kernel boot and PID namespace) and has a new Railway deployment id. The server's PID-based proof that an earlier owner exited (`controller-process-identity.ts`, `owner-proof.ts`) never applies across a deploy. Recovery must use the deployment proof or the lease deadlines instead. K1 and K2 restart on the same machine, so every PID proof succeeds and that path stays untested. See `doc/plans/2026-11-11-staging-failures-vs-chaos-coverage.md`. K15 emulates the container replacement without a container: - Every server in a wave that has a K15 is launched with a `--import` preload (`redeploy-preload.mjs`). The preload makes `os.hostname()` return a per-generation name, which changes the process-space hash. - Every server gets Railway-shaped variables: `RAILWAY_PROJECT_ID`, `RAILWAY_ENVIRONMENT_ID`, `RAILWAY_SERVICE_ID` and `RAILWAY_DEPLOYMENT_ID`, plus `RAILWAY_VOLUME_ID` and `RAILWAY_VOLUME_MOUNT_PATH`, which is the instance home. - A K15 stops the server with SIGTERM, like K2. The replacement starts as the next generation, with a new host name and deployment id, on the same project, service and volume. - Other faults in the same wave restart within the current generation, like a platform restart of the same deployment. - Identities derive from the wave id; a replay uses the source wave id, so it sees the same ones. - Each K15 receipt records `redeploy` (both generations) in `faults.json`, and `redeploy_switched` in the timeline. Limits: - The Daytona sandboxes and remote runners survive, as they do on staging. - Local runners are stopped with the server's process tree. - The cloud stop-proof service (`PAPERCLIP_CLOUD_*`) is not emulated, so stop proofs that need it stay unsupported, as on any self-hosted Railway deploy. - K15 does not combine with MS1–MS3, because a second server would run in the real host's process space. - Combine K15 with `--adapters opencode` and `--daytona-reuse-lease` or `--daytona-warm` to match staging's workload mix. ### Long mid-tool redeploy (`--k15-hold-seconds`, T1, Runner logs) ```sh node cli/node_modules/tsx/dist/cli.mjs tests/restart-chaos/main.ts --env daytona --daytona-image $IMG --daytona-cpu 3 \ --adapters opencode --workloads T1 --faults K15 --k15-hold-seconds 240-480 --concurrency 2 --tasks 4 --seed 9310 ``` A staging deploy usually lands mid-turn and keeps the server down for 4–7 minutes. In staging class R, recovery then found the remote Runner gone (`runner_remote_process_identity_unavailable`). - **`--k15-hold-seconds ` or `-`** (0–600 s) seeds each K15's outage. The server stops with SIGTERM and stays down for the hold. Then the next deploy generation starts. Without the option, a K15 restarts at once. The range is drawn only for K15 cells, so other seeds keep their plans. - **H2** (opt-in workload, staging class H) has the agent save `brief`, then hand the task to the person who created it with status `in_review` as its last step. The task must rest `in_review` with that person, no run of the task may end `issue_reassigned`, and the task must have no execution blocker or active recovery action. Run it with a native adapter, for example `--adapters claude --workloads H2`. - **T1** (opt-in workload) has the agent run one shell command in the foreground for about 100 s (50 ticks of 2 s). The command prints the loop's own clock window. The agent then saves `brief`, whose first line is `TICKS-=50 start= end=`. Its fault window (35–80 s after launch) aims to land while the tool runs in the sandbox, and stays short of provider shell-tool timeouts. The `fault_crossed_tool` check (skipped for `K0` baselines and provider faults; a storm task counts the storm's faults) fails the task unless one of its own faults started inside the reported window, with 5 s of clock slack. A fault that hit preparation, with the loop run afterwards, tested nothing mid-tool, as a provider-fault task whose fault never applied. - **Runner evidence:** on a Daytona K15 wave, the harness captures every started sandbox of the wave three times: - right after the server stopped (`-stopped`); - after the hold, just before the next deploy starts (`-before_start`); - at wave end (`wave-end`). Each capture is written to `results//daytona-runner/