mirror of
https://github.com/paperclipai/paperclip.git
synced 2026-11-08 21:01:54 +01:00
## Thinking Path
> - Paperclip is the open source app people use to manage AI agents for
work.
> - Rolling tests must exercise the lifecycle they claim to cover.
> - The warm lane selected a warm environment.
> - Its profiles also set an explicit per-turn agent policy, which took
precedence.
> - The test then waited for a live workspace that per-turn cleanup had
correctly retired.
> - This pull request sets warm agent policy for providers admitted by
the production warm capability.
> - The matrix now checks effective lifecycle and preserves per-turn
coverage for every qualified native profile.
## Linked Issues or Issue Description
Builds on merged #18982 for the source controller dependency link. This
PR now targets master.
**What happened?**
The warm rolling fixture built a Codex agent with `lifecycleMode:
per_turn` and an environment with `runnerLifecycleMode: warm`. The
explicit agent policy won. The initial task completed, its disposable
workspace retired, and the fixture waited for a live file before it
reached deployment.
**Expected behavior**
Warm rolling, legacy migration, remote-file and controller-outage cells
must create actual warm agents. Only providers supported by the
production managed warm-session capability belong in that lane. All
qualified native profiles retain per-turn coverage.
**Steps to reproduce**
Build the old warm Codex cell's agent and environment and compare their
lifecycle policies. The new effective-policy regression fails on the old
catalog and passes on this branch. No duplicate exact-scope warm-fixture
PR was found.
## What Changed
- Share the production managed warm capability filter and explicit warm
agent policy across rolling, legacy migration, remote-file and
controller-outage suites.
- Check effective agent and environment policies and update matrix
coverage/counts.
- Read completed warm turns from the exact saved snapshot while
independently requiring the retained, bound workspace location.
- Keep both rolling lanes separate from the outage simulation and
exercise their assembled supervisor requests.
- Version the corrected definitions and keep every qualified native
profile in the per-turn lanes.
## Verification
- Baseline regression: failed against the unchanged catalog; retained
before the fix.
- Fixed catalog/controller selection: 39 checks passed.
- The first real warm-policy attempt completed and saved its workspace
but timed out because the file oracle demanded live content; retained
trace responses prove the API returned the correct saved snapshot with a
retained lease.
- A new regression fails on the previous reader and passes after
separating saved file source from retained versus released location.
Focused catalog, reader and rolling checks: 81 passed.
- The next warm attempt reached replacement and exposed a second fixture
defect: warm also selected a SIGKILL outage, which the supervisor
rejected alongside rolling mode. The failure remains retained; its four
owned sandboxes, temporary key and local bucket were deleted.
- An outage-selection regression failed before the fix; 57
outage/supervisor checks pass afterward, including assembled requests
for both rolling lanes. The fresh warm Codex run passed all 56 checks in
8.5 minutes: original run/session/runner/lease retained, authenticated
takeover, both predecessor homes removed, later native continuation and
saved file readback. Two replacement receipts recorded 742 ordinary
reads and 75 writes, all 75 read back, with zero HTTP probe failures. A
transient `native_workspace_sync_out_failed` phase recovered before
successful finalization and remains retained. This source-lane result
does not claim released-image or hosted Railway qualification.
- The invalid earlier attempt was interrupted before deployment. Its
four archived disposable sandboxes were deleted and verified absent; its
temporary key and local bucket were removed.
- Broad local typecheck reached stale shared database declarations in
this checkout's linked build dependencies. The fixture's own type error
was corrected; clean-head CI remains required. No full build is claimed
locally.
- An incidental report-catalog test selected by a substring filter
failed to generate its normalized output. That failure is retained
separately; the focused catalog/controller checks pass.
- Review follow-up: fixed the same policy conflict in the base
file-storage, legacy migration and controller-outage suites. The roster
now has 822 valid cells; unsupported warm combinations remain covered
per-turn. Updated the explicit supervisor-request control to use a
supported warm provider. Focused catalog, file-reader, migration,
rolling and supervisor checks pass (133 checks).
- Earlier full CI passed at dd5aa71 using the built-in GitHub-hosted
fallback after self-hosted runner shutdowns. That result does not
qualify this new head; fresh CI and review are required. The final head
now has a 5/5 review and passing full CI (run 41901807639, attempt 2).
Attempt 1 hit two unrelated port collisions: the unchanged managed Codex
credential lease test and CLI company-server startup on a busy requested
port. Both passed on one failed-job retry. Those failures remain
retained.
## Risks
This changes test setup and coverage. It does not change agent runtime
defaults or provider capabilities. Warm cells use the production
capability boundary, while every qualified native profile keeps its
per-turn cell.
## Model Used
OpenAI Codex, exact model ID `gpt-6.1-sol`, with reasoning, tool use and
code execution. The host does not expose context window size.
## 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 linked existing issues or described the issue in-PR
following the relevant issue template
- [x] I have not referenced internal/instance-local Paperclip issues or
links
- [x] My branch name describes the change and contains no internal
ticket id or instance-derived details
- [x] I have run the relevant tests locally; failures and limits are
retained above
- [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 risks above
- [x] All Paperclip CI gates are green
- [x] Greptile is 5/5 with no open P2s, recommendations, or follow-ups
- [x] I will address all Greptile and reviewer comments before
requesting merge
---------
Co-authored-by: Paperclip <noreply@paperclip.ing>
162 lines
8.6 KiB
TypeScript
162 lines
8.6 KiB
TypeScript
import { lstat, rename } from "node:fs/promises";
|
|
import type { ServingArtifact } from "./upgrade-artifacts.js";
|
|
import type { ControllerRecoveryReceipt } from "./controller-recovery-observer.js";
|
|
import { setTimeout as delay } from "node:timers/promises";
|
|
import type { MatrixExecution } from "./types.js";
|
|
import { isRollingWebDeployment } from "./controller-rolling-deployment.js";
|
|
|
|
export interface ControllerOutage {
|
|
signal: "SIGTERM" | "SIGKILL";
|
|
holdMs: number;
|
|
}
|
|
|
|
export interface ControllerOutageReceipt extends ControllerOutage {
|
|
schema: "paperclip.e2e.controller-outage/v1";
|
|
requestId: string;
|
|
previousPid: number;
|
|
replacementPid?: number;
|
|
startedAt: string;
|
|
stoppedAfterMs?: number;
|
|
cacheDiscarded?: boolean;
|
|
replacementStartedAfterMs?: number;
|
|
readyAfterMs?: number;
|
|
previousArtifact?: ServingArtifact;
|
|
replacementArtifact?: ServingArtifact;
|
|
recovery?: ControllerRecoveryReceipt;
|
|
recoveryProgress?: Partial<ControllerRecoveryReceipt>;
|
|
}
|
|
|
|
export function parseControllerOutage(value: unknown): ControllerOutage {
|
|
if (!value || typeof value !== "object" || Array.isArray(value)) throw new Error("Invalid controller outage");
|
|
const { signal, holdMs } = value as Record<string, unknown>;
|
|
if ((signal !== "SIGTERM" && signal !== "SIGKILL") || !Number.isSafeInteger(holdMs)
|
|
|| Number(holdMs) < 0 || Number(holdMs) > 300_000) throw new Error("Controller outage requires SIGTERM/SIGKILL and 0..300000 integer milliseconds");
|
|
return { signal, holdMs: Number(holdMs) };
|
|
}
|
|
|
|
export function configuredControllerOutage(env: NodeJS.ProcessEnv, defaultHoldMs = 1_000): ControllerOutage {
|
|
const raw = env.PAPERCLIP_RUNNER_E2E_CONTROLLER_OUTAGE_MS ?? String(defaultHoldMs);
|
|
if (!/^\d+$/.test(raw)) throw new Error("Invalid PAPERCLIP_RUNNER_E2E_CONTROLLER_OUTAGE_MS");
|
|
return parseControllerOutage({ signal: env.PAPERCLIP_RUNNER_E2E_CONTROLLER_STOP_SIGNAL ?? "SIGKILL", holdMs: Number(raw) });
|
|
}
|
|
|
|
export function controllerOutageForExecution(execution: MatrixExecution, env: NodeJS.ProcessEnv): ControllerOutage | undefined {
|
|
if (isRollingWebDeployment(execution)) return undefined;
|
|
if (execution.task.flow !== "everyday_workflow" || execution.task.id !== "recover-controller"
|
|
|| execution.environment.id !== "daytona" || execution.profile.generation !== "native"
|
|
|| (execution.profile.provider !== "codex" && execution.profile.provider !== "acpx")) return undefined;
|
|
const declaredHoldMs = execution.suite.definitionMetadata?.controllerDowntimeMs;
|
|
if (typeof declaredHoldMs !== "number") throw new Error("Controller recovery suite must declare its outage duration");
|
|
const outage = configuredControllerOutage(env, declaredHoldMs);
|
|
if (["daytona-restart-continuity", "remote-workspace-storage"].includes(execution.suite.id) && outage.holdMs < declaredHoldMs) {
|
|
throw new Error("Controller outage is shorter than the dedicated continuity contract");
|
|
}
|
|
return outage;
|
|
}
|
|
|
|
/** A fault receipt is required in addition to the runner's continuity receipts. */
|
|
export function validControllerOutageReceipt(value: unknown, expected?: ControllerOutage, requestId?: string,
|
|
expectedArtifacts?: { previous: Pick<ServingArtifact, "revision" | "treeSha256">;
|
|
replacement: Pick<ServingArtifact, "revision" | "treeSha256"> }): value is ControllerOutageReceipt {
|
|
if (!value || typeof value !== "object" || Array.isArray(value)) return false;
|
|
const r = value as ControllerOutageReceipt;
|
|
try { parseControllerOutage(r); } catch { return false; }
|
|
const durations = [r.stoppedAfterMs, r.replacementStartedAfterMs, r.readyAfterMs];
|
|
return r.schema === "paperclip.e2e.controller-outage/v1"
|
|
&& typeof r.requestId === "string" && /^[A-Za-z0-9._:-]{1,200}$/.test(r.requestId)
|
|
&& typeof r.startedAt === "string" && Number.isFinite(Date.parse(r.startedAt))
|
|
&& Number.isSafeInteger(r.previousPid) && r.previousPid > 0
|
|
&& Number.isSafeInteger(r.replacementPid) && Number(r.replacementPid) > 0 && r.previousPid !== r.replacementPid
|
|
&& r.cacheDiscarded === true
|
|
&& durations.every(ms => typeof ms === "number" && Number.isFinite(ms) && ms >= 0)
|
|
&& r.replacementStartedAfterMs! - r.stoppedAfterMs! >= r.holdMs
|
|
&& r.readyAfterMs! >= r.replacementStartedAfterMs!
|
|
&& r.readyAfterMs! < 420_000
|
|
&& ((!r.previousArtifact && !r.replacementArtifact) || Boolean(r.previousArtifact && r.replacementArtifact
|
|
&& [r.previousArtifact, r.replacementArtifact].every(a => /^[a-f0-9]{40}$/.test(a.revision)
|
|
&& /^[a-f0-9]{64}$/.test(a.treeSha256) && typeof a.version === "string"
|
|
&& ["released", "development-build"].includes(a.evidence))
|
|
&& r.previousArtifact.revision !== r.replacementArtifact.revision
|
|
&& r.previousArtifact.treeSha256 !== r.replacementArtifact.treeSha256))
|
|
&& (!expectedArtifacts || Boolean(r.previousArtifact && r.replacementArtifact
|
|
&& r.previousArtifact.revision === expectedArtifacts.previous.revision
|
|
&& r.previousArtifact.treeSha256 === expectedArtifacts.previous.treeSha256
|
|
&& r.replacementArtifact.revision === expectedArtifacts.replacement.revision
|
|
&& r.replacementArtifact.treeSha256 === expectedArtifacts.replacement.treeSha256))
|
|
&& (requestId === undefined || r.requestId === requestId)
|
|
&& (!expected || (r.signal === expected.signal && r.holdMs === expected.holdMs));
|
|
}
|
|
|
|
/** Test harness only. Owners supply process cleanup, HTTP probing and cache paths.
|
|
* No database mutation, runner command or production recovery hook is involved.
|
|
*/
|
|
export async function replaceController<T extends { pid?: number }>(input: {
|
|
requestId: string; previousPid: number; outage: ControllerOutage;
|
|
stop: (signal: ControllerOutage["signal"]) => Promise<void>;
|
|
waitForUnhealthy: () => Promise<void>;
|
|
discardCache: () => Promise<void>;
|
|
start: () => Promise<T>;
|
|
waitForReady: (replacement: T) => Promise<void>;
|
|
cancelled: () => boolean;
|
|
record: (receipt: ControllerOutageReceipt) => Promise<void>;
|
|
previousArtifact?: ServingArtifact;
|
|
replacementArtifact?: () => ServingArtifact | undefined;
|
|
afterStopped?: (receipt: ControllerOutageReceipt) => Promise<void>;
|
|
afterReady?: (receipt: ControllerOutageReceipt, record: () => Promise<void>) => Promise<void>;
|
|
}): Promise<ControllerOutageReceipt> {
|
|
const outage = parseControllerOutage(input.outage);
|
|
const started = performance.now();
|
|
const receipt: ControllerOutageReceipt = { schema: "paperclip.e2e.controller-outage/v1",
|
|
requestId: input.requestId, previousPid: input.previousPid, startedAt: new Date().toISOString(), ...outage,
|
|
...(input.previousArtifact ? { previousArtifact: input.previousArtifact } : {}) };
|
|
const check = () => { if (input.cancelled()) throw new Error("Wrapper shutdown interrupted the controller outage"); };
|
|
const record = () => input.record({ ...receipt });
|
|
check();
|
|
await record(); // Failed attempts retain the boundary they actually reached.
|
|
await input.stop(outage.signal);
|
|
await input.waitForUnhealthy();
|
|
receipt.stoppedAfterMs = performance.now() - started;
|
|
await input.afterStopped?.(receipt);
|
|
await record();
|
|
await input.discardCache();
|
|
receipt.cacheDiscarded = true;
|
|
await record();
|
|
while (performance.now() - started - receipt.stoppedAfterMs < outage.holdMs) {
|
|
check();
|
|
await delay(Math.min(100, outage.holdMs - (performance.now() - started - receipt.stoppedAfterMs)));
|
|
}
|
|
check();
|
|
receipt.replacementStartedAfterMs = performance.now() - started;
|
|
await record();
|
|
const replacement = await input.start();
|
|
receipt.replacementPid = replacement.pid;
|
|
await record();
|
|
await input.waitForReady(replacement);
|
|
check();
|
|
receipt.readyAfterMs = performance.now() - started;
|
|
if (input.previousArtifact) {
|
|
receipt.replacementArtifact = input.replacementArtifact?.();
|
|
if (!receipt.replacementArtifact) throw new Error("Replacement has no verified serving artifact");
|
|
}
|
|
await record();
|
|
if (!validControllerOutageReceipt(receipt, outage, input.requestId)) throw new Error("Controller outage did not produce a qualifying replacement receipt");
|
|
await input.afterReady?.(receipt, record);
|
|
return receipt;
|
|
}
|
|
|
|
/** Retire only the controller-owned cache; this is not Runner state. */
|
|
export async function retireControllerCache(cache: string, retired: string): Promise<void> {
|
|
try { await rename(cache, retired); }
|
|
catch (error) {
|
|
if ((error as NodeJS.ErrnoException).code !== "ENOENT") throw error;
|
|
// ENOENT can also mean the destination parent is missing. Only absence of
|
|
// the old cache satisfies retirement; preserve every other failure.
|
|
try { await lstat(cache); }
|
|
catch (missing) {
|
|
if ((missing as NodeJS.ErrnoException).code === "ENOENT") return;
|
|
throw missing;
|
|
}
|
|
throw error;
|
|
}
|
|
}
|