mirror of
https://github.com/paperclipai/paperclip.git
synced 2026-12-04 21:21:27 +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 zero-downtime
gate waves and grades each wave and each task
> - Gate wave A1 of rerun 6 (w-20261116T001158-s7106) failed. Its "warm
sessions that did not close" count was 28, but only 2 sessions failed to
close. Task t010 also failed R5, but its run was healthy.
> - The harness's environment-delete retry loop re-ran one failing close
every 3 s, so one failed session was logged 27 times. The harness
counted log lines, not failures. Also, no sandbox capture existed from
the time of the failed idle close, so the cause was not recorded.
> - R5 saw 253 s of silence on t010's run aedc1f6e. The run spent 251 s
in `environment.acquire` (a Daytona restore of an archived sandbox, with
one 90 s plugin call timeout). The "run started" event is written only
after acquire, so the run had no event during that time. The run then
succeeded.
> - This pull request makes the warm-shutdown grade count distinct (run,
reason) failures, captures the sandbox at the first idle-close failure,
and lets R5 wait up to 10 minutes while a running run has no run event
yet.
> - The benefit is a wave grade that shows the real number of failed
sessions, records why a close failed, and does not report a slow
environment acquire as a dead run.
## Linked Issues or Issue Description
**Bug description**
Three findings from gate wave A1 of rerun 6 (w-20261116T001158-s7106):
1. `warm-shutdown.ts` reports one failure per log line. The wave showed
29 shutdown close failures (28 "did not close" lines and 1 "cleanup
failed before controller shutdown" line) for 2 sessions: run 300f0d61 (2
lines) and run 70d909cc (27 lines from the environment-delete retries).
No sandbox capture was taken when the idle close of 70d909cc failed, so
why the Runner did not suspend is not known.
2. R5 reported `silent_dead_run aedc1f6e… 181s` for task t010. The run
was in environment acquire for 251 s. It then succeeded.
3. Task t024 failed its content check `subtask_1_done`. The child saved
its ledger with Read-tool line-number prefixes (`1\tROUND 1 ...`). The
grader requires lines that start with `ROUND`. This is model behaviour:
a ledger that the agent corrupts is a real content failure. This pull
request does NOT change that check.
**Steps to reproduce**
1. Grade the A1 server log lines (fixture
`fixtures/a1-warm-close-failures.log`) with `gradeWarmShutdown`. The
result has 29 `shutdownCloseFailures` entries.
2. Grade the t010 samples (fixture
`fixtures/t010-slow-environment-acquire.json`) with `gradeR5`. The
result is `fail: silent_dead_run aedc1f6e…`.
**Expected behavior**
1. The grade shows 2 distinct shutdown close failures, each with its
line count, and the verdict stays "fail".
2. R5 passes a run that has no run event yet for up to 10 minutes. R5
still fails a run with no event past 10 minutes, and a started run that
is silent past 3 minutes.
## What Changed
- `warm-shutdown.ts`: `shutdownCloseFailures` and `idleCloseFailures`
are now lists of distinct `{ runId, reason, lines, firstLine }` entries,
keyed by run and failure reason. The reason drops the JSON detail after
the error text (for example timings), so retries of the same failure
merge. A line with no parsable run keeps its own message as the reason.
Each distinct shutdown failure still adds a problem, so the verdict is
unchanged in meaning: any distinct failure fails the wave.
- `warm-shutdown.ts`: new `watchFirstIdleCloseFailure` splits server
output into lines per stream and reports the first idle-close failure
once. New optional `sandboxCaptures` input and output, listed in the
markdown section.
- `supervisor.ts`: new `onServerOutput(chunk, source)` hook, called for
the primary and the second server's stdout and stderr. A hook error is
recorded in the timeline and never breaks logging.
- `main.ts`: on a Daytona warm wave, the first idle-close failure
triggers one `captureRunnerLogs("idle-close-failure-<run>")` (the class
R probe: processes, sockets, Runner runtime files including
`runner-state.json`, and logs). The harness waits for that capture
before the environment cleanup and before the warm-shutdown grade.
- `observer.ts` / `types.ts`: a running run whose events read back empty
(the read succeeded and there is no event yet) gets `preparing: true` in
its sample. A failed events read does not set it.
- `grader.ts`: new `PREPARATION_LIMIT_MS` (10 minutes). `deadRunningRun`
uses it when the run sample has `preparing`.
- Why 10 minutes: the observed acquire took 251 s, including one 90 s
plugin call timeout. The Daytona provider bounds each start or restore
at 5 minutes by default (`DEFAULT_DAYTONA_OPERATION_TIMEOUT_MS`), so 10
minutes covers one timed-out restore and its retry. This is the same
bound #21730 gave an active provider turn.
- New fixtures: `fixtures/a1-warm-close-failures.log` (the 34 real
close-failure lines of the A1 server log) and
`fixtures/t010-slow-environment-acquire.json` (the 87 real t010 samples
of run aedc1f6e, with the time of its first run event).
- `README.md`: document the distinct-failure count, the idle-close
capture and the preparation bound for R5.
- t024: no change. Decision: the ledger check stays strict, because a
ledger that the agent saved with line-number prefixes is a real content
failure.
## Verification
- Red on `origin/master` sources, green with this change (9 tests):
- `warm-shutdown.test.ts` › "reports each distinct (run, reason) once,
not each log line (w-20261116T001158-s7106 A1: 2 sessions, 29 lines)": 2
failures (300f0d61 with 2 lines, 70d909cc with 27 lines), 2 problems,
verdict fail.
- `warm-shutdown.test.ts` › "still fails on one distinct failure, and
keeps different reasons for the same run apart" (guards: the 27 lines of
one session still fail; two reasons for one run give two problems; an
unparsable line still fails).
- `warm-shutdown.test.ts` › "names the first idle-close failure once,
across chunk boundaries and interleaved streams" (a forced-stop line
does not trigger it).
- `warm-shutdown.test.ts` › "lists the sandbox captures taken at the
first idle-close failure", plus the two updated shape tests.
- `triggers.test.ts` › R5 live evidence › "does not flag a run that is
still acquiring its environment before its first run event
(w-20261116T001158-s7106/t010)": the real samples still fail without
`preparing`, and pass with `preparing` on the samples before the first
run event.
- `triggers.test.ts` › R5 live evidence › "still fails a run silent past
the preparation bound, and a started run silent past the stall bound"
(guards: 9.5 min preparing passes; 10.5 min preparing fails; 4 min quiet
without `preparing` fails).
- `triggers.test.ts` › R5 live evidence › "marks a running run as
preparing only while its events read back empty" (the flag clears after
the "run started" event; a failed events read never sets it).
- `npx vitest run --config tests/restart-chaos/vitest.config.ts`: 71
files, 833 tests pass.
- `npx tsc -p tests/restart-chaos/tsconfig.json --noEmit`: clean.
- No wave was run. The live idle-close capture path in `main.ts` is not
exercised by a unit test.
## Risks
- Low risk. The change touches only the test harness.
- `warm-shutdown.json` changes shape: `shutdownCloseFailures` and
`idleCloseFailures` are now objects, not strings. Scripts that read
these fields as strings must read `firstLine`. Summary counts now show
sessions, not lines, so they are lower than before for the same log.
- A run that dies before its first run event now fails R5 after 10
minutes instead of 3. The fault is still caught, but later.
- The idle-close capture can add up to 45 s (the capture deadline)
before the environment cleanup on a wave that had an idle-close failure.
> For core feature work, check [`ROADMAP.md`](ROADMAP.md) first and
discuss it in `#dev` before opening the PR. Feature PRs that overlap
with planned core work may need to be redirected — check the roadmap
first. See `CONTRIBUTING.md`.
## Model Used
- Anthropic Claude Opus 5.5 (`claude-opus-5-5`), used in Claude Code
with tool use and code execution.
## 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 Opus 5.5 <noreply@anthropic.com>
583 lines
36 KiB
TypeScript
583 lines
36 KiB
TypeScript
import { spawnSync } from "node:child_process";
|
||
import { readFileSync } from "node:fs";
|
||
import { mkdtemp, rm, writeFile } from "node:fs/promises";
|
||
import os from "node:os";
|
||
import path from "node:path";
|
||
import { describe, expect, it } from "vitest";
|
||
import { isSocketTypeOfServiceRace, type ChaosApi } from "./api.js";
|
||
import { parseCommand } from "./config.js";
|
||
import { gradeR5, PREPARATION_LIMIT_MS } from "./grader.js";
|
||
import { DEFAULT_UNIVERSAL_BOUNDS, gradeU1 } from "./universal.js";
|
||
import { latestIso, localProcessAlive, noteLivenessEvent, QUEUED_TRIGGER_MAX_EMPTY_SAMPLES, TaskObserver, TRIGGER_LATE_MS } from "./observer.js";
|
||
import { observedFaultSchedule, planTasks, taskFaultSchedule, TRIGGER_DELAY_RANGE_MS } from "./scheduler.js";
|
||
import type { ChaosLab } from "./seed.js";
|
||
import { crashLoopShouldFire } from "./supervisor.js";
|
||
import { Timeline } from "./timeline.js";
|
||
import { ledgerLine } from "./ledger.js";
|
||
import type { TaskGrade, TaskPlan, TaskRecord, TaskSample, WaveOptions, WavePlan } from "./types.js";
|
||
|
||
process.env.RESTART_CHAOS_QUIET = "1";
|
||
const lab: ChaosLab = { companyId: "c1", environmentId: "e1", environmentKind: "local", projectId: "p1", fixtureRepositoryPath: "/tmp/none",
|
||
agents: { codex: { id: "a1", name: "Chaos codex" }, claude: { id: "a2", name: "Chaos claude" }, opencode: { id: "a3", name: "Chaos opencode" } } };
|
||
const ready = { serverReady: true, faultInProgress: false };
|
||
const base: TaskPlan = { taskId: "t01", index: 0, workload: "A1", adapter: "codex", fault: "K1", fireAfterMs: 999_999,
|
||
holdMs: 0, followUpAfterMs: null, nonce: "abcd1234" };
|
||
const options: WaveOptions = { env: "local", adapters: ["codex", "claude", "opencode"], workloads: ["A1", "B1", "B5", "C1"],
|
||
faults: ["K1", "K2", "K4", "K6"], concurrency: 3, tasks: 60, seed: 9, budgetCents: 3_000, pollMs: 3_000,
|
||
triggers: ["time", "comment", "retry", "queued", "tool"] };
|
||
|
||
type Json = Record<string, unknown>;
|
||
function scriptedApi(state: { runs: Json[]; issue: Json; retry?: Json; events?: Json[] }) {
|
||
const api = {
|
||
async get(route: string) {
|
||
if (route.includes("/events")) {
|
||
const after = Number(new URL(route, "http://x").searchParams.get("afterSeq") ?? 0);
|
||
return (state.events ?? []).filter(event => Number(event.seq) > after);
|
||
}
|
||
return route.endsWith("/runs") ? state.runs : route.endsWith("/comments") ? [] : state.issue;
|
||
},
|
||
async post(route: string) {
|
||
if (route.endsWith("/issues")) return { id: "i1", identifier: "CHA-1" };
|
||
if (route.endsWith("/retry")) return state.retry ?? { accepted: true };
|
||
return { id: "comment-1" };
|
||
},
|
||
};
|
||
return api as unknown as ChaosApi;
|
||
}
|
||
|
||
describe("trigger planning", () => {
|
||
it("pairs comment only with C1 and tool only with B5, with delays inside each range", () => {
|
||
const tasks = planTasks(options);
|
||
for (const task of tasks) {
|
||
if (task.trigger === "comment") expect(task.workload).toBe("C1");
|
||
if (task.trigger === "tool") expect(task.workload).toBe("B5");
|
||
if (task.trigger && task.trigger !== "time") {
|
||
const [min, max] = TRIGGER_DELAY_RANGE_MS[task.trigger];
|
||
expect(task.triggerDelayMs).toBeGreaterThanOrEqual(min);
|
||
expect(task.triggerDelayMs).toBeLessThanOrEqual(max);
|
||
} else expect(task.triggerDelayMs).toBeUndefined();
|
||
}
|
||
expect(new Set(tasks.map(task => task.trigger ?? "time")).size).toBe(5);
|
||
expect(planTasks(options)).toEqual(tasks);
|
||
});
|
||
|
||
it("keeps time-only plans free of trigger fields and rejects a trigger with no fitting workload", () => {
|
||
expect(planTasks({ ...options, triggers: undefined }).every(task => task.trigger === undefined)).toBe(true);
|
||
expect(() => planTasks({ ...options, workloads: ["A1"], triggers: ["tool"] })).toThrow(/needs workload B5/);
|
||
});
|
||
|
||
it("schedules the K8 retry fault as an extra K1 after the planned fault", () => {
|
||
expect(taskFaultSchedule({ ...base, fireAfterMs: 30_000, trigger: "retry", triggerDelayMs: 500 })).toEqual([
|
||
{ kind: "K1", holdMs: 0, atMs: 30_000 }, { kind: "K1", holdMs: 0, atMs: 0, trigger: "retry", delayMs: 500 }]);
|
||
expect(taskFaultSchedule({ ...base, fault: "K6", trigger: "queued", triggerDelayMs: 0 }))
|
||
.toEqual([{ kind: "K6", holdMs: 0, atMs: 999_999, trigger: "queued", delayMs: 0 }]);
|
||
});
|
||
|
||
it("re-arms only the replayed task's own triggered faults", () => {
|
||
const faults = [
|
||
{ faultId: "f01", kind: "K1" as const, holdMs: 0, startedAt: 2_000, requestedBy: "t01", trigger: "queued" as const, triggerDelayMs: 0 },
|
||
{ faultId: "f02", kind: "K1" as const, holdMs: 0, startedAt: 9_000, requestedBy: "t02", trigger: "comment" as const, triggerDelayMs: 3_000 },
|
||
];
|
||
expect(observedFaultSchedule(1_000, ["f01", "f02"], faults, "t01")).toEqual([
|
||
{ kind: "K1", holdMs: 0, atMs: 1_000, trigger: "queued", delayMs: 0 }, { kind: "K1", holdMs: 0, atMs: 8_000 }]);
|
||
});
|
||
|
||
it("parses --triggers and refuses it with --replay", () => {
|
||
expect(parseCommand(["--triggers", "comment,queued"])).toMatchObject({ options: { triggers: ["comment", "queued"] } });
|
||
expect(parseCommand([])).toMatchObject({ options: { triggers: ["time"] } });
|
||
expect(() => parseCommand(["--triggers", "later"])).toThrow(/Unknown triggers/);
|
||
expect(() => parseCommand(["--replay", "w-20261106T101112-s42/t03", "--triggers", "comment"])).toThrow(/reproduces the saved plan/);
|
||
});
|
||
});
|
||
|
||
describe("trigger firing", () => {
|
||
it("queued: fires on the first run that is still queued, and misses once a run has started", async () => {
|
||
const state = { runs: [{ runId: "r1", status: "queued", createdAt: new Date().toISOString() }] as Json[], issue: { id: "i1", status: "todo" } };
|
||
const observer = new TaskObserver({ ...base, trigger: "queued", triggerDelayMs: 0 }, scriptedApi(state), lab, new Timeline(null), ready);
|
||
await observer.launch();
|
||
const start = observer.record.createdAt!;
|
||
expect(observer.faultDue(start)).toBeNull();
|
||
await observer.poll(start + 10);
|
||
expect(observer.faultDue(start + 10)).toMatchObject({ trigger: "queued", kind: "K1" });
|
||
|
||
const late = { runs: [{ runId: "r1", status: "running", startedAt: new Date().toISOString() }] as Json[], issue: { id: "i1", status: "in_progress" } };
|
||
const missed = new TaskObserver({ ...base, trigger: "queued", triggerDelayMs: 0 }, scriptedApi(late), lab, new Timeline(null), ready);
|
||
await missed.launch();
|
||
await missed.poll(missed.record.createdAt! + 10);
|
||
expect(missed.faultDue(missed.record.createdAt! + 10)).toBeNull();
|
||
expect(missed.record.triggerMissed).toEqual(["queued"]);
|
||
});
|
||
|
||
it("queued: gives up after several polls with no run at all", async () => {
|
||
const state = { runs: [] as Json[], issue: { id: "i1", status: "todo" } };
|
||
const observer = new TaskObserver({ ...base, trigger: "queued", triggerDelayMs: 0 }, scriptedApi(state), lab, new Timeline(null), ready);
|
||
await observer.launch();
|
||
const start = observer.record.createdAt!;
|
||
for (let index = 1; index < QUEUED_TRIGGER_MAX_EMPTY_SAMPLES; index += 1) {
|
||
await observer.poll(start + index);
|
||
expect(observer.faultDue(start + index)).toBeNull();
|
||
}
|
||
expect(observer.record.triggerMissed).toBeUndefined();
|
||
await observer.poll(start + 100);
|
||
observer.faultDue(start + 100);
|
||
expect(observer.record.triggerMissed).toEqual(["queued"]);
|
||
});
|
||
|
||
it("comment: fires its delay after the follow-up reaches a live run", async () => {
|
||
const state = { runs: [{ runId: "r1", status: "running", startedAt: new Date().toISOString() }] as Json[], issue: { id: "i1", status: "in_progress" } };
|
||
const observer = new TaskObserver({ ...base, workload: "C1", followUpAfterMs: 1_000, trigger: "comment", triggerDelayMs: 2_000 },
|
||
scriptedApi(state), lab, new Timeline(null), ready);
|
||
await observer.launch();
|
||
const start = observer.record.createdAt!;
|
||
await observer.poll(start + 500);
|
||
expect(observer.faultDue(start + 500)).toBeNull();
|
||
await observer.poll(start + 1_500);
|
||
expect(observer.record.followUp).toMatchObject({ commentId: "comment-1", duringRun: true });
|
||
expect(observer.faultDue(start + 3_499)).toBeNull();
|
||
expect(observer.faultDue(start + 3_500)).toMatchObject({ trigger: "comment" });
|
||
});
|
||
|
||
it("comment: a follow-up posted to a resting task does not fire", async () => {
|
||
const state = { runs: [{ runId: "r1", status: "succeeded", finishedAt: new Date().toISOString() }] as Json[], issue: { id: "i1", status: "done" } };
|
||
const observer = new TaskObserver({ ...base, workload: "C1", followUpAfterMs: 0, trigger: "comment", triggerDelayMs: 0 },
|
||
scriptedApi(state), lab, new Timeline(null), ready);
|
||
await observer.launch();
|
||
await observer.poll(observer.record.createdAt! + 10);
|
||
expect(observer.faultDue(observer.record.createdAt! + 10)).toBeNull();
|
||
expect(observer.record.triggerMissed).toEqual(["comment"]);
|
||
});
|
||
|
||
it("clicks Retry through the board UI when the wave drives a browser, and records what the user saw", async () => {
|
||
const state = { runs: [{ runId: "r1", status: "failed", finishedAt: new Date().toISOString() }] as Json[],
|
||
issue: { id: "i1", status: "blocked", interruption: { state: "failed", canRetry: true, observedRunId: "r1" } } };
|
||
const clicks: string[] = [];
|
||
const board = { clickRetry: async (issue: string) => { clicks.push(issue);
|
||
return { clicked: true, httpStatus: 202, accepted: true, error: null, bannerText: "Couldn’t finish this attempt." }; } };
|
||
const observer = new TaskObserver(base, scriptedApi(state), lab, new Timeline(null), ready, undefined, board);
|
||
await observer.launch();
|
||
const start = observer.record.createdAt!;
|
||
await observer.poll(start + 1_000);
|
||
await observer.poll(start + 1_000 + 12_001);
|
||
expect(clicks).toEqual(["CHA-1"]);
|
||
expect(observer.record.retry).toMatchObject({ via: "ui", accepted: true, httpStatus: 202, bannerText: "Couldn’t finish this attempt." });
|
||
|
||
const missing = { clickRetry: async () => ({ clicked: false, httpStatus: null, accepted: null, error: "ui_retry_button_missing", bannerText: "Saving files from the previous attempt" }) };
|
||
const blind = new TaskObserver(base, scriptedApi(state), lab, new Timeline(null), ready, undefined, missing);
|
||
await blind.launch();
|
||
await blind.poll(blind.record.createdAt! + 1_000);
|
||
await blind.poll(blind.record.createdAt! + 1_000 + 12_001);
|
||
expect(blind.record.retry).toMatchObject({ via: "ui", accepted: null, error: "ui_retry_button_missing" });
|
||
});
|
||
|
||
it("retry: fires the extra K1 right after an accepted Retry click, and closes unfired triggers at sweep", async () => {
|
||
const state = { runs: [{ runId: "r1", status: "failed", finishedAt: new Date().toISOString() }] as Json[],
|
||
issue: { id: "i1", status: "blocked", interruption: { state: "needs_retry", canRetry: true, observedRunId: "r1" } } };
|
||
const observer = new TaskObserver({ ...base, fireAfterMs: 1_000, trigger: "retry", triggerDelayMs: 0 }, scriptedApi(state), lab, new Timeline(null), ready);
|
||
await observer.launch();
|
||
const start = observer.record.createdAt!;
|
||
expect(observer.faultDue(start + 1_000)).toEqual({ kind: "K1", holdMs: 0, atMs: 1_000 });
|
||
await observer.poll(start + 2_000);
|
||
expect(observer.faultDue(start + 2_000)).toBeNull();
|
||
await observer.poll(start + 2_000 + 12_001);
|
||
expect(observer.record.retry).toMatchObject({ accepted: true });
|
||
expect(observer.faultDue(start + 14_002)).toMatchObject({ kind: "K1", trigger: "retry" });
|
||
|
||
const unclicked = new TaskObserver({ ...base, trigger: "retry", triggerDelayMs: 0 }, scriptedApi(state), lab, new Timeline(null), ready);
|
||
await unclicked.launch();
|
||
await unclicked.sweep();
|
||
expect(unclicked.record.triggerMissed).toEqual(["retry"]);
|
||
});
|
||
|
||
it("clicks Retry once per fault: again only after a fault that started after the last click", async () => {
|
||
const state = { runs: [{ runId: "r1", status: "failed", finishedAt: new Date().toISOString() }] as Json[],
|
||
issue: { id: "i1", status: "blocked", interruption: { state: "failed", canRetry: true, observedRunId: "r1" } } };
|
||
const observer = new TaskObserver({ ...base }, scriptedApi(state), lab, new Timeline(null), ready);
|
||
await observer.launch();
|
||
const start = observer.record.createdAt!;
|
||
await observer.poll(start + 1_000);
|
||
await observer.poll(start + 1_000 + 12_001);
|
||
const first = observer.record.retry!;
|
||
expect(first.accepted).toBe(true);
|
||
await observer.poll(start + 20_000);
|
||
await observer.poll(start + 20_000 + 12_001);
|
||
expect(observer.done).toBe(true);
|
||
expect(observer.record.retry).toBe(first);
|
||
|
||
const again = new TaskObserver({ ...base }, scriptedApi(state), lab, new Timeline(null), ready);
|
||
await again.launch();
|
||
const begin = again.record.createdAt!;
|
||
await again.poll(begin + 1_000);
|
||
await again.poll(begin + 1_000 + 12_001);
|
||
const clicked = again.record.retry!;
|
||
again.noteFault("f01", clicked.at + 1);
|
||
await again.poll(begin + 20_000);
|
||
await again.poll(begin + 20_000 + 12_001);
|
||
expect(again.done).toBe(false);
|
||
expect(again.record.priorRetries).toEqual([clicked]);
|
||
expect(again.record.retry).not.toBe(clicked);
|
||
});
|
||
|
||
it("tool: fires its delay after bench.sh progress is first seen", async () => {
|
||
const observer = new TaskObserver({ ...base, workload: "B5", trigger: "tool", triggerDelayMs: 20_000 },
|
||
scriptedApi({ runs: [], issue: { id: "i1", status: "in_progress" } }), lab, new Timeline(null), ready);
|
||
await observer.launch();
|
||
const start = observer.record.createdAt!;
|
||
expect(observer.faultDue(start + 60_000)).toBeNull();
|
||
observer.record.benchFirstSeenAt = start + 30_000;
|
||
expect(observer.faultDue(start + 49_999)).toBeNull();
|
||
expect(observer.faultDue(start + 50_000)).toMatchObject({ trigger: "tool" });
|
||
});
|
||
|
||
it("result: arms from the target run's result event and fires only while that run is running", async () => {
|
||
const running = { runId: "r1", status: "running", startedAt: new Date().toISOString() };
|
||
const state = { runs: [running] as Json[], issue: { id: "i1", status: "in_progress" },
|
||
events: [{ seq: 1, eventType: "turn.started", createdAt: new Date().toISOString() }] as Json[] };
|
||
const observer = new TaskObserver({ ...base, trigger: "result", triggerDelayMs: 2_000 }, scriptedApi(state), lab, new Timeline(null), ready);
|
||
await observer.launch();
|
||
const start = observer.record.createdAt!;
|
||
observer.record.followUp = { at: start, postedAt: start, commentId: "c1", error: null, duringRun: true };
|
||
await observer.poll(start + 1_000);
|
||
// An unrelated event does not arm the trigger.
|
||
expect(observer.record.resultAcceptedAt).toBeUndefined();
|
||
state.events.push({ seq: 2, eventType: "run.result.accepted", createdAt: new Date().toISOString() });
|
||
await observer.poll(start + 2_000);
|
||
const armedAt = observer.record.resultAcceptedAt!;
|
||
expect(observer.record.resultRunId).toBe("r1");
|
||
expect(observer.faultDue(armedAt + 1_999)).toBeNull();
|
||
const fault = observer.faultDue(armedAt + 2_000);
|
||
expect(fault).toMatchObject({ trigger: "result" });
|
||
expect(await observer.confirmTrigger(fault!, armedAt + 2_000)).toBe(true);
|
||
// The run settled before dispatch: the fault would land outside the window.
|
||
state.runs = [{ ...running, status: "succeeded", finishedAt: new Date().toISOString() }];
|
||
expect(await observer.confirmTrigger(fault!, armedAt + 2_000)).toBe(false);
|
||
expect(observer.record.triggerMissed).toEqual(["result"]);
|
||
});
|
||
|
||
it("result: records a miss when the target run settled during the delay", async () => {
|
||
const state = { runs: [{ runId: "r1", status: "running" }] as Json[], issue: { id: "i1", status: "in_progress" },
|
||
events: [{ seq: 1, eventType: "run.result.proposed", createdAt: new Date().toISOString() }] as Json[] };
|
||
const observer = new TaskObserver({ ...base, trigger: "result", triggerDelayMs: 3_000 }, scriptedApi(state), lab, new Timeline(null), ready);
|
||
await observer.launch();
|
||
const start = observer.record.createdAt!;
|
||
observer.record.followUp = { at: start, postedAt: start, commentId: "c1", error: null, duringRun: true };
|
||
await observer.poll(start + 1_000);
|
||
const armedAt = observer.record.resultAcceptedAt!;
|
||
state.runs = [{ runId: "r1", status: "succeeded" }];
|
||
await observer.poll(armedAt + 1_000);
|
||
expect(observer.faultDue(armedAt + 3_000)).toBeNull();
|
||
expect(observer.record.triggerMissed).toEqual(["result"]);
|
||
});
|
||
|
||
it("result: misses when the follow-up was posted at rest", async () => {
|
||
const observer = new TaskObserver({ ...base, trigger: "result", triggerDelayMs: 0 },
|
||
scriptedApi({ runs: [], issue: { id: "i1", status: "done" } }), lab, new Timeline(null), ready);
|
||
await observer.launch();
|
||
const start = observer.record.createdAt!;
|
||
observer.record.followUp = { at: start, postedAt: start, commentId: "c1", error: null, duringRun: false };
|
||
expect(observer.faultDue(start + 1)).toBeNull();
|
||
expect(observer.record.triggerMissed).toEqual(["result"]);
|
||
});
|
||
|
||
it("records a miss instead of firing a triggered fault after its window has passed", async () => {
|
||
const observer = new TaskObserver({ ...base, workload: "B5", trigger: "tool", triggerDelayMs: 1_000 },
|
||
scriptedApi({ runs: [], issue: { id: "i1", status: "in_progress" } }), lab, new Timeline(null), ready);
|
||
await observer.launch();
|
||
const start = observer.record.createdAt!;
|
||
observer.record.benchFirstSeenAt = start;
|
||
expect(observer.faultDue(start + 1_000 + TRIGGER_LATE_MS + 1)).toBeNull();
|
||
expect(observer.record.triggerMissed).toEqual(["tool"]);
|
||
});
|
||
|
||
it("queued: misses when the run started before the fault could fire", async () => {
|
||
const state = { runs: [{ runId: "r1", status: "queued" }] as Json[], issue: { id: "i1", status: "todo" } };
|
||
const observer = new TaskObserver({ ...base, trigger: "queued", triggerDelayMs: 0 }, scriptedApi(state), lab, new Timeline(null), ready);
|
||
await observer.launch();
|
||
const start = observer.record.createdAt!;
|
||
await observer.poll(start + 10);
|
||
state.runs = [{ runId: "r1", status: "running", startedAt: new Date().toISOString() }];
|
||
await observer.poll(start + 20);
|
||
expect(observer.faultDue(start + 20)).toBeNull();
|
||
expect(observer.record.triggerMissed).toEqual(["queued"]);
|
||
});
|
||
|
||
it("keeps replayed fixed-offset faults on time while a re-armed trigger waits", async () => {
|
||
const observer = new TaskObserver({ ...base, workload: "B5", replayFaults: [
|
||
{ kind: "K1", holdMs: 0, atMs: 0, trigger: "tool", delayMs: 0 }, { kind: "K2", holdMs: 0, atMs: 5_000 }] },
|
||
scriptedApi({ runs: [], issue: { id: "i1", status: "in_progress" } }), lab, new Timeline(null), ready);
|
||
await observer.launch();
|
||
const start = observer.record.createdAt!;
|
||
expect(observer.faultDue(start + 5_000)).toEqual({ kind: "K2", holdMs: 0, atMs: 5_000 });
|
||
observer.record.benchFirstSeenAt = start + 6_000;
|
||
expect(observer.faultDue(start + 6_000)).toMatchObject({ kind: "K1", trigger: "tool" });
|
||
});
|
||
});
|
||
|
||
describe("ledger load", () => {
|
||
it("records the highest load among the task's crossing faults", () => {
|
||
const plan = { waveId: "w", seed: 1, options: { env: "local" } } as unknown as WavePlan;
|
||
const record = { plan: base, identifier: "CHA-1", issueId: "i1", retry: null } as unknown as TaskRecord;
|
||
const grade = { rules: {}, T: { verdict: "pass" }, crossed: true, crossingFaults: ["f01", "f02"], pass: true, signature: null } as unknown as TaskGrade;
|
||
const line = ledgerLine(plan, record, grade, "sha", null,
|
||
[{ faultId: "f01", loadAvg1m: 12.5 }, { faultId: "f02", loadAvg1m: 21 }, { faultId: "f03", loadAvg1m: 40 }]);
|
||
expect(line.maxLoadAvg1m).toBe(21);
|
||
expect(ledgerLine(plan, record, grade, "sha", null).maxLoadAvg1m).toBeUndefined();
|
||
});
|
||
});
|
||
|
||
describe("pre-fault files", () => {
|
||
it("checks lost files in the workspace the snapshot was taken from, and records a move", async () => {
|
||
const before = await mkdtemp(path.join(os.tmpdir(), "restart-chaos-before-"));
|
||
const after = await mkdtemp(path.join(os.tmpdir(), "restart-chaos-after-"));
|
||
try {
|
||
await writeFile(path.join(before, "kept.txt"), "x");
|
||
await writeFile(path.join(before, "other-task.txt"), "x");
|
||
const state = { runs: [] as Json[], issue: { id: "i1", status: "in_progress", currentExecutionWorkspace: { cwd: before } } as Json };
|
||
const observer = new TaskObserver({ ...base, workload: "B5" }, scriptedApi(state), lab, new Timeline(null), ready);
|
||
await observer.launch();
|
||
await observer.poll(observer.record.createdAt! + 10);
|
||
await observer.snapshotBeforeFault();
|
||
await rm(path.join(before, "other-task.txt"));
|
||
state.issue = { id: "i1", status: "done", currentExecutionWorkspace: { cwd: after } };
|
||
await observer.collectArtifacts();
|
||
expect(observer.record.lostFiles).toEqual(["other-task.txt"]);
|
||
expect(observer.record.workspaceMovedTo).toBe(after);
|
||
} finally {
|
||
await rm(before, { recursive: true, force: true });
|
||
await rm(after, { recursive: true, force: true });
|
||
}
|
||
});
|
||
});
|
||
|
||
describe("dispatch checks", () => {
|
||
it("confirmTrigger rechecks a queued run right before the kill", async () => {
|
||
const state = { runs: [{ runId: "r1", status: "queued" }] as Json[], issue: { id: "i1", status: "todo" } };
|
||
const observer = new TaskObserver({ ...base, trigger: "queued", triggerDelayMs: 0 }, scriptedApi(state), lab, new Timeline(null), ready);
|
||
await observer.launch();
|
||
const start = observer.record.createdAt!;
|
||
await observer.poll(start + 10);
|
||
const due = observer.faultDue(start + 10)!;
|
||
expect(await observer.confirmTrigger(due, start + 20)).toBe(true);
|
||
state.runs = [{ runId: "r1", status: "running", startedAt: new Date().toISOString() }];
|
||
expect(await observer.confirmTrigger(due, start + 30)).toBe(false);
|
||
expect(observer.record.triggerMissed).toEqual(["queued"]);
|
||
expect(await observer.confirmTrigger({ kind: "K1", holdMs: 0, atMs: 0 }, start)).toBe(true);
|
||
});
|
||
|
||
it("records an unreadable pre-fault workspace at rest instead of reporting every file lost", async () => {
|
||
const before = await mkdtemp(path.join(os.tmpdir(), "restart-chaos-gone-"));
|
||
await writeFile(path.join(before, "a.txt"), "x");
|
||
const state = { runs: [] as Json[], issue: { id: "i1", status: "in_progress", currentExecutionWorkspace: { cwd: before } } as Json };
|
||
const observer = new TaskObserver({ ...base, workload: "B5" }, scriptedApi(state), lab, new Timeline(null), ready);
|
||
await observer.launch();
|
||
await observer.poll(observer.record.createdAt! + 10);
|
||
await observer.snapshotBeforeFault();
|
||
await rm(before, { recursive: true, force: true });
|
||
state.issue = { id: "i1", status: "done" };
|
||
await observer.collectArtifacts();
|
||
expect(observer.record.lostFiles).toBeNull();
|
||
expect(observer.record.restSnapshotError).toMatch(/ENOENT/);
|
||
});
|
||
});
|
||
|
||
describe("R5 live evidence", () => {
|
||
const fixture = JSON.parse(readFileSync(path.join(import.meta.dirname, "fixtures/rc30-terminal-then-k2.json"), "utf8")) as { samples: TaskSample[] };
|
||
const record = (samples: TaskSample[]) => ({ samples } as unknown as TaskRecord);
|
||
|
||
it("fails a run that stays running with no event evidence after the server is ready (RC-30, w-20261106T190257-s707/t05)", () => {
|
||
expect(gradeR5(record(fixture.samples))).toMatchObject({ verdict: "fail", detail: expect.stringMatching(/^silent_dead_run b57890ae/) });
|
||
});
|
||
|
||
it("passes the same timeline while the run keeps producing events", () => {
|
||
const live = fixture.samples.map(sample => ({ ...sample,
|
||
runs: sample.runs?.map(run => ({ ...run, lastEvidenceAt: new Date(sample.at - 30_000).toISOString() })) }));
|
||
expect(gradeR5(record(live)).verdict).toBe("pass");
|
||
});
|
||
|
||
it("counts only time since the server became ready", () => {
|
||
const start = Date.parse("2026-11-06T10:00:00Z");
|
||
const run = { id: "r1", status: "running", createdAt: null, startedAt: new Date(start - 600_000).toISOString(), finishedAt: null,
|
||
errorCode: null, retryOfRunId: null, wakeCommentIds: [], livenessState: null, lastEvidenceAt: null };
|
||
const sample = (at: number, ready = true): TaskSample => ({ at, reachable: ready, serverReady: ready, issueStatus: "in_progress", runs: [run] });
|
||
expect(gradeR5(record([sample(start, false), sample(start + 1_000), sample(start + 120_000)])).verdict).toBe("pass");
|
||
expect(gradeR5(record([sample(start, false), sample(start + 1_000), sample(start + 200_000)])).verdict).toBe("fail");
|
||
});
|
||
|
||
const quietB5 = (live: { toolInFlight?: boolean; processAlive?: boolean }) => {
|
||
// A B5 run quiet for 4 minutes while bench.sh runs: no event, no activity, started long before.
|
||
const start = Date.parse("2026-11-06T10:00:00Z");
|
||
const run = { id: "r1", status: "running", createdAt: null, startedAt: new Date(start - 600_000).toISOString(), finishedAt: null,
|
||
errorCode: null, retryOfRunId: null, wakeCommentIds: [], livenessState: null, lastEvidenceAt: new Date(start).toISOString(), ...live };
|
||
return record([0, 60_000, 120_000, 180_000, 240_000].map(offset => ({ at: start + offset, reachable: true, serverReady: true,
|
||
issueStatus: "in_progress", runs: [run] })));
|
||
};
|
||
|
||
it("does not flag a quiet run whose tool is still in flight or whose process is verifiably alive (B5 quiet 4 min)", () => {
|
||
expect(gradeR5(quietB5({ toolInFlight: true })).verdict).toBe("pass");
|
||
expect(gradeR5(quietB5({ processAlive: true })).verdict).toBe("pass");
|
||
expect(gradeR5(quietB5({}))).toMatchObject({ verdict: "fail", detail: expect.stringMatching(/^silent_dead_run r1/) });
|
||
});
|
||
|
||
it("does not flag a slow model request while the provider turn is active with no tool running (w-20261115T044649-s7106/t028)", () => {
|
||
const slow = JSON.parse(readFileSync(path.join(import.meta.dirname, "fixtures/t028-slow-provider-turn.json"), "utf8")) as { samples: TaskSample[] };
|
||
const gap = slow.samples.filter(sample => sample.runs?.[0]?.lastEvidenceAt === "2026-11-15T05:22:13.005Z");
|
||
expect(gap.at(-1)!.at - gap[0]!.at).toBeGreaterThan(300_000);
|
||
expect(gap.every(sample => sample.runs![0]!.providerTurnActive && !sample.runs![0]!.toolInFlight)).toBe(true);
|
||
expect(gradeR5(record(slow.samples)).verdict).toBe("pass");
|
||
});
|
||
|
||
const quietTurn = (live: { providerTurnActive?: boolean; preparing?: boolean }, quietMs: number) => {
|
||
const start = Date.parse("2026-11-15T05:00:00Z");
|
||
const run = { id: "r1", status: "running", createdAt: null, startedAt: new Date(start - 600_000).toISOString(), finishedAt: null,
|
||
errorCode: null, retryOfRunId: null, wakeCommentIds: [], livenessState: null, lastEvidenceAt: new Date(start).toISOString(), ...live };
|
||
const offsets = Array.from({ length: Math.floor(quietMs / 30_000) + 1 }, (_, index) => index * 30_000);
|
||
return record(offsets.map(offset => ({ at: start + offset, reachable: true, serverReady: true, issueStatus: "in_progress", runs: [run] })));
|
||
};
|
||
|
||
it("still fails a silent run with no active provider turn, and a provider turn silent past the provider-latency bound", () => {
|
||
expect(gradeR5(quietTurn({}, 240_000))).toMatchObject({ verdict: "fail", detail: expect.stringMatching(/^silent_dead_run r1/) });
|
||
expect(gradeR5(quietTurn({ providerTurnActive: false }, 240_000))).toMatchObject({ verdict: "fail", detail: expect.stringMatching(/^silent_dead_run r1/) });
|
||
expect(gradeR5(quietTurn({ providerTurnActive: true }, 570_000)).verdict).toBe("pass");
|
||
expect(gradeR5(quietTurn({ providerTurnActive: true }, 630_000))).toMatchObject({ verdict: "fail",
|
||
detail: expect.stringMatching(/^silent_dead_run r1 .* for 630s/) });
|
||
});
|
||
|
||
it("does not flag a run that is still acquiring its environment before its first run event (w-20261116T001158-s7106/t010)", () => {
|
||
const slow = JSON.parse(readFileSync(path.join(import.meta.dirname, "fixtures/t010-slow-environment-acquire.json"), "utf8")) as
|
||
{ runId: string; firstRunEventAt: string; samples: TaskSample[] };
|
||
const firstEventAt = Date.parse(slow.firstRunEventAt);
|
||
const quiet = slow.samples.filter(sample => sample.at < firstEventAt);
|
||
expect(quiet.at(-1)!.at - quiet[0]!.at).toBeGreaterThan(240_000);
|
||
expect(quiet.every(sample => sample.runs!.find(run => run.id === slow.runId)!.lastEvidenceAt
|
||
=== sample.runs!.find(run => run.id === slow.runId)!.startedAt)).toBe(true);
|
||
expect(gradeR5(record(slow.samples))).toMatchObject({ verdict: "fail", detail: expect.stringMatching(/^silent_dead_run aedc1f6e/) });
|
||
const observed = slow.samples.map(sample => ({ ...sample, runs: sample.runs?.map(run =>
|
||
run.id === slow.runId && run.status === "running" && sample.at < firstEventAt ? { ...run, preparing: true } : run) }));
|
||
expect(gradeR5(record(observed)).verdict).toBe("pass");
|
||
expect(gradeU1(record(observed), DEFAULT_UNIVERSAL_BOUNDS).verdict).toBe("pass");
|
||
});
|
||
|
||
it("R5 and U1 agree on a preparing run: a 6 and 7 minute restore passes both, silence past the preparation bound fails both", () => {
|
||
for (const quietMs of [360_000, 420_000]) {
|
||
expect(gradeR5(quietTurn({ preparing: true }, quietMs)).verdict).toBe("pass");
|
||
expect(gradeU1(quietTurn({ preparing: true }, quietMs), DEFAULT_UNIVERSAL_BOUNDS).verdict).toBe("pass");
|
||
}
|
||
const pastBound = PREPARATION_LIMIT_MS + DEFAULT_UNIVERSAL_BOUNDS.orphanMs + 60_000;
|
||
expect(gradeR5(quietTurn({ preparing: true }, pastBound))).toMatchObject({ verdict: "fail", detail: expect.stringMatching(/^silent_dead_run r1/) });
|
||
expect(gradeU1(quietTurn({ preparing: true }, pastBound), DEFAULT_UNIVERSAL_BOUNDS)).toMatchObject({ verdict: "fail",
|
||
detail: expect.stringMatching(/^no_owner_no_action/) });
|
||
expect(gradeU1(quietTurn({}, 420_000), DEFAULT_UNIVERSAL_BOUNDS).verdict).toBe("fail");
|
||
});
|
||
|
||
it("still fails a run silent past the preparation bound, and a started run silent past the stall bound", () => {
|
||
expect(gradeR5(quietTurn({ preparing: true }, 570_000)).verdict).toBe("pass");
|
||
expect(gradeR5(quietTurn({ preparing: true }, 630_000))).toMatchObject({ verdict: "fail",
|
||
detail: expect.stringMatching(/^silent_dead_run r1 .* for 630s/) });
|
||
expect(gradeR5(quietTurn({ preparing: false }, 240_000))).toMatchObject({ verdict: "fail", detail: expect.stringMatching(/^silent_dead_run r1/) });
|
||
});
|
||
|
||
it("marks a running run as preparing only while its events read back empty", async () => {
|
||
const startedAt = new Date().toISOString();
|
||
const state = { runs: [{ runId: "r1", status: "running", startedAt }] as Json[], issue: { id: "i1", status: "in_progress" }, events: [] as Json[] };
|
||
const observer = new TaskObserver({ ...base, workload: "B5" }, scriptedApi(state), lab, new Timeline(null), ready);
|
||
await observer.launch();
|
||
await observer.poll(Date.now());
|
||
expect(observer.record.samples.at(-1)!.runs![0]).toMatchObject({ preparing: true });
|
||
state.events.push({ seq: 1, eventType: "lifecycle", message: "run started", payload: {}, createdAt: startedAt });
|
||
await observer.poll(Date.now() + 3_000);
|
||
expect(observer.record.samples.at(-1)!.runs![0]!.preparing).toBeUndefined();
|
||
|
||
const unread = scriptedApi({ ...state, events: [] });
|
||
const failing = { ...unread, get: async (route: string) => {
|
||
if (route.includes("/events")) throw new Error("events unavailable");
|
||
return (unread as unknown as { get(route: string): Promise<unknown> }).get(route);
|
||
} } as unknown as ChaosApi;
|
||
const blind = new TaskObserver({ ...base, workload: "B5" }, failing, lab, new Timeline(null), ready);
|
||
await blind.launch();
|
||
await blind.poll(Date.now());
|
||
expect(blind.record.samples.at(-1)!.runs![0]!.preparing).toBeUndefined();
|
||
});
|
||
|
||
it("derives tool-in-flight and process liveness from run events", async () => {
|
||
const startedAt = new Date().toISOString();
|
||
const identity = { processPid: 4242, processGroupId: 4242, processStartedAt: "2026-11-06T10:00:00.000Z", targetKind: "local" };
|
||
const state = { runs: [{ runId: "r1", status: "running", startedAt }] as Json[], issue: { id: "i1", status: "in_progress" },
|
||
events: [{ seq: 1, eventType: "native.process_identity_recorded", payload: identity, createdAt: startedAt },
|
||
{ seq: 2, eventType: "tool.execution.started", payload: {}, createdAt: startedAt }] as Json[] };
|
||
const observer = new TaskObserver({ ...base, workload: "B5" }, scriptedApi(state), lab, new Timeline(null), ready);
|
||
const checked: Array<[number, string]> = [];
|
||
observer.processAlive = (pid, at) => { checked.push([pid, at]); return true; };
|
||
await observer.launch();
|
||
await observer.poll(Date.now());
|
||
expect(observer.record.samples.at(-1)!.runs![0]).toMatchObject({ toolInFlight: true, processAlive: true });
|
||
expect(checked).toEqual([[4242, "2026-11-06T10:00:00.000Z"]]);
|
||
state.events.push({ seq: 3, eventType: "tool.execution.completed", payload: {}, createdAt: startedAt },
|
||
{ seq: 4, eventType: "native.local_process_stopped", payload: { processPid: 4242 }, createdAt: startedAt });
|
||
await observer.poll(Date.now() + 3_000);
|
||
const latest = observer.record.samples.at(-1)!.runs![0]!;
|
||
expect(latest.toolInFlight).toBeUndefined();
|
||
expect(latest.processAlive).toBeUndefined();
|
||
});
|
||
|
||
it("drops tool liveness when the runner that owned the tool stops or is replaced", () => {
|
||
const cursor = { seq: 0, lastAt: null, openTools: 0, process: null as { pid: number; startedAt: string } | null };
|
||
const identity = (pid: number) => ({ eventType: "native.process_identity_recorded",
|
||
payload: { processPid: pid, processStartedAt: "2026-11-06T10:00:00.000Z", targetKind: "local" } });
|
||
noteLivenessEvent(cursor, identity(10));
|
||
noteLivenessEvent(cursor, { eventType: "tool.execution.started", payload: {} });
|
||
expect(cursor.openTools).toBe(1);
|
||
// A fault killed the runner mid-tool: the tool can never report its end.
|
||
noteLivenessEvent(cursor, { eventType: "native.local_process_stopped", payload: { processPid: 10 } });
|
||
expect(cursor).toMatchObject({ openTools: 0, process: null });
|
||
noteLivenessEvent(cursor, identity(11));
|
||
noteLivenessEvent(cursor, { eventType: "tool.execution.started", payload: {} });
|
||
// A replacement runner recorded without a stop event still resets the count.
|
||
noteLivenessEvent(cursor, identity(12));
|
||
expect(cursor).toMatchObject({ openTools: 0, process: { pid: 12 } });
|
||
});
|
||
|
||
it("records a due trigger the wave skipped as missed", async () => {
|
||
const observer = new TaskObserver({ ...base, workload: "C1", trigger: "result", triggerDelayMs: 0 },
|
||
scriptedApi({ runs: [], issue: { id: "i1", status: "in_progress" } }), lab, new Timeline(null), ready);
|
||
observer.markTriggerMissed({ kind: "K1", holdMs: 0, atMs: 0, trigger: "result", delayMs: 0 });
|
||
observer.markTriggerMissed({ kind: "K2", holdMs: 0, atMs: 0 });
|
||
expect(observer.record.triggerMissed).toEqual(["result"]);
|
||
});
|
||
|
||
it.skipIf(process.platform === "win32")("checks a local process by PID and start time, so a recycled PID is not alive", () => {
|
||
const lstart = spawnSync("ps", ["-o", "lstart=", "-p", String(process.pid)], { encoding: "utf8", env: { PATH: "/usr/bin:/bin", LANG: "C", LC_ALL: "C" } }).stdout.trim();
|
||
const startedAt = new Date(Date.parse(lstart)).toISOString();
|
||
expect(localProcessAlive(process.pid, startedAt)).toBe(true);
|
||
expect(localProcessAlive(process.pid, new Date(Date.parse(lstart) - 60_000).toISOString())).toBe(false);
|
||
});
|
||
|
||
it("keeps the latest evidence timestamp", () => {
|
||
expect(latestIso([null, "2026-11-06T10:00:00Z", "2026-11-06T09:00:00Z", "bad"])).toBe("2026-11-06T10:00:00.000Z");
|
||
expect(latestIso([undefined])).toBeNull();
|
||
});
|
||
});
|
||
|
||
describe("socket race", () => {
|
||
it("matches only the undici setTypeOfService EINVAL race", () => {
|
||
expect(isSocketTypeOfServiceRace(Object.assign(new Error("setTypeOfService EINVAL"), { code: "EINVAL", syscall: "setTypeOfService" }))).toBe(true);
|
||
expect(isSocketTypeOfServiceRace(Object.assign(new Error("x"), { code: "EINVAL", syscall: "write" }))).toBe(false);
|
||
expect(isSocketTypeOfServiceRace(null)).toBe(false);
|
||
});
|
||
});
|
||
|
||
describe("timeline", () => {
|
||
it("keeps the event kind when event data has a kind field", () => {
|
||
expect(new Timeline(null).add("fault_started", { kind: "K1" }).kind).toBe("fault_started");
|
||
});
|
||
});
|
||
|
||
describe("K6 crash loop", () => {
|
||
it("kills in recovering (or ready when recovering was skipped), then just after ready", () => {
|
||
expect(crashLoopShouldFire("recovering", "starting")).toBe(false);
|
||
expect(crashLoopShouldFire("recovering", "unreachable")).toBe(false);
|
||
expect(crashLoopShouldFire("recovering", "recovering")).toBe(true);
|
||
expect(crashLoopShouldFire("recovering", "ready")).toBe(true);
|
||
expect(crashLoopShouldFire("ready", "recovering")).toBe(false);
|
||
expect(crashLoopShouldFire("ready", "ready")).toBe(true);
|
||
});
|
||
});
|