mirror of
https://github.com/paperclipai/paperclip.git
synced 2026-12-05 14:35:17 +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/`) runs real agent
tasks and breaks the control plane on purpose, so failures show up
before staging users see them
> - A census of 48 hours of staging failures found runs whose result
save-back failed because the sandbox disk was full (class F). The
harness never filled a sandbox disk, so it missed that class
> - #20758 made a full-disk save end recovery at once with cause
`sandbox_disk_full` and a Retry. Nothing in chaos exercised that path
end to end
> - A real full disk cannot be made on demand. The owner chose a
test-only hook that makes the save report a full disk, not a small disk
> - This pull request adds the hook at the save's sandbox boundary and a
DF1 fault that arms it, clears it, and grades the result
> - The benefit is that every wave can now check the disk-full rest, the
Retry offer, and that Retry works after space is freed
## Linked Issues or Issue Description
Refs #20758 (product behaviour under test), #20678 (finalization hands a
full-disk copy-back to recovery)
**What is the problem?**
The chaos harness had no fault for a full sandbox disk during result
save-back. Staging saw this failure (census class F in
`doc/plans/2026-11-11-staging-failures-vs-chaos-coverage.md`), and chaos
could not reproduce it.
**What is the expected behaviour?**
A wave can schedule DF1. While DF1 is armed, the task's final workspace
saves fail as a full disk. When DF1 is cleared, saves succeed again. The
task must rest with `sandbox_disk_full` and a Retry, and that Retry must
finish the task.
**Why does it matter?**
Without a fault, a regression in the disk-full path (no Retry, a wrong
cause, or a Retry that does not work) reaches staging users before chaos
sees it.
## What Changed
- `server/src/services/sandbox-disk-full-fault.ts` (new, test-only):
`sandboxDiskFullFaultTarget` wraps the target of a final save only when
the harness armed that save. The capture commands then exit 1 with the
exact message the in-sandbox script writes on ENOSPC, and the provider
download fails with `No space left on device`. The gate follows
`@paperclipai/shared/crash-points`: `PAPERCLIP_DISK_FULL_FAULT_CONTROL`
is read once at import and ignored under `NODE_ENV=production`.
Disarmed, the hook is one comparison and returns the save's own target.
- `server/src/services/remote-workspaces.ts`: the capture call in
`saveRemoteWorkspace` passes its target through the hook. No other
product change. `workspace-recovery.ts` is not touched.
- `tests/restart-chaos/disk-full-faults.ts` (new): the DF1 kind, the
control-file seam (atomic writes), the rest evidence
(`activeRecoveryAction.evidence.systemRecovery.failure.cause.label`),
the `disk_full_fault` T check, and the DF1 R3 rule (one expected Retry
that must finish the task).
- Harness wiring: `--faults DF1` (refused without `--env daytona`, with
a storm, or with PV faults), no scheduled restart, arm at launch, clear
at the first rest just before the Retry click, receipts in
`<wave>/disk-full-faults.jsonl`, and ledger fields `diskFull: {
faultedSaves, restedDiskFull, retryOffered, retryWorked }`.
- Docs: a "Sandbox disk full (DF1)" section in
`tests/restart-chaos/README.md`, and the census plan marks DF1 as built.
## Verification
- `cd server && pnpm exec vitest run
src/services/sandbox-disk-full-fault.test.ts`: the gate is off by
default and under `NODE_ENV=production`, the save's own target comes
back when disarmed, only a listed final save is faulted, the product
capture turns it into the named disk-full failure, and clearing the file
disarms the next save.
- `pnpm exec vitest run --config tests/restart-chaos/vitest.config.ts
tests/restart-chaos/disk-full-faults.test.ts
tests/restart-chaos/grader.test.ts tests/restart-chaos/scheduler.test.ts
tests/restart-chaos/provider-faults.test.ts`: planning, the control
file, and grading.
- `node scripts/typecheck-test-projects.mjs tests/restart-chaos` and the
server `tsc --noEmit`: clean.
- Live Daytona waves (Codex, `--storage s3`, image content `96c4339f…`,
run through the two-slot queue):
- `w-20261111T131314-s9411` (B1): the hook was armed in the server but
no save reached it. B1 uses a local worktree synced into the sandbox,
not a remote workspace. Graded `not_applied` as designed. The harness
now requires `--storage s3` and the docs point at R1.
- `w-20261111T131941-s9412` (R1): 3 faulted saves. t01 rested `blocked`
with `sandbox_disk_full`, `user_action_required`, board owner, API
`canRetry: true`. t02 was cleared too early, while recovery still
checked its source; that recovery then saved and the task finished.
Fixed in 626f552e (wait for the disk-full verdict).
- `w-20261111T134316-s9413` (R1, after the fix): 2/2 tasks rested with
`sandbox_disk_full` and API `canRetry: true`. In both, the board showed
**"Recover saved files"** and no Retry button, so the UI Retry click
failed (`ui_retry_button_missing`). Retry-worked is not shown. The wave
was interrupted by SIGTERM during the post-rest file reads, before final
grading.
- Local wave: not run. A local run has no sandbox workspace save, so DF1
cannot fire there; the harness refuses `--env local`.
## Risks
- Low risk for production. The hook reads its variable once at startup
and is ignored under `NODE_ENV=production`. Without the variable it does
one comparison and returns the same target object.
- The hook fails every sandbox command of an armed capture, including
the read-only fallback's inventory. A real full disk can let that
inventory succeed and fail later at the download. The outcome is the
same (`sandbox_disk_full`), but the fallback's inventory step is not
exercised under DF1.
- DF1 runs only with `--env daytona --storage s3` and a remote workspace
(R1). A local run has no sandbox workspace save, so the harness refuses
DF1 there. DF1 is refused in `--matrix` waves, and T1's restart check is
skipped for DF1.
## Model Used
- Claude Opus 5.5 (Anthropic, model ID `claude-opus-5-5`), in Claude
Code with tool use (shell, file edits, GitHub CLI).
## 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
- [ ] All Paperclip CI gates are green
- [ ] Greptile is 5/5 with no open P2s, recommendations, or follow-ups
- [x] I will address all Greptile and reviewer comments before
requesting merge
🤖 Generated with [Claude Code](https://claude.com/claude-code)
---------
Co-authored-by: Claude <noreply@anthropic.com>
184 lines
9.2 KiB
TypeScript
184 lines
9.2 KiB
TypeScript
/**
|
|
* DF1: the sandbox disk is full when the run's result is saved (staging census class F,
|
|
* doc/plans/2026-11-11-staging-failures-vs-chaos-coverage.md).
|
|
*
|
|
* A genuinely full disk cannot be made on demand, so the server carries a test-only hook
|
|
* (server/src/services/sandbox-disk-full-fault.ts). The harness starts its server with
|
|
* PAPERCLIP_DISK_FULL_FAULT_CONTROL pointing at a file it owns. While a task's issue id is in
|
|
* that file, each final workspace save of that task gets the answer a full sandbox gives: the
|
|
* capture command exits 1 with the product's disk-full message, and the provider download fails
|
|
* with "No space left on device". Everything after that is the product's own handling.
|
|
*
|
|
* The harness arms the task when it launches and clears it when the task first rests offering a
|
|
* Retry, just before the observer clicks Retry, as a person who freed space would. Grading:
|
|
* - the fault applied (the server wrote a receipt for the task);
|
|
* - the task rested with recovery cause `sandbox_disk_full` and a Retry offered;
|
|
* - one Retry, after the fault cleared, finished the task (R3).
|
|
*
|
|
* DF1 restarts nothing. It needs a remote sandbox workspace, so it runs with `--env daytona`.
|
|
*/
|
|
import { randomUUID } from "node:crypto";
|
|
import { mkdir, readFile, rename, writeFile } from "node:fs/promises";
|
|
import path from "node:path";
|
|
import type { OracleResult, RuleResult, TaskPlan, TaskRecord } from "./types.js";
|
|
|
|
type Json = Record<string, any>;
|
|
|
|
export const DISK_FULL_FAULT_KINDS = ["DF1"] as const;
|
|
export type DiskFullFaultKind = (typeof DISK_FULL_FAULT_KINDS)[number];
|
|
export function isDiskFullFault(value: string): value is DiskFullFaultKind {
|
|
return (DISK_FULL_FAULT_KINDS as readonly string[]).includes(value);
|
|
}
|
|
|
|
/** The recovery cause the product names for a save that found the sandbox disk full. */
|
|
export const SANDBOX_DISK_FULL_CAUSE = "sandbox_disk_full";
|
|
|
|
/** Server-side receipt, one per faulted save (sandbox-disk-full-fault.ts DiskFullFaultReceipt). */
|
|
export interface DiskFullReceipt { issueId: string | null; runId: string; boundary: string; pid: number; at: string }
|
|
|
|
/** What the board showed when a DF1 task first rested. */
|
|
export interface DiskFullRest {
|
|
at: number;
|
|
status: string | null;
|
|
canRetry: boolean;
|
|
/** `activeRecoveryAction.evidence.systemRecovery.failure.cause.label`. */
|
|
causeLabel: string | null;
|
|
retryClass: string | null;
|
|
ownerType: string | null;
|
|
}
|
|
|
|
export interface DiskFullRecord {
|
|
kind: DiskFullFaultKind;
|
|
armedAt: number | null;
|
|
clearedAt: number | null;
|
|
rest: DiskFullRest | null;
|
|
/** First rest seen while armed; the harness waits for the disk-full verdict from here (DISK_FULL_REST_SETTLE_MS). */
|
|
firstRestAt?: number;
|
|
/** Faulted saves the server recorded for the task; filled in at grading. */
|
|
appliedSaves?: number;
|
|
armError?: string;
|
|
}
|
|
|
|
export function diskFullRest(issue: Json | null, at: number): DiskFullRest {
|
|
const action = (issue?.activeRecoveryAction ?? null) as Json | null;
|
|
const failure = (action?.evidence?.systemRecovery?.failure ?? null) as Json | null;
|
|
return {
|
|
at, status: typeof issue?.status === "string" ? issue.status : null,
|
|
canRetry: issue?.interruption?.canRetry === true,
|
|
causeLabel: typeof failure?.cause?.label === "string" ? failure.cause.label : null,
|
|
retryClass: typeof failure?.retryClass === "string" ? failure.retryClass : null,
|
|
ownerType: typeof action?.ownerType === "string" ? action.ownerType : null,
|
|
};
|
|
}
|
|
|
|
/**
|
|
* A board-owned recovery can look like a rest while it is still checking the saved source
|
|
* ("Recovering saved files…", wave w-20261111T131941-s9412/t02). Clearing the fault there would
|
|
* let that recovery's own save succeed and hide the disk-full rest. While armed, the harness
|
|
* keeps waiting at an unfinished rest until the board names `sandbox_disk_full`, up to this long.
|
|
*/
|
|
export const DISK_FULL_REST_SETTLE_MS = 10 * 60_000;
|
|
|
|
/** True when the harness may record this rest and clear the fault; false keeps watching. */
|
|
export function diskFullRestReady(record: DiskFullRecord, rest: DiskFullRest, now: number): boolean {
|
|
if (rest.status === "done" || rest.causeLabel === SANDBOX_DISK_FULL_CAUSE) return true;
|
|
record.firstRestAt ??= now;
|
|
return now - record.firstRestAt >= DISK_FULL_REST_SETTLE_MS;
|
|
}
|
|
|
|
/** The control file the server reads and the receipts it writes. */
|
|
export class DiskFullFaultSeam {
|
|
private readonly armed = new Set<string>();
|
|
private writes: Promise<void> = Promise.resolve();
|
|
|
|
private constructor(readonly controlPath: string, readonly receiptPath: string) {}
|
|
|
|
static async install(input: { root: string; receiptPath: string }): Promise<DiskFullFaultSeam> {
|
|
const directory = path.join(input.root, "disk-full-fault");
|
|
await mkdir(directory, { recursive: true, mode: 0o700 });
|
|
const seam = new DiskFullFaultSeam(path.join(directory, "control"), input.receiptPath);
|
|
await seam.write();
|
|
return seam;
|
|
}
|
|
|
|
get serverEnvironment(): Record<string, string> {
|
|
return { PAPERCLIP_DISK_FULL_FAULT_CONTROL: this.controlPath, PAPERCLIP_DISK_FULL_FAULT_RECEIPT: this.receiptPath };
|
|
}
|
|
|
|
arm(issueId: string): Promise<void> { this.armed.add(issueId); return this.write(); }
|
|
clear(issueId: string): Promise<void> { this.armed.delete(issueId); return this.write(); }
|
|
|
|
/** Atomic, so a save never reads half a file; serialized, so the last change wins. */
|
|
private write(): Promise<void> {
|
|
const body = [...this.armed].map(id => `${id}\n`).join("");
|
|
this.writes = this.writes.catch(() => undefined).then(async () => {
|
|
const temporary = `${this.controlPath}.${randomUUID()}.tmp`;
|
|
await writeFile(temporary, body, { mode: 0o600 });
|
|
await rename(temporary, this.controlPath);
|
|
});
|
|
return this.writes;
|
|
}
|
|
|
|
async receipts(): Promise<DiskFullReceipt[]> {
|
|
const text = await readFile(this.receiptPath, "utf8").catch(() => "");
|
|
return text.split("\n").filter(Boolean).flatMap(line => { try { return [JSON.parse(line) as DiskFullReceipt]; } catch { return []; } });
|
|
}
|
|
}
|
|
|
|
export function receiptsForIssue(receipts: readonly DiskFullReceipt[], issueId: string | null): DiskFullReceipt[] {
|
|
return issueId ? receipts.filter(receipt => receipt.issueId === issueId) : [];
|
|
}
|
|
|
|
/** Adds the `disk_full_fault` check: the fault applied and the task rested on it with a Retry. */
|
|
export function withDiskFullCheck(oracle: OracleResult, plan: TaskPlan, record: TaskRecord): OracleResult {
|
|
if (!isDiskFullFault(plan.fault)) return oracle;
|
|
const disk = record.diskFull;
|
|
const applied = disk?.appliedSaves ?? 0;
|
|
const rest = disk?.rest ?? null;
|
|
const problems = [
|
|
...(disk?.armError ? [`arm_failed=${disk.armError}`] : []),
|
|
...(applied === 0 ? ["not_applied (no save reached the hook: an unchanged workspace, a local run or a server without the hook)"] : []),
|
|
...(applied > 0 && !rest ? ["no_rest_while_armed"] : []),
|
|
...(rest && rest.causeLabel !== SANDBOX_DISK_FULL_CAUSE ? [`rest_cause=${rest.causeLabel ?? "none"}`] : []),
|
|
...(rest && !rest.canRetry ? ["retry_not_offered"] : []),
|
|
];
|
|
const detail = `${plan.fault}: faultedSaves=${applied} rest=${rest ? `${rest.status}/${rest.causeLabel ?? "none"}/${rest.retryClass ?? "none"}/canRetry=${rest.canRetry}` : "none"}`
|
|
+ (problems.length ? `; ${problems.join("; ")}` : "");
|
|
const checks = [...oracle.checks, { name: "disk_full_fault", ok: problems.length === 0, detail }];
|
|
return { verdict: checks.every(check => check.ok) ? "pass" : "fail", checks };
|
|
}
|
|
|
|
/**
|
|
* R3 for DF1. The product cannot free a sandbox disk, so one Retry is the expected outcome, not a
|
|
* failure: R3 passes when exactly one accepted Retry, after the fault cleared, finished the task.
|
|
* Whether the Retry started a new run is not graded: applying the already-saved result without a
|
|
* new turn is a correct Retry too.
|
|
*/
|
|
export function gradeDiskFullRetry(record: TaskRecord, expectedStatus: string): RuleResult {
|
|
const retry = record.retry;
|
|
if (!retry) {
|
|
return { verdict: "fail", detail: `disk_full_retry_missing: rested ${record.finalStatus ?? "unknown"}${record.timedOut ? " (timed out)" : ""} without a Retry` };
|
|
}
|
|
if (retry.error || retry.accepted !== true) {
|
|
return { verdict: "fail", detail: `retry_rejected: http=${retry.httpStatus ?? "none"} accepted=${String(retry.accepted)} ${retry.error ?? ""}`.trim() };
|
|
}
|
|
const clicks = 1 + (record.priorRetries?.length ?? 0);
|
|
if (clicks > 1) return { verdict: "fail", detail: `retry_needed_${clicks}_clicks (expected one Retry after the disk-full fault cleared)` };
|
|
if (record.finalStatus !== expectedStatus) {
|
|
return { verdict: "fail", detail: `disk_full_retry_did_not_complete (status ${record.finalStatus ?? "unknown"}${record.timedOut ? ", timed out" : ""})` };
|
|
}
|
|
return { verdict: "pass", detail: `expected Retry after ${SANDBOX_DISK_FULL_CAUSE}; Retry worked (${expectedStatus})` };
|
|
}
|
|
|
|
/** Ledger fields: needed-Retry and Retry-worked for the cell. */
|
|
export function diskFullLedger(record: TaskRecord, expectedStatus: string) {
|
|
const disk = record.diskFull;
|
|
if (!disk) return undefined;
|
|
return {
|
|
faultedSaves: disk.appliedSaves ?? 0,
|
|
restedDiskFull: disk.rest?.causeLabel === SANDBOX_DISK_FULL_CAUSE,
|
|
retryOffered: disk.rest?.canRetry === true,
|
|
retryWorked: record.retry?.accepted === true && record.finalStatus === expectedStatus,
|
|
};
|
|
}
|