Files
PaperClipAI/tests/restart-chaos/redeploy.ts
T
DottaandClaude Fable 5.2 fb3b09aaef refactor: split the runner-e2e and restart-chaos READMEs into a runbook and a catalog (#21743)
## Thinking Path

> - Paperclip is the open source app people use to manage AI agents for
work
> - `tests/runner-e2e` is the paid Product E2E harness and
`tests/restart-chaos` is the restart chaos harness
> - A README is the first file a person or an agent opens in a directory
> - These two READMEs grew to 3,805 and 2,277 lines. Most of each is a
catalog with one section per suite or per fault scenario, and almost
none of it is ever trimmed
> - This pull request splits each README into a runbook and a catalog
file
> - The benefit is a README that can be read in full, and a clear place
for the next suite or scenario note

## Linked Issues or Issue Description

Refs #21670 and #21700 (the same cleanup for `doc/DEVELOPING.md` and
`doc/DATABASE.md`).

**Issue type**

Outdated or confusing documentation.

**Where is the issue?**

`tests/runner-e2e/README.md` and `tests/restart-chaos/README.md`

**What's wrong?**

In the last 60 days, `tests/runner-e2e/README.md` gained 3,476 lines and
lost 182. `tests/restart-chaos/README.md` gained 2,411 and lost 134. The
setup, evidence, and CI sections sit between suite notes. The first 225
lines of the runner-e2e README are suite notes with no heading.

**Suggested fix**

Keep how to run the harness in the README. Move the per-suite and
per-scenario sections to a catalog file in the same directory.

## What Changed

- `tests/runner-e2e/README.md` is now 767 lines: credentials, local
commands, the Daytona image, evidence and cleanup, billing, the
dashboard, GitHub Actions, and the report preview.
- New `tests/runner-e2e/SUITES.md` (3,055 lines) holds every per-suite
section. The two blocks of suite notes that had no heading now have one.
- `tests/restart-chaos/README.md` is now 592 lines: run, fault timing,
Daytona mode, hosted mode, universal checks, grading notes, pieces,
output, and the crash-point suite.
- New `tests/restart-chaos/SCENARIOS.md` (1,694 lines) holds every
workload and fault scenario section.
- All text is moved without wording changes. Nothing is deleted. The
only edits are three "(below)" references in the restart-chaos README,
which are now links.
- Repointed 22 anchor links and 3 plain links in `doc/evals.md` and
`maps/feature-map/cases.md`.
- Updated seven code comments in `tests/restart-chaos/` that name a
moved section, and two skills that list the runner-e2e docs to read.

## Verification

- The split script asserts that each source line is kept or moved
exactly one time, and checks the first line of each range.
- A link check on the four files and on every file that links into them
found 0 missing files and 0 missing anchors.
- `tests/runner-e2e/daytona-image.test.ts` reads the README for a Docker
build recipe. The recipe is still in the README. I did not run that test
locally.
- `node scripts/check-maps.mjs` passes.
- `node --test .github/scripts/tests/*.test.mjs`: 808 pass, 0 fail.
- `pnpm verify` was not run. This worktree has no installed
dependencies.

## Risks

- Low risk. The change is documentation and comments only.
- A link to a moved section from outside this repository lands on the
top of the README.
- The catalog files are still long. This change moves them off the
first-read path. It does not prune them.

## Model Used

- Claude Fable 5.2 (`claude-fable-5-2`), Claude Code desktop, with tool
use.

## 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
- [ ] 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 Fable 5.2 <noreply@anthropic.com>
2026-11-15 06:01:06 -06:00

170 lines
9.7 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
/**
* K15 (redeploy): what a hosted deploy does to the control plane, beyond K2's graceful stop.
*
* On the hosted staging stack every deploy replaces the server's container. The replacement runs
* in another process space (host name, kernel boot and PID namespace), so the server's PID-based
* "the previous owner has exited" proofs (`server/src/services/controller-process-identity.ts`,
* `owner-proof.ts`) never apply. It also carries a new Railway deployment id on the same exclusive
* volume, which is the proof hosted recovery uses instead. A K1/K2 restart on one machine keeps the
* process space, so every PID proof succeeds there and this path is never exercised.
*
* K15 emulates both changes without a container: each server of a K15 wave sees an emulated host
* name (a `--import` preload replaces `os.hostname`, which changes the process-space hash) and
* Railway-shaped deployment variables naming one stable project, environment, service and volume
* and a deployment id per generation. A K15 stops the server with SIGTERM like K2 and starts the
* replacement as the next generation. Other faults in the same wave restart within a generation,
* like a platform restart of the same deployment.
*/
import { createHash } from "node:crypto";
import { fileURLToPath } from "node:url";
import type { WavePlan } from "./types.js";
/** Whether any server of this wave can be redeployed: a planned, storm or replayed K15. */
export function redeployWave(plan: Pick<WavePlan, "options" | "tasks" | "storm">): boolean {
// CR1 always redeploys; CR2 only when it holds the controller down (class-r.ts). Planned holds decide CR2.
const redeploys = (kind: string, holdMs: number) => kind === "K15" || kind === "CR1" || (kind === "CR2" && holdMs > 0);
return plan.options.faults.some(kind => kind === "K15" || kind === "CR1")
|| (plan.storm?.faults.some(fault => redeploys(fault.kind, fault.holdMs)) ?? false)
|| plan.tasks.some(task => redeploys(task.fault, task.holdMs)
|| (task.replayFaults?.some(fault => redeploys(fault.kind, fault.holdMs)) ?? false));
}
/** `--k15-hold-seconds` upper bound: the controller-outage cap (tests/runner-e2e/controller-outage.ts). */
export const K15_MAX_HOLD_SECONDS = 600;
/**
* `--k15-hold-seconds <n>` or `<min>-<max>` (0–600 s): how long a K15 keeps the server down between its SIGTERM
* and the next deploy's start. Staging deploys were down 4–7 minutes, so the remote Runner has to survive the
* gap mid-turn. Without it a K15 restarts at once.
*/
export function parseK15HoldSeconds(options: { faults: readonly string[] }, raw: string | undefined): { k15HoldMs?: [number, number] } {
if (raw === undefined) return {};
if (!options.faults.includes("K15")) throw new Error("--k15-hold-seconds sets the K15 outage; add K15 to --faults");
const match = /^([0-9]+)(?:-([0-9]+))?$/.exec(raw.trim());
if (!match) throw new Error("--k15-hold-seconds takes <seconds> or <min>-<max> seconds");
const min = Number(match[1]);
const max = match[2] === undefined ? min : Number(match[2]);
if (max > K15_MAX_HOLD_SECONDS || max < min) {
throw new Error(`--k15-hold-seconds must be between 0 and ${K15_MAX_HOLD_SECONDS} seconds, min not above max`);
}
return { k15HoldMs: [min * 1000, max * 1000] };
}
/** `--k15-overlap-seconds` bounds: staging's old server kept running 30–150 s after the new one was up. */
export const K15_OVERLAP_SECONDS_RANGE: readonly [number, number] = [5, 600];
/**
* The staging deploy shape (SCENARIOS.md "Redeploy without a volume, with overlap"):
*
* - `--k15-overlap-seconds <n>` or `<min>-<max>`: a K15 boots the next deploy generation beside the old server,
* switches traffic (the wave's stable port) to it once it is ready, keeps the old server running for the seeded
* overlap, then stops the old one with SIGTERM. The seeded K15 hold becomes the overlap; there is no outage.
* - `--k15-fresh-home`: every deploy generation gets a new, empty instance home and no Railway volume, as staging's
* deploys after 07:25Z reported `volumeId: null`. The database, secrets key and storage stay (they live outside
* the instance home on staging); controller-local files such as `runtime-context-assets` do not. Daytona only:
* a local run's workspace and runner live under the instance home.
*/
export function parseK15DeployShape(options: { env: string; faults: readonly string[]; k15HoldMs?: [number, number] },
overlapRaw: string | undefined, freshHome: boolean): { k15HoldMs?: [number, number]; k15Overlap?: true; k15FreshHome?: true } {
const out: { k15HoldMs?: [number, number]; k15Overlap?: true; k15FreshHome?: true } = {};
if ((overlapRaw !== undefined || freshHome) && !options.faults.includes("K15")) {
throw new Error("--k15-overlap-seconds and --k15-fresh-home shape the K15 redeploy; add K15 to --faults");
}
if (overlapRaw !== undefined) {
if (options.k15HoldMs) throw new Error("--k15-overlap-seconds replaces the K15 outage; do not combine it with --k15-hold-seconds");
const match = /^([0-9]+)(?:-([0-9]+))?$/.exec(overlapRaw.trim());
if (!match) throw new Error("--k15-overlap-seconds takes <seconds> or <min>-<max> seconds");
const min = Number(match[1]);
const max = match[2] === undefined ? min : Number(match[2]);
const [low, high] = K15_OVERLAP_SECONDS_RANGE;
if (min < low || max > high || max < min) throw new Error(`--k15-overlap-seconds must be between ${low} and ${high} seconds, min not above max`);
out.k15HoldMs = [min * 1000, max * 1000];
out.k15Overlap = true;
}
if (freshHome) {
if (options.env !== "daytona") throw new Error("--k15-fresh-home runs only with --env daytona: a local run's workspace and runner live in the instance home");
out.k15FreshHome = true;
}
return out;
}
/** The seeded hold of one K15. Draws only when a range is set, so existing seeds keep their plans. */
export function k15HoldMs(range: readonly [number, number] | undefined, int: (min: number, max: number) => number): number {
return range ? int(range[0], range[1]) : 0;
}
/** The preload that applies the emulated host name before the server loads. */
export const REDEPLOY_PRELOAD_PATH = fileURLToPath(new URL("./redeploy-preload.mjs", import.meta.url));
/** Read by the preload: the host name `os.hostname()` returns in the server process. */
export const REDEPLOY_HOSTNAME_ENV = "RESTART_CHAOS_REDEPLOY_HOSTNAME";
export interface RedeployIdentity {
/** 0 for the wave's first server; each K15 adds one. */
generation: number;
hostname: string;
projectId: string;
environmentId: string;
serviceId: string;
deploymentId: string;
volumeId: string;
}
/** A deterministic UUID-shaped id for one wave, role and generation (no randomness: replays match). */
function uuidFor(waveId: string, role: string, generation = 0): string {
const hex = createHash("sha256").update(`restart-chaos-redeploy:${waveId}:${role}:${generation}`).digest("hex");
// Version 5-style layout so validators that require a UUID shape accept it.
const variant = ((parseInt(hex[16]!, 16) & 0x3) | 0x8).toString(16);
return `${hex.slice(0, 8)}-${hex.slice(8, 12)}-5${hex.slice(13, 16)}-${variant}${hex.slice(17, 20)}-${hex.slice(20, 32)}`;
}
/** The identity of the server that serves generation `generation` of this wave. */
export function redeployIdentity(waveId: string, generation: number): RedeployIdentity {
if (!Number.isInteger(generation) || generation < 0) throw new Error(`Redeploy generation must be a non-negative integer, got ${generation}`);
return {
generation,
hostname: `chaos-deploy-${createHash("sha256").update(`${waveId}:${generation}`).digest("hex").slice(0, 10)}`,
projectId: uuidFor(waveId, "project"),
environmentId: uuidFor(waveId, "environment"),
serviceId: uuidFor(waveId, "service"),
deploymentId: uuidFor(waveId, "deployment", generation),
volumeId: uuidFor(waveId, "volume"),
};
}
/** The next deploy of the same service: same project, environment, service and volume. */
export function nextRedeployIdentity(waveId: string, current: RedeployIdentity): RedeployIdentity {
return redeployIdentity(waveId, current.generation + 1);
}
/**
* Server environment for one generation. The volume mount is the instance home: on staging the
* instance directory lives on the exclusive volume that survives each deploy.
*/
export function redeployEnvironment(identity: RedeployIdentity, volumeMountPath: string | null): Record<string, string> {
return {
[REDEPLOY_HOSTNAME_ENV]: identity.hostname,
RAILWAY_PROJECT_ID: identity.projectId,
RAILWAY_ENVIRONMENT_ID: identity.environmentId,
RAILWAY_SERVICE_ID: identity.serviceId,
RAILWAY_DEPLOYMENT_ID: identity.deploymentId,
// `--k15-fresh-home`: no volume, as staging's later deploys reported `volumeId: null`.
...(volumeMountPath === null ? {} : { RAILWAY_VOLUME_ID: identity.volumeId, RAILWAY_VOLUME_MOUNT_PATH: volumeMountPath }),
};
}
/** `--k15-fresh-home`: generation N's own instance home (generation 0 keeps the wave's first home). */
export function generationHome(temporaryRoot: string, firstHome: string, generation: number): string {
return generation === 0 ? firstHome : `${temporaryRoot}/home-g${generation}`;
}
/** Node arguments that load the preload ahead of the server entry's own `--import` loader. */
export function redeployNodeArgs(args: readonly string[]): string[] {
return ["--import", REDEPLOY_PRELOAD_PATH, ...args];
}
/** What a K15 receipt records: both generations, so a replay and the evidence name them. */
export function redeployReceipt(from: RedeployIdentity, to: RedeployIdentity) {
return { fromGeneration: from.generation, toGeneration: to.generation, fromHostname: from.hostname, toHostname: to.hostname,
fromDeploymentId: from.deploymentId, toDeploymentId: to.deploymentId, volumeId: to.volumeId };
}