mirror of
https://github.com/paperclipai/paperclip.git
synced 2026-11-12 22:56:58 +01:00
## Thinking Path > - Paperclip is the open source app people use to manage AI agents for work. > - Control-plane restarts leave in-progress records that each subsystem releases in its own way. The durable-ownership plan replaces those paths with one shared path. > - Phase 1 added a report-only reconciler. Its light local waves showed zero violations, and that proves little. > - Phase 2 moves kinds to the shared path. It needs data that shows which kinds really leak, and the speed numbers to protect. > - This pull request records that data from harsher waves. It also fixes the harness so that K4 outages past the reconnect grace qualify. > - The benefit is that Phase 2 moves kinds in order of measured risk, against a known speed baseline. ## Linked Issues or Issue Description Refs #19831 (durable-ownership plan), #19861 (report-only reconciler), #19863 (speed budgets), #19797 (K4 hold cap). **What is the problem?** Phase 2 needs per-kind invariant data and speed data from harsh restart waves. Only light local waves existed. In addition, a K4 hold over about 405 s always failed its fault receipt, so the 600 s cap from #19797 could not be used. **Where is it documented?** `doc/plans/2026-11-07-durable-ownership-and-reconciliation.md` (Phase 2 rows) and `tests/restart-chaos/README.md`. **What should change?** Record the data in a dated plan doc. Let chaos K4 holds run up to 600 s and still qualify. ## What Changed - Added `doc/plans/2026-11-07-phase2-reconciler-data.md`. It covers 5 unmasked local waves (two storms, a crash loop, two K4 runs). It gives per-kind violation counts with example rows, owner verdicts, TTFT, boot and restart recovery against the budgets, Phase 3 gate notes, and what is not covered (Daytona). - Added a short pointer to that doc in the durable-ownership plan. - `tests/restart-chaos`: new flag `--k4-hold-max-seconds` (120–600). It raises the upper end of the seeded K4 hold. The default range (120–300 s) does not change. - `tests/runner-e2e/controller-outage.ts`: the receipt's ready bound is now a parameter (`CONTROLLER_READY_BY_MS`, default 420 s). Runner suites keep 420 s. The chaos supervisor passes hold + 420 s, so a hold past the Runner's reconnect grace qualifies. ## Verification - `pnpm exec vitest run --config tests/restart-chaos/vitest.config.ts`: 12 files, 135 tests pass, including the new flag test. - `pnpm exec vitest run --config tests/runner-e2e/vitest.config.ts tests/runner-e2e/controller-outage.test.ts`: 36 pass, including the new long-hold receipt test. - `node scripts/typecheck-test-projects.mjs tests/restart-chaos` and `tests/runner-e2e`: pass. - Live: the K4 wave at seed 9203 failed 3 of 6 tasks with the old bound (fault error "did not produce a qualifying replacement receipt"). It passed 6 of 6 with this fix, with holds of 294–579 s. ## Risks - Low risk. The changes are test harness code and docs only. The runner suites keep the 420 s ready bound by default. - The data is local only. The doc says which kinds the waves do not reach. ## Model Used - Claude Opus 5.5 (`claude-opus-5-5`), Anthropic, in Claude Code with tool use (shell, file edits). The model ran the chaos waves and wrote the analysis and 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 - [ ] All Paperclip CI gates are green - [ ] Greptile is 5/5 with no open P2s, recommendations, or follow-ups - [ ] I will address all Greptile and reviewer comments before requesting merge 🤖 Generated with [Claude Code](https://claude.com/claude-code) --------- Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
154 lines
10 KiB
TypeScript
154 lines
10 KiB
TypeScript
import { mkdtemp, mkdir, writeFile, readFile, rm, lstat } from "node:fs/promises";
|
|
import { tmpdir } from "node:os";
|
|
import { join } from "node:path";
|
|
import { describe, expect, it, vi } from "vitest";
|
|
import { configuredControllerOutage, controllerOutageForExecution, parseControllerOutage, replaceController, retireControllerCache, validControllerOutageReceipt } from "./controller-outage.js";
|
|
import { parseRunnerSelectors, selectRunnerExecutions } from "./selectors.js";
|
|
|
|
function fixture() {
|
|
const order: string[] = [];
|
|
const receipts: unknown[] = [];
|
|
return { order, receipts, input: {
|
|
requestId: "calibration", previousPid: 100, outage: { signal: "SIGKILL" as const, holdMs: 20 },
|
|
stop: async (signal: string) => { order.push(signal); },
|
|
waitForUnhealthy: async () => { order.push("http-down"); },
|
|
discardCache: async () => { order.push("empty-cache"); },
|
|
start: vi.fn(async () => { order.push("start"); return { pid: 200 }; }),
|
|
waitForReady: async () => { order.push("ready"); }, cancelled: () => false,
|
|
record: async (receipt: unknown) => { receipts.push(receipt); },
|
|
} };
|
|
}
|
|
|
|
describe("controller outage qualification", () => {
|
|
it("keeps original-execution fault evidence enabled for every dedicated continuity cell", async () => {
|
|
const executions = selectRunnerExecutions(parseRunnerSelectors(["--suite", "daytona-restart-continuity"]));
|
|
// Only providers with production managed warm sessions belong in this lane (#18994).
|
|
expect(executions.map(execution => execution.profile.id)).toEqual(["runner-codex"]);
|
|
for (const execution of executions) {
|
|
const outage = controllerOutageForExecution(execution, {});
|
|
expect(outage).toEqual({ signal: "SIGKILL", holdMs: 300_000 });
|
|
expect(controllerOutageForExecution(execution, { PAPERCLIP_RUNNER_E2E_CONTROLLER_OUTAGE_MS: "300000" }))
|
|
.toEqual({ signal: "SIGKILL", holdMs: 300_000 });
|
|
expect(() => controllerOutageForExecution(execution, { PAPERCLIP_RUNNER_E2E_CONTROLLER_OUTAGE_MS: "1000" }))
|
|
.toThrow("shorter than the dedicated continuity contract");
|
|
}
|
|
});
|
|
|
|
it("uses the everyday suite's declared default while retaining explicit short profiles", () => {
|
|
const [execution] = selectRunnerExecutions(parseRunnerSelectors([
|
|
"--id", "everyday-workflows.runner-codex.daytona.recover-controller",
|
|
]));
|
|
expect(controllerOutageForExecution(execution!, {})).toEqual({ signal: "SIGKILL", holdMs: 125_000 });
|
|
expect(controllerOutageForExecution(execution!, { PAPERCLIP_RUNNER_E2E_CONTROLLER_OUTAGE_MS: "1000" }))
|
|
.toEqual({ signal: "SIGKILL", holdMs: 1_000 });
|
|
});
|
|
|
|
it.each(["runner-codex", "runner-acpx-claude"])("supplies replacement fault evidence to the %s Daytona restart cell", async profile => {
|
|
const [execution] = selectRunnerExecutions(parseRunnerSelectors([
|
|
"--id", `everyday-workflows.${profile}.daytona.recover-controller`,
|
|
]));
|
|
expect(execution).toBeDefined();
|
|
const f = fixture();
|
|
const outage = controllerOutageForExecution(execution!, { PAPERCLIP_RUNNER_E2E_CONTROLLER_OUTAGE_MS: "20" });
|
|
const receipt = outage ? await replaceController({ ...f.input, outage }) : undefined;
|
|
expect(validControllerOutageReceipt(receipt, { signal: "SIGKILL", holdMs: 20 })).toBe(true);
|
|
expect(receipt).toMatchObject({ previousPid: 100, replacementPid: 200, cacheDiscarded: true });
|
|
expect(f.order).toEqual(["SIGKILL", "http-down", "empty-cache", "start", "ready"]);
|
|
for (const other of [
|
|
{ ...execution!, environment: { ...execution!.environment, id: "local" as const } },
|
|
{ ...execution!, profile: { ...execution!.profile, generation: "legacy" as const } },
|
|
{ ...execution!, task: { ...execution!.task, id: "stop-redirect" } },
|
|
]) expect(controllerOutageForExecution(other, {})).toBeUndefined();
|
|
});
|
|
it("records an actual bounded outage before starting the successor", async () => {
|
|
const f = fixture();
|
|
const receipt = await replaceController(f.input);
|
|
expect(f.order).toEqual(["SIGKILL", "http-down", "empty-cache", "start", "ready"]);
|
|
expect(receipt.replacementStartedAfterMs! - receipt.stoppedAfterMs!).toBeGreaterThanOrEqual(20);
|
|
expect(validControllerOutageReceipt(receipt, f.input.outage)).toBe(true);
|
|
expect(validControllerOutageReceipt(receipt, { signal: "SIGTERM", holdMs: 20 })).toBe(false);
|
|
expect(validControllerOutageReceipt(receipt, { signal: "SIGKILL", holdMs: 300_000 })).toBe(false);
|
|
expect(validControllerOutageReceipt(receipt, f.input.outage, "another-attempt")).toBe(false);
|
|
expect(f.receipts[0]).not.toHaveProperty("readyAfterMs");
|
|
expect(f.receipts.at(-1)).toEqual(receipt);
|
|
});
|
|
|
|
it.each(["stop", "waitForUnhealthy", "discardCache", "start", "waitForReady"] as const)("retains incomplete evidence when %s fails", async stage => {
|
|
const f = fixture();
|
|
f.input[stage] = vi.fn(async () => { throw new Error(stage); });
|
|
await expect(replaceController(f.input)).rejects.toThrow(stage);
|
|
expect(f.receipts.length).toBeGreaterThan(0);
|
|
expect(f.receipts.every(receipt => !validControllerOutageReceipt(receipt))).toBe(true);
|
|
});
|
|
|
|
it("cancels during the offline interval without launching another server", async () => {
|
|
const f = fixture();
|
|
f.input.cancelled = () => f.order.includes("empty-cache");
|
|
await expect(replaceController(f.input)).rejects.toThrow("shutdown interrupted");
|
|
expect(f.input.start).not.toHaveBeenCalled();
|
|
});
|
|
|
|
it.each([-1, 600001, 0.5, NaN, Infinity, "300000", null])("rejects invalid duration %s before signaling", holdMs => {
|
|
expect(() => parseControllerOutage({ signal: "SIGKILL", holdMs })).toThrow();
|
|
});
|
|
it("accepts chaos holds up to ten minutes", () => {
|
|
expect(parseControllerOutage({ signal: "SIGKILL", holdMs: 360_000 })).toEqual({ signal: "SIGKILL", holdMs: 360_000 });
|
|
expect(parseControllerOutage({ signal: "SIGTERM", holdMs: 600_000 })).toEqual({ signal: "SIGTERM", holdMs: 600_000 });
|
|
});
|
|
it.each(["", "-1", "1e3", "NaN", " 1000", "600001"])("rejects invalid environment duration %s", value => {
|
|
expect(() => configuredControllerOutage({ PAPERCLIP_RUNNER_E2E_CONTROLLER_OUTAGE_MS: value })).toThrow();
|
|
});
|
|
it("accepts the five-minute contract without extending the runner grace", () => {
|
|
expect(configuredControllerOutage({ PAPERCLIP_RUNNER_E2E_CONTROLLER_OUTAGE_MS: "300000" }))
|
|
.toEqual({ signal: "SIGKILL", holdMs: 300000 });
|
|
expect(validControllerOutageReceipt({ schema: "paperclip.e2e.controller-outage/v1", requestId: "late",
|
|
signal: "SIGKILL", holdMs: 300000, previousPid: 1, replacementPid: 2, startedAt: new Date().toISOString(),
|
|
stoppedAfterMs: 0, cacheDiscarded: true, replacementStartedAfterMs: 300000, readyAfterMs: 420000 })).toBe(false);
|
|
});
|
|
it("accepts a hold past the reconnect grace only with an explicit later ready bound", () => {
|
|
const receipt = { schema: "paperclip.e2e.controller-outage/v1", requestId: "long", signal: "SIGKILL", holdMs: 579_090,
|
|
previousPid: 1, replacementPid: 2, startedAt: new Date().toISOString(), stoppedAfterMs: 200, cacheDiscarded: true,
|
|
replacementStartedAfterMs: 579_400, readyAfterMs: 593_500 };
|
|
expect(validControllerOutageReceipt(receipt)).toBe(false);
|
|
expect(validControllerOutageReceipt(receipt, undefined, undefined, undefined, 579_090 + 420_000)).toBe(true);
|
|
});
|
|
});
|
|
|
|
it.each(["absent", "present"])("retires a %s old controller cache", async state => {
|
|
const root = await mkdtemp(join(tmpdir(), "controller-cache-"));
|
|
const cache = join(root, "cache"), retired = join(root, "retired");
|
|
try {
|
|
if (state === "present") { await mkdir(cache); await writeFile(join(cache, "evidence"), "saved"); }
|
|
await retireControllerCache(cache, retired);
|
|
await expect(lstat(cache)).rejects.toMatchObject({ code: "ENOENT" });
|
|
if (state === "present") expect(await readFile(join(retired, "evidence"), "utf8")).toBe("saved");
|
|
} finally { await rm(root, { recursive: true, force: true }); }
|
|
});
|
|
it("does not mistake a missing retirement parent for an already absent cache", async () => {
|
|
const root = await mkdtemp(join(tmpdir(), "controller-cache-")), cache = join(root, "cache");
|
|
try {
|
|
await mkdir(cache); await writeFile(join(cache, "evidence"), "saved");
|
|
await expect(retireControllerCache(cache, join(root, "missing", "retired"))).rejects.toMatchObject({ code: "ENOENT" });
|
|
expect(await readFile(join(cache, "evidence"), "utf8")).toBe("saved");
|
|
} finally { await rm(root, { recursive: true, force: true }); }
|
|
});
|
|
it.each(["missing", "previous-revision", "previous-tree", "replacement-revision", "replacement-tree", "reversed"])(
|
|
"requires the requested upgrade artifact pair when evidence is %s", problem => {
|
|
const A = { revision: "a".repeat(40), treeSha256: "a".repeat(64), version: "1", evidence: "development-build" as const };
|
|
const B = { ...A, revision: "b".repeat(40), treeSha256: "b".repeat(64) };
|
|
const receipt = { schema: "paperclip.e2e.controller-outage/v1", requestId: "upgrade", previousPid: 1, replacementPid: 2,
|
|
startedAt: new Date().toISOString(), signal: "SIGKILL", holdMs: 0, stoppedAfterMs: 0,
|
|
replacementStartedAfterMs: 1, readyAfterMs: 2, cacheDiscarded: true,
|
|
previousArtifact: { ...A }, replacementArtifact: { ...B } };
|
|
expect(validControllerOutageReceipt(receipt, undefined, "upgrade", { previous: A, replacement: B })).toBe(true);
|
|
expect(validControllerOutageReceipt({ ...receipt, previousArtifact: B, replacementArtifact: A }, undefined,
|
|
"upgrade", { previous: B, replacement: A })).toBe(true);
|
|
if (problem === "missing") Object.assign(receipt, { previousArtifact: undefined, replacementArtifact: undefined });
|
|
if (problem === "previous-revision") receipt.previousArtifact.revision = "c".repeat(40);
|
|
if (problem === "previous-tree") receipt.previousArtifact.treeSha256 = "c".repeat(64);
|
|
if (problem === "replacement-revision") receipt.replacementArtifact.revision = "c".repeat(40);
|
|
if (problem === "replacement-tree") receipt.replacementArtifact.treeSha256 = "c".repeat(64);
|
|
if (problem === "reversed") Object.assign(receipt, { previousArtifact: B, replacementArtifact: A });
|
|
expect(validControllerOutageReceipt(receipt, undefined, "upgrade", { previous: A, replacement: B })).toBe(false);
|
|
});
|