mirror of
https://github.com/paperclipai/paperclip.git
synced 2026-11-25 16:14:26 +01:00
## Thinking Path > - Paperclip is the open source app people use to manage AI agents for work > - The restart-chaos harness (`tests/restart-chaos/`) tests that agent work survives control-plane faults > - In one 8-hour staging window, 20 of 25 failed runs happened with no restart at all, so the harness did not see them > - The harness had blind spots: one short task per agent, no wake right after a successful run, no fault in a later recovery step, short turns, and a redeploy that always keeps its instance home > - This pull request adds cells for those shapes, so the harness reproduces these failure classes on master > - The benefit is that fixes for these classes can be proven red and green with the harness, without staging ## Linked Issues or Issue Description **What happened?** On staging, an agent ran 10–13 tasks at once on reused sandboxes. 30–60 s after a long run succeeded, an ordinary wake (a comment or an issue monitor) started the next run of the same task. That run or its recovery failed before any provider work, with errors such as `runner_remote_process_identity_unavailable`, `Controller journal drain timed out` and `journal_tool_input_unanswered`. Other failures happened in a later recovery step (a held agent-directory lock, a missing runtime asset after a deploy without a volume). **Expected behavior** The chaos harness can reproduce each of these shapes on demand, and grades them: no failed attempt, every task `done`, and no task left blocked without a working Retry. **Steps to reproduce** See the commands in the README sections "Re-wake after success", "Fail the Nth recovery step", "Long turn" and "Redeploy without a volume, with overlap". Related: #20844 (session fault SR1). W2C is the configuration change after a successful run; SR1 is the same change while a question is parked. This PR does not add or change `session-faults.ts`. ## What Changed - New workloads W2, W2Q, W2C (`rewake.ts`): phase 1 ends with the task left open; the harness, as the board, wakes the same task the seeded 0–60 s after its run settled. W2 uses a comment or a board-scheduled issue monitor (by nonce). W2Q parks on an unanswered `request_human_input` question and is woken by a comment before the answer. W2C changes the agent's `adapterConfig.idleTimeoutMs` before the wake. Oracle: phase 1 succeeded, the wake was served by a run that succeeded, `no_failed_attempt`, `done`, markers. - `--faults K0`: cells with no fault, for workloads whose shape is the fault. - `--fail-recovery-step <step>[:<nth>]` (`recovery-step-faults.ts`): when the wave's first restart fault starts its replacement, the harness arms one crash point in a new fail mode; the nth hit throws the error of the real step, once. Steps: `runnerd-start` (`spawn paperclip-runnerd EAGAIN`), `teardown` (provider destroy did not finish), `directory-lock` (`Agent directory operation is already active`). Crossed tasks get `recovery_step_failed_once` and `no_failed_attempt`. - Crash points (`packages/shared/src/crash-points.ts`): fail mode in the control file (`<token> <name>:<nth> fail [pid=<n>]`), with an optional call-site error; `pid=` binds the line to one server process. The harness arms the step for the replacement only and disarms it once its receipt lands. New point `agent_directory.operation_lock.before_acquire`. The teardown point moved into its `try`, so fail mode behaves like a failed provider destroy; kill mode is unchanged. All points stay disarmed under `NODE_ENV=production`. The runner package's own crash-point copy is not changed (runner image content ID unchanged). - `--long-turn-minutes <n>` (`long-turn.ts`, 15–60, opt-in): every task's first turn runs rounds of real tool work for n minutes before its workload. Checks `long_turn_rounds` and `long_turn_run_observed`. - K15 `--k15-fresh-home` (Daytona) and `--k15-overlap-seconds <min>-<max>` (`redeploy.ts`, `supervisor.ts`, `edge-proxy.ts`): each deploy generation gets a new, empty instance home and no volume variables; the next generation boots beside the old one behind an edge proxy on the wave's port, takes traffic once ready, and the old one gets SIGTERM after the overlap. - `tests/runner-e2e/source-sdk-public-inputs.json`: refreshed pins for the changed shared crash-point files. - README: one section per new cell, with what it covers. ## Verification - `pnpm exec vitest run --config tests/restart-chaos/vitest.config.ts` (48 files, 581 tests after rebasing on master, includes the new `shape-cells.test.ts`). - `pnpm exec vitest run packages/shared/src/crash-points.test.ts server/src/__tests__/crash-point-call-sites.test.ts` (fail mode, call sites). - `node scripts/typecheck-test-projects.mjs tests/restart-chaos`. - Chaos waves on master `1d67e309e0` server code (Daytona image `ghcr.io/paperclipai/paperclip-daytona-runner@sha256:99fc2671fc320816407f63cffd3acbd27471621febcd26494fe25bb5d7c5dd77`, content ID `1836c515…`), all RED unless noted: | Cell | Wave | Result on master | Staging class | | --- | --- | --- | --- | | W2/W2Q/W2C, 10 tasks on one Codex agent, `--daytona-warm`, K0 | `w-20261111T163206-s5201` | 9/10 fail. 3 tasks (W2 t02, W2C t03, t06): first fault `native_runner_process_exited`, same-run reattach, `native.remote_runner_recovery_failed` with `stage: process_verification`, `reason: process_not_running`, `runnerLifecycle: ready`, `runnerSettled: false`, terminal `runner_remote_process_identity_unavailable`, "Workspace repair required". 3 tasks (t04, t08, t10): `native_restart_recovery_blocked` (`native_retry_source_superseded`) while its successor ran (R4 `concurrent_runs`). 3 W2Q tasks: the answer's continuation was cancelled `issue_not_in_progress` (status `blocked`), and the task needed Retry. 2 W2C tasks then looped: 60+ succeeded runs in 20 minutes on an `in_progress` task. | D′/T terminal step reproduced with no restart, no governed wait and no PRP timeout (same error code and refusal fields). C+ retry outcome (ownership ambiguous) reproduced as `native_restart_recovery_blocked`. Not reproduced: `Controller journal drain timed out`, `did not durably suspend`, `journal_tool_input_unanswered`. | | Same, local `--lifecycle warm` | `w-20261111T160103-s5101` | 4/10 fail. 3/3 W2Q: continuation cancelled `issue_not_in_progress`, Retry needed. 1 W2C: the same `in_progress` run loop (39+ runs). | The remote-runner classes need a remote runner; locally they do not show. | | `--fail-recovery-step runnerd-start:1`, K1 at 10 s, local A1 | `w-20261111T162432-s5303` | Fail. After K1 the first runnerd start of recovery failed (`spawn paperclip-runnerd EAGAIN`); the run ended `native_provider_terminal_failed` ("previous turn is no longer active", "Automatic recovery stopped") and needed Retry. Control, same seed and K1 without the step fault (`w-20261111T171114-s5303`): pass. | A later recovery step that fails once ends the run instead of trying again (the A-chain shape). | | `runnerd-start:2`, local | `w-20261111T170909-s5304` | Step never reached: recovery started the runner once and succeeded. Grade fails `recovery_step_failed_once` (tested nothing). | — | | `teardown:1`, K1, Daytona A1 | `w-20261111T172048-s5312` | Pass. The teardown failed once and the sweep settled it. | Not reproduced. | | `directory-lock:1`, K2, Daytona A1 | `w-20261111T171247-s5311` | Step never reached by A1 after K2. | Not reproduced; A1 recovery does not collect remote agent files. | | K15 `--k15-fresh-home --k15-overlap-seconds 30-150`, `--storage s3`, Codex and OpenCode, T1/C1 | `w-20261111T173618-s5322` | 1/4 fail (OpenCode T1): `native_continuation_requires_reconciliation` with "Agent directory belongs to a different execution environment"; the Retry runs failed `adapter_failed` "Configured instruction entry is missing"; the task rests `blocked` on a board recovery action, and two sandboxes were left (R6). One Codex T1 task finished before its fault (`fault_crossed_tool`). | A-deploy: a controller-local file missing after a deploy without a volume. Here the missing file is the agent's instruction bundle, not a runtime-context asset; whether staging keeps instruction bundles outside the instance home is not verified. | | `--long-turn-minutes 15`, K1 at 600 s, local A1 | `w-20261111T175505-s5401` | Task pass (10/10 rounds, 992 s span, run 1019 s, K1 crossed mid-turn). The wave exited 2 only because I switched branches in the worktree during the wave. | Shape check only. | ## Risks - Product code changes are test instrumentation only: three `crashPoint` call sites take a fail-mode error, and one new call site was added. Disarmed (always in production) each call is one comparison. Moving the teardown point into its `try` does not change kill mode: the process dies at the same instant. - The new cells are opt-in. Default waves plan the same tasks as before for the same seed. - The W2 cells depend on model behaviour (phase 1 leaves the task open). The oracle records the task status at the wake. - `--k15-fresh-home` drops everything under the instance home. Whether staging keeps agent instruction bundles outside the instance home is not verified (see the K15 result). ## Model Used - Claude Opus 5.5 (`claude-opus-5-5`), Anthropic, agentic coding with tool use (shell, file edits, test and chaos runs) in Claude Code. ## Checklist - [x] I have included a thinking path that traces from project context to this change - [x] I have specified the model used (with version and capability details) - [x] I have checked ROADMAP.md and confirmed this PR does not duplicate planned core work - [x] I have searched GitHub for duplicate or related PRs and linked them above - [x] I have either (a) linked existing issues with `Fixes: #` / `Closes #` / `Refs #` OR (b) described the issue in-PR following the relevant issue template - [x] I have not referenced internal/instance-local Paperclip issues or links (only public GitHub `#NNN` / `github.com/paperclipai/paperclip` URLs) - [x] My branch name describes the change (e.g. `docs/...`, `fix/...`) and contains no internal Paperclip ticket id or instance-derived details - [x] I have run tests locally and they pass - [x] I have added or updated tests where applicable - [x] I have updated relevant documentation to reflect my changes - [x] I have considered and documented any risks above 🤖 Generated with [Claude Code](https://claude.com/claude-code) --------- Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
181 lines
10 KiB
TypeScript
181 lines
10 KiB
TypeScript
/**
|
||
* Registry of named crash points (durable ownership plan, "Testing: enumerate
|
||
* crash points"). Browser-safe data only; the helper is in `crash-points.ts`.
|
||
*
|
||
* Each point marks one durable write boundary. Add a point by adding an entry
|
||
* here and one `crashPoint("<name>")` call at the boundary; see
|
||
* tests/restart-chaos/README.md, "Crash-point suite".
|
||
*
|
||
* Name: `<subsystem>.<record>.<before|after>_<step>`, lower snake case.
|
||
* `kinds` are ownable kind ids from server/src/services/recovery/ownership-registry.ts
|
||
* (the Phase 1 registry of doc/plans/2026-11-07-ownership-inventory.md). `invariants` are the plan's
|
||
* I1–I8 that a crash here puts at risk. `environments` are where a suite task
|
||
* reaches the point (a local run never creates a sandbox, for example).
|
||
*/
|
||
|
||
export type CrashPointInvariant = "I1" | "I2" | "I3" | "I4" | "I5" | "I6" | "I7" | "I8";
|
||
export type CrashPointEnvironment = "local" | "daytona";
|
||
|
||
export type CrashPointDefinition = {
|
||
description: string;
|
||
environments: readonly CrashPointEnvironment[];
|
||
kinds: readonly string[];
|
||
invariants: readonly CrashPointInvariant[];
|
||
/** What a run must go through first when one plain task does not reach the point. */
|
||
prerequisite?: string;
|
||
};
|
||
|
||
export const CRASH_POINT_NAME_PATTERN = /^[a-z][a-z0-9_]*\.[a-z][a-z0-9_]*\.(before|after)_[a-z0-9_]+$/;
|
||
|
||
export const CRASH_POINTS = {
|
||
"remote_workspace.prepare.after_publish_before_provision": {
|
||
description: "A run restored its remote workspace's saved version and published the root as its dirty epoch, with the unchanged baseline; no provisioning, runner command or agent process has started. Recovery must hand the workspace on at its saved version and keep the root, not abandon the epoch.",
|
||
environments: ["daytona"],
|
||
kinds: ["remote_workspace_unsaved_files"],
|
||
invariants: ["I2", "I7"],
|
||
prerequisite: "a previously saved remote workspace: the point counts only a preparation that restores a saved version (a follow-up or continuation run, for example workload S1), never a workspace's first preparation",
|
||
},
|
||
"sandbox.create.after_intent_before_provider": {
|
||
description: "The sandbox_creation_operations intent is committed; the provider create call has not been made. Recovery must settle the intent without a sandbox to find.",
|
||
environments: ["daytona"],
|
||
kinds: ["sandbox_creation_intent"],
|
||
invariants: ["I1", "I2", "I7"],
|
||
},
|
||
"sandbox.create.after_provider_before_lease": {
|
||
description: "The provider created the sandbox; no environment lease row records it yet. Recovery must adopt or destroy the sandbox from the intent, never leak it.",
|
||
environments: ["daytona"],
|
||
kinds: ["sandbox_creation_intent", "environment_run_lease_active"],
|
||
invariants: ["I2", "I7"],
|
||
},
|
||
"native.process_start.after_requested_before_spawn": {
|
||
description: "native.process_start_requested is in the run log; runnerd has not been spawned. No provider work started, so a resumed attempt must not be charged.",
|
||
environments: ["local", "daytona"],
|
||
kinds: ["native_startup_context", "native_executor_claim"],
|
||
invariants: ["I2", "I5", "I7"],
|
||
},
|
||
"runner.process.after_spawn_before_identity": {
|
||
description: "runnerd is spawned (own process group, survives the server); its pid and process identity are not yet recorded on the run. Recovery must find or stop the orphan by identity. Local spawns only: a remote launcher returns before runnerd exists.",
|
||
environments: ["local"],
|
||
kinds: ["native_executor_claim", "detached_process_marker"],
|
||
invariants: ["I1", "I2", "I5"],
|
||
},
|
||
"runner.turn_start.after_runner_accept_before_controller_checkpoint": {
|
||
description: "runnerd returned the turn.start result; the controller's command journal still says pending. Recovery must adopt the accepted turn, not start a second one.",
|
||
environments: ["local", "daytona"],
|
||
kinds: ["native_executor_claim", "native_restart_recovery_claim"],
|
||
invariants: ["I4", "I5", "I6"],
|
||
},
|
||
"runner.turn_start.after_controller_journal_before_db_checkpoint": {
|
||
description: "The controller journal recorded the turn.start result; the next send and (remote runs) the database checkpoint have not happened.",
|
||
environments: ["local", "daytona"],
|
||
kinds: ["native_restart_recovery_claim"],
|
||
invariants: ["I4", "I6"],
|
||
},
|
||
"runner.semantic_tool.after_input_before_dispatch": {
|
||
description: "The controller received a dynamic tool call (for example write_document) from the Runner and has not dispatched it. On Daytona the Runner and Codex outlive the controller, so with --hold-ms Codex keeps the call pending through the outage (restart chaos t03); a local restart also stops the Runner.",
|
||
environments: ["local", "daytona"],
|
||
kinds: ["native_executor_claim"],
|
||
invariants: ["I4", "I7"],
|
||
},
|
||
"native.result.after_accept_before_finalize": {
|
||
description: "The run's result and its workspace_finalizing finalization row are committed; finalization has not started. The accepted result must be finalized exactly once.",
|
||
environments: ["local", "daytona"],
|
||
kinds: ["native_accepted_result_lease", "native_finalizer_lease"],
|
||
invariants: ["I2", "I4", "I7"],
|
||
},
|
||
"native.finalize.after_decision_before_projection": {
|
||
description: "The status decision is committed; the run and issue projection is not. Recovery must finish the projection, not decide again.",
|
||
environments: ["local", "daytona"],
|
||
kinds: ["native_finalizer_lease"],
|
||
invariants: ["I2", "I7"],
|
||
},
|
||
"workspace.finalize.after_start_before_copyback": {
|
||
description: "A workspace_finalize operation row is running; copyback or export has not started. Recovery must settle the operation and keep the workspace.",
|
||
environments: ["local", "daytona"],
|
||
kinds: ["native_workspace_finalize_attempt", "copyback_owner_hold"],
|
||
invariants: ["I1", "I2", "I7"],
|
||
},
|
||
"workspace.finalize.after_copyback_before_done": {
|
||
description: "Copyback or export finished; the workspace operation row still says running. Recovery must settle it without copying again over newer work.",
|
||
environments: ["local", "daytona"],
|
||
kinds: ["native_workspace_finalize_attempt", "copyback_owner_hold"],
|
||
invariants: ["I2", "I7"],
|
||
},
|
||
"environment.lease_release.after_provider_before_lease": {
|
||
description: "The provider released the sandbox; the environment lease row is still active.",
|
||
environments: ["daytona"],
|
||
kinds: ["environment_run_lease_active"],
|
||
invariants: ["I2"],
|
||
},
|
||
"environment.teardown.after_claim_before_destroy": {
|
||
description: "A pending_cleanup teardown claim is held; the provider destroy has not been called. Proof of the dead claimant must release the claim, not a TTL.",
|
||
environments: ["daytona"],
|
||
kinds: ["environment_teardown_claim", "environment_pending_cleanup"],
|
||
invariants: ["I2", "I7"],
|
||
prerequisite: "A pending_cleanup lease: a provider release that failed or could not be verified. A plain task's release succeeds and never claims a teardown.",
|
||
},
|
||
"environment.teardown.after_destroy_before_lease": {
|
||
description: "A reusable sandbox was destroyed at the provider; its lease row is not released.",
|
||
environments: ["daytona"],
|
||
kinds: ["environment_run_lease_active", "environment_retained_hold"],
|
||
invariants: ["I2"],
|
||
prerequisite: "A reuse_by_environment lease that expires or is replaced (destroyReusableSandboxLease). The chaos Daytona environment's leases are ephemeral by default.",
|
||
},
|
||
"agent_directory.operation_lock.before_acquire": {
|
||
description: "A remote agent-directory operation (collect, checkpoint, release) is about to take its per-company-and-agent Postgres lock; no agent file has been read or written. In fail mode the call site throws the lock's own conflict (\"Agent directory operation is already active\"), staging class A's terminal step, so a recovery that collects a stopped run's agent files meets a held lock.",
|
||
environments: ["daytona"],
|
||
kinds: ["copyback_owner_hold"],
|
||
invariants: ["I2", "I7"],
|
||
prerequisite: "A remote (Daytona) agent directory copy: a task whose run materialized the agent's files in a sandbox.",
|
||
},
|
||
"environment.stop_retain.after_claim_before_stop": {
|
||
description: "A stop-and-retain intent and its claim are committed; the provider stop has not been retried.",
|
||
environments: ["daytona"],
|
||
kinds: ["environment_stop_and_retain_intent"],
|
||
invariants: ["I2", "I7"],
|
||
prerequisite: "A stop-and-retain intent: run with --daytona-reuse-lease, so each per-turn run stops and keeps its reusable sandbox.",
|
||
},
|
||
"environment.lease.after_release_before_runtime_services": {
|
||
description: "The run's environment leases are released; its workspace runtime services are not.",
|
||
environments: ["local", "daytona"],
|
||
kinds: ["execution_workspace_runtime_lease", "workspace_runtime_service"],
|
||
invariants: ["I2"],
|
||
},
|
||
"wake.claim.after_run_running_before_wakeup_claimed": {
|
||
description: "The claimed run is running; its wake request still says queued. The wake must be delivered exactly once.",
|
||
environments: ["local", "daytona"],
|
||
kinds: ["wake_request_claimed"],
|
||
invariants: ["I4", "I7"],
|
||
},
|
||
"budget.reservation.after_hold_before_dispatch": {
|
||
description: "The run's budget reservation hold is committed; the run has not been dispatched. The hold must not gate admission or outlive the run.",
|
||
environments: ["local", "daytona"],
|
||
kinds: ["run_accounting_debt"],
|
||
invariants: ["I2", "I3", "I5"],
|
||
},
|
||
"accounting.usage_receipt.after_spool_before_db": {
|
||
description: "A usage receipt is fsynced to the local spool; its database row is not written.",
|
||
environments: ["local", "daytona"],
|
||
kinds: ["usage_receipt_spool"],
|
||
invariants: ["I3", "I4"],
|
||
},
|
||
"accounting.usage_receipt.after_db_before_unlink": {
|
||
description: "The usage receipt row is written; its spool file is not removed. Replaying the spool must not double-count.",
|
||
environments: ["local", "daytona"],
|
||
kinds: ["usage_receipt_spool"],
|
||
invariants: ["I4"],
|
||
},
|
||
"accounting.closure.after_commit_before_spool_unlink": {
|
||
description: "Run accounting is closed (reservation settled, cost recorded); the recovered spool files are not removed.",
|
||
environments: ["local", "daytona"],
|
||
kinds: ["run_accounting_debt", "usage_receipt_spool"],
|
||
invariants: ["I3", "I4"],
|
||
},
|
||
} as const satisfies Record<string, CrashPointDefinition>;
|
||
|
||
export type CrashPointName = keyof typeof CRASH_POINTS;
|
||
|
||
export function isCrashPointName(value: string): value is CrashPointName {
|
||
return Object.prototype.hasOwnProperty.call(CRASH_POINTS, value);
|
||
}
|