mirror of
https://github.com/paperclipai/paperclip.git
synced 2026-11-23 13:13:46 +01:00
## Thinking Path
> - Paperclip is the open source app people use to manage AI agents for
work.
> - The restart-chaos harness grades release swaps. One rule,
`MS_double_executor`, flags a run that records a second runner identity
before the first one is shown stopped.
> - The server records stop evidence (`native.local_process_stopped`)
only for local processes. It never records it for a sandbox
(`targetKind: "remote"`) process.
> - So when a sandbox run relaunches its runner inside the same run (a
session retry after a reconnect), the grader counts each new sandbox PID
as a second executor. Sandbox PIDs are also in a different PID space
from the server.
> - In a 197-task wave, run `c5b1f8ae` (a Daytona run that retried its
session after a reconnect) was reported as 2 double executors. The
runner journal shows the first turn was stopped with
`providerExitConfirmed: true` before the relaunch, so nothing ran twice.
> - This pull request makes the rule grade only local identities, as
`SCENARIOS.md` already describes it ("a second local runner identity").
> - The benefit is that the duplicate count in release-swap results
shows only real duplicates.
## Linked Issues or Issue Description
**What happened?**
The release-swap grade reported "2 double executor(s)" for one Daytona
run whose session retried in the same run. The previous provider process
had confirmed exit. No two processes ran together.
**Expected behavior**
`MS_double_executor` charges only local runner identities. A sandbox
relaunch is not a double executor.
**Steps to reproduce**
1. Run a restart-chaos wave on Daytona.
2. Have one run retry its native session in the same run (a reconnect).
3. Read `release-swap-summary.md`. The run appears under double
executors once per relaunch.
**Paperclip version or commit**
`master` at 1c67687998.
## What Changed
- `tests/restart-chaos/multi-server.ts`: reads `payload.targetKind` for
runner identity events and skips `remote` identities in
`MS_double_executor`.
- `tests/restart-chaos/multi-server.test.ts`: adds a red/green test with
three sandbox relaunches of one run.
- `tests/restart-chaos/SCENARIOS.md`: states that sandbox identities are
not graded, and why.
## Verification
- Red: without the filter, the new test fails (2 violations for 3 remote
identities).
- Green: `npx vitest run --config tests/restart-chaos/vitest.config.ts
tests/restart-chaos/multi-server.test.ts` passes (16 tests).
- `tsc -p tests/restart-chaos/tsconfig.json` shows no errors in the
changed files.
## Risks
- Low risk. Harness only; no product code.
- A real double executor inside a sandbox is not caught by this rule. It
was never reliably caught before: no remote stop evidence exists, so
every remote relaunch was flagged. Sandbox ownership stays graded by the
Runner checkpoint owner checks.
## Model Used
- Claude Opus 5.5 (`claude-opus-5-5`), Anthropic, via Claude Code with
tool use (shell, file edit). Extended reasoning on.
## 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>
63 lines
4.8 KiB
TypeScript
63 lines
4.8 KiB
TypeScript
import { afterAll, beforeAll, describe, expect, it } from "vitest";
|
|
import { createDb, type Db } from "../../packages/db/src/index.js";
|
|
import { getEmbeddedPostgresTestSupport, startEmbeddedPostgresTestDatabase } from "../../packages/db/src/test-embedded-postgres.js";
|
|
import { checkCrossServer, readCrossServerEvidence, type ServerProcessWindow } from "./multi-server.js";
|
|
|
|
const support = await getEmbeddedPostgresTestSupport();
|
|
const COMPANY = "00000000-0000-4000-8000-000000000001";
|
|
const NOON = Date.parse("2026-11-10T12:00:00.000Z");
|
|
const iso = (ms: number) => new Date(ms).toISOString();
|
|
|
|
describe.skipIf(!support.supported)("reading cross-server evidence from a wave database", () => {
|
|
let temporary: Awaited<ReturnType<typeof startEmbeddedPostgresTestDatabase>>;
|
|
let db: Db;
|
|
|
|
beforeAll(async () => {
|
|
temporary = await startEmbeddedPostgresTestDatabase("chaos-ms-");
|
|
db = createDb(temporary.connectionString, { maxConnections: 1 });
|
|
// Only the columns the reader selects, with the product's names and types, in a schema ahead of the
|
|
// migrated one (one connection, so the search path holds for every query).
|
|
await db.$client.unsafe(`create schema chaos_ms`);
|
|
await db.$client.unsafe(`set search_path to chaos_ms, public`);
|
|
await db.$client.unsafe(`create table heartbeat_runs (id uuid primary key, company_id uuid not null, issue_id uuid, status text not null,
|
|
error_code text, finished_at timestamptz, updated_at timestamptz not null, controller_boot_id uuid)`);
|
|
await db.$client.unsafe(`create table native_run_finalizations (run_id uuid primary key, controller_boot_id text, lease_holder jsonb)`);
|
|
await db.$client.unsafe(`create table controller_instances (boot_id text primary key, pid integer not null)`);
|
|
await db.$client.unsafe(`create table heartbeat_run_events (run_id uuid not null, event_type text not null, payload jsonb, created_at timestamptz not null)`);
|
|
await db.$client.unsafe(`insert into controller_instances values ('boot-a', 100), ('boot-b', 200)`);
|
|
// #20508's marker: still running, with the ownership code, written by another server's sweep.
|
|
await db.$client.unsafe(`insert into heartbeat_runs values ('00000000-0000-4000-8000-0000000000a1', $1, null, 'running',
|
|
'native_execution_ownership_unverified', null, $2, null)`, [COMPANY, iso(NOON)]);
|
|
await db.$client.unsafe(`insert into native_run_finalizations values ('00000000-0000-4000-8000-0000000000a1', 'boot-a', null)`);
|
|
// An ordinary success: not read as a failure.
|
|
await db.$client.unsafe(`insert into heartbeat_runs values ('00000000-0000-4000-8000-0000000000a2', $1, null, 'succeeded', null, $2, $2, null)`, [COMPANY, iso(NOON)]);
|
|
await db.$client.unsafe(`insert into heartbeat_run_events values ('00000000-0000-4000-8000-0000000000a2', 'native.process_identity_recorded', '{"processPid": 11}', $1),
|
|
('00000000-0000-4000-8000-0000000000a2', 'native.process_identity_recorded', '{"processPid": 12}', $2)`, [iso(NOON - 2_000), iso(NOON - 1_000)]);
|
|
await db.$client.unsafe(`insert into heartbeat_runs values ('00000000-0000-4000-8000-0000000000a3', $1, null, 'succeeded', null, $2, $2, null)`, [COMPANY, iso(NOON)]);
|
|
await db.$client.unsafe(`insert into heartbeat_run_events values ('00000000-0000-4000-8000-0000000000a3', 'native.process_identity_recorded', '{"processPid": 21, "targetKind": "remote"}', $1),
|
|
('00000000-0000-4000-8000-0000000000a3', 'native.process_identity_recorded', '{"processPid": 22, "targetKind": "remote"}', $2)`, [iso(NOON - 2_000), iso(NOON - 1_000)]);
|
|
}, 120_000);
|
|
|
|
afterAll(async () => {
|
|
await db?.$client.end();
|
|
await temporary?.cleanup();
|
|
});
|
|
|
|
it("reads a running run that carries the ownership marker, at its write time, and charges it to a live owner", async () => {
|
|
const evidence = await readCrossServerEvidence(db, COMPANY);
|
|
expect(evidence.runs).toEqual([expect.objectContaining({ runId: "00000000-0000-4000-8000-0000000000a1", status: "running",
|
|
errorCode: "native_execution_ownership_unverified", endedAt: NOON, ownerBootId: "boot-a", ownerPid: 100 })]);
|
|
expect(evidence.events.map(event => event.pid)).toEqual(expect.arrayContaining([11, 12]));
|
|
expect(evidence.events.filter(event => event.runId.endsWith("a3")).map(event => event.targetKind)).toEqual(["remote", "remote"]);
|
|
const windows: ServerProcessWindow[] = [
|
|
{ pid: 100, role: "primary", spawnedAt: NOON - 60_000, exitedAt: null, frozen: [{ from: NOON - 50_000, to: NOON - 5_000 }] },
|
|
{ pid: 200, role: "secondary", spawnedAt: NOON - 55_000, exitedAt: null, frozen: [] },
|
|
];
|
|
const check = checkCrossServer({ ...evidence, windows });
|
|
expect(check.violations.map(violation => [violation.rule, violation.runId])).toEqual([
|
|
["MS_foreign_failure", "00000000-0000-4000-8000-0000000000a1"],
|
|
["MS_double_executor", "00000000-0000-4000-8000-0000000000a2"],
|
|
]);
|
|
});
|
|
});
|