Files
PaperClipAI/tests/runner-e2e/chat-catalog-domains/runtime-native-fault.ts
T
f4337bb5fb test(evals): land the chat catalog eval harness on master (#19614)
## Thinking Path

> - Paperclip is the open source app people use to manage AI agents for
work
> - The chat-feature evals measure whether agents complete real chat
requests through the product
> - The chat catalog eval harness and its repairs live on the
`chat-eval/master-candidate` branch, not on master
> - Today's work made 139 of 242 chat evals pass in verified single-case
live runs. Each product fix landed on master as its own pull request
> - The eval-side changes (setups, graders, fault seams, evidence
capture) still exist only on the candidate
> - This pull request lands the harness on master. Master stays the
source of truth for product behavior
> - The benefit is one tree: evals run against master commits, and
product fixes reach the evals as soon as they merge

## Linked Issues or Issue Description

Refs #19441, Refs #19599, Refs #20270, Refs #20334, Refs #20342, Refs
#20344, Refs #20354, Refs #20360, Refs #20373, Refs #20382, Refs #20409

**What existing behavior does this improve?**
The chat catalog eval harness and the product it evaluates live on a
long-running branch outside master. Eval fixes do not reach master, so
master-based eval runs use old setups and graders.

**Subsystem affected**
`tests/runner-e2e` chat catalog harness, plus a small set of product
changes that exist only on the candidate.

**Proposed change**
Land the harness on master. Every product fix from this eval work
already merged to master as its own pull request. Conflicts keep
master's product behavior.

## What Changed

- Most of the diff (808 of 851 files) is under `tests/runner-e2e/`:
chat-catalog domains, scenarios, descriptors, the TestOps manifest,
private evidence tooling, and their tests.
- Graders now check saved state, setup literals and rendered or clicked
links. Many keyword and regex checks on free-form replies are removed.
Each changed grader has a bumped `oracleVersion` and calibration tests
(a valid reply, a reworded valid reply, and broken variants that must
fail).
- The shared link helper `hasLink` no longer treats a list link (for
example `/COM/issues?view=mine`) as a link to every task without a URL
key.
- Setup fixes build real state through supported product routes: routine
history, agent grants through the board grant route, budget holds with a
real cap, and a storage-layer archive fault for
`inbox-search.archive-partial-failure`.
- Browser boundary journeys (sign-in, chat-disabled, onboarding) now
write the standard pass evidence files.
- Retargeted cases, approved by the maintainer:
`agent-chat.chat-disabled` (Conference Room gate),
`agents.restore-instructions` (no saved instruction history),
`access.manage-membership` (member permission edits stay board-only).
- The private evidence trusted files (`manual-private-handoff.ts`,
`manual-private-retention.ts`, `manual-private-report-assets.ts`) are
byte-identical to master.
- Product files outside `tests/` (43 files, +1,328 −49) carry
candidate-only changes that master does not yet have. Most are tests.
The main code changes are in `request-human-input.ts`,
`heartbeat-run-summary.ts`, `native-completion-feedback.ts`,
`native-run-finalizer.ts`, `openapi.ts`, `secrets.ts` and
`IssueChatLongThreadPerf.tsx`.

## Verification

- `pnpm vitest run chat-catalog-domains chat-catalog-contract.test.ts
chat-catalog-consistency.test.ts unit-launcher.test.mjs
--testTimeout=180000` in `tests/runner-e2e`: 269 files pass, 3,550 tests
pass.
- `node --test chat-full-catalog-testops-manifest.test.mjs`: 10 pass.
- `node tests/runner-e2e/source-sdk-public-inputs.mjs <HEAD> --check`:
no change.
- `tsc` for `server` and `tests/runner-e2e`: clean.
- Live single-case verification: 139 of 242 cases passed on paid runs,
and a person read the saved evidence for each. These are single-case
runs, not one full-cohort run.

## Risks

- Large diff. Most of it is test-only, but the 43 non-test files change
product code paths. Review those files first.
- Some graders are now less strict on reply wording. A person must read
replies for meaning on those cases.
- 42 cases need disposable outside accounts (Notion, Slack, GitHub,
Daytona and others) and stay blocked. `access.invite-teammate` stays
failing until local agent isolation lands, because the runner's durable
state keeps a live invite token.
- The paid workflow compares the trusted private-evidence files with
master. They are unchanged, so this risk is low.

## Model Used

Anthropic Claude Opus 5.5 (`claude-opus-5-5`), with tool use and code
execution, in Claude Code. Subagents used the same model.

## 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>
Co-authored-by: Paperclip <noreply@paperclip.ing>
2026-11-10 08:02:11 -06:00

109 lines
10 KiB
TypeScript

import { execFile } from "node:child_process";
import { promisify } from "node:util";
import path from "node:path";
import { realpath } from "node:fs/promises";
import type { heartbeatRuns } from "../../../packages/db/src/schema/heartbeat_runs.js";
import type { HeartbeatRun } from "../../../packages/shared/src/types/heartbeat.js";
import type { ChatCatalogContext } from "../chat-catalog-contract.js";
import { readProcessStartedAt } from "../../../server/src/services/hot-restart.js";
import { defaultCapabilityRunnerdBinary } from "../../../server/src/vendor/paperclip-runner/index.js";
import { pollUntil } from "../api.js";
import { collectRunEvents } from "../run-observations.js";
// The public full-run route selects these persisted native fields; the legacy
// shared HeartbeatRun DTO does not yet declare them. Keep this exact projection.
export type NativeFaultRun = HeartbeatRun & Pick<typeof heartbeatRuns.$inferSelect, "runtimeMode" | "nativeIssueId" | "runnerInstanceId" | "nativePhase" | "nativeSessionId" | "runnerProfileJson">;
export type NativeFaultBinding = Pick<NativeFaultRun, "id" | "companyId" | "agentId" | "status" | "runtimeMode" | "nativeIssueId" | "runnerInstanceId" | "processPid" | "processGroupId" | "processStartedAt">;
export interface OwnedNativeIdentity {
pid: number; uid: number; group: number; startedAt: string; executable: string; commandRunId: string; commandRunnerId: string; runtimeRoot: string;
}
export function matchesOwnedNativeIdentity(input: { identity: OwnedNativeIdentity; run: NativeFaultBinding;
expected: { companyId: string; agentId: string; issueId: string; uid: number; executable: string; root: string } }) {
const { identity: p, run, expected: e } = input;
return run.status === "running" && run.runtimeMode === "native" && run.companyId === e.companyId && run.agentId === e.agentId && run.nativeIssueId === e.issueId
&& Number.isSafeInteger(p.pid) && p.pid > 1 && p.pid !== process.pid && p.pid === run.processPid && p.group === run.processGroupId
&& p.uid === e.uid && p.commandRunId === run.id && p.commandRunnerId === run.runnerInstanceId
&& p.executable === e.executable && path.isAbsolute(p.runtimeRoot) && p.runtimeRoot.startsWith(`${e.root}${path.sep}`) && path.resolve(p.runtimeRoot) === p.runtimeRoot
&& !!run.processStartedAt && Number.isFinite(Date.parse(p.startedAt)) && Math.abs(Date.parse(p.startedAt) - Date.parse(String(run.processStartedAt))) < 2_000;
}
export function ownedNativeExecutablePath(pid: number, command: string, platform: NodeJS.Platform = process.platform) {
if (!Number.isSafeInteger(pid) || pid <= 1 || pid === process.pid) throw new Error("Executable identity requires an owned process candidate");
if (platform === "linux") return `/proc/${pid}/exe`;
if (platform === "darwin" && path.isAbsolute(command)) return command;
throw new Error("Owned executable identity is unavailable on this platform");
}
async function processIdentity(run: NativeFaultRun): Promise<OwnedNativeIdentity> {
const pid = run.processPid;
if (!Number.isSafeInteger(pid) || !pid || pid <= 1) throw new Error("Native infrastructure fault lacks an actual public process identity");
const read = async (field: string) => (await promisify(execFile)("/bin/ps", ["-p", String(pid), "-o", `${field}=`], { maxBuffer: 65_536, timeout: 5_000 })).stdout.trim();
try {
const [uid, group, executable, command, startedAt] = await Promise.all([read("uid"), read("pgid"), read("comm"), read("args"), readProcessStartedAt(pid)]);
if (!startedAt) throw new Error("missing process start");
// Source buildNativeRunnerArguments has exactly these finite identity flags.
// Never retain or print the complete command line or transport URL.
const argument = (name: string) => {
const matches = [...command.matchAll(new RegExp(`(?:^|\\s)--${name}\\s+([^\\s]+)(?=\\s|$)`, "g"))];
if (matches.length !== 1) throw new Error("ambiguous process argument identity");
return matches[0]![1]!;
};
return { pid, uid: Number(uid), group: Number(group), startedAt, executable: await realpath(ownedNativeExecutablePath(pid, executable)), commandRunId: argument("run-id"), commandRunnerId: argument("runner-id"), runtimeRoot: await realpath(argument("state-dir")) };
} catch { throw new Error("Native infrastructure fault could not independently verify the actual process; private diagnostics withheld"); }
}
/** Codes the product records for a lost Runner, or for its cleanup quarantine. */
export const NATIVE_INFRASTRUCTURE_FAULT_CODES = ["native_runner_process_exited", "native_session_interrupted", "native_session_retry_exhausted", "provider_transport_failed",
"provider_stdout_closed", "provider_process_output_closed", "native_session_cleanup_quarantined"];
/** The infrastructure fault code a run's own failure events name (the failed attempt's error, turn or session failure). */
export function retainedFaultCode(events: readonly Record<string, unknown>[]): string | null {
for (const row of events) {
if (!["error", "turn.failed", "session.failed"].includes(String(row.eventType))) continue;
const payload = (row.payload ?? {}) as Record<string, any>, prp = (payload.prpEvent?.payload ?? {}) as Record<string, any>;
const messages = [row.message, payload.error?.message, prp.message, prp.error?.message].filter((value): value is string => typeof value === "string");
const code = NATIVE_INFRASTRUCTURE_FAULT_CODES.find(candidate => messages.some(message => new RegExp(`(?:^|[\\s:])${candidate}(?::|$)`).test(message)));
if (code) return code;
}
return null;
}
/** `failed` once the run settled failed; `resumed` once a new Runner process serves the same run. */
export function nativeFaultOutcome(run: Pick<NativeFaultRun, "status" | "finishedAt" | "errorCode" | "processPid">, killedPid: number): "failed" | "resumed" | null {
if (run.status === "failed" && !!run.finishedAt && !!run.errorCode) return "failed";
if (run.status === "running" && !!run.processPid && run.processPid !== killedPid) return "resumed";
return null;
}
/** Authoring primitive only: this function is invoked solely inside the coordinator's selected live attempt. */
export async function verifyOwnedNativeRunner(ctx: ChatCatalogContext, binding: { runId: string; issueId: string; agentId: string }) {
if (ctx.input.execution.environment.id !== "local" || typeof process.getuid !== "function") throw new Error("Owned infrastructure fault requires a supported local UID/process identity");
const isolated = process.env.PAPERCLIP_RUNNER_E2E_TEMP_ROOT; if (!isolated) throw new Error("Owned infrastructure fault requires the explicit isolated attempt root");
const expected = { companyId: ctx.input.fixtures.company.id, agentId: binding.agentId, issueId: binding.issueId, uid: process.getuid(), executable: await realpath(defaultCapabilityRunnerdBinary()), root: await realpath(isolated) };
const load = () => ctx.input.api.get<NativeFaultRun>(`/api/heartbeat-runs/${binding.runId}`);
const first = await load(), observed = await processIdentity(first);
if (!matchesOwnedNativeIdentity({ identity: observed, run: first, expected })) throw new Error("Owned infrastructure fault rejected a foreign or mismatched native process identity");
const current = await load(), confirmed = await processIdentity(current);
if (!matchesOwnedNativeIdentity({ identity: confirmed, run: current, expected }) || JSON.stringify(confirmed) !== JSON.stringify(observed)) throw new Error("Owned infrastructure fault rejected process reuse or changed ownership");
return { run: current, identity: confirmed };
}
export async function faultOwnedNativeProcess(ctx: ChatCatalogContext, binding: { runId: string; issueId: string; agentId: string }) {
const { run: current, identity: confirmed } = await verifyOwnedNativeRunner(ctx, binding);
const load = () => ctx.input.api.get<NativeFaultRun>(`/api/heartbeat-runs/${binding.runId}`);
// Deliberately signal only the verified Runner PID. Its provider/tools remain
// subject to the production cleanup/quarantine rules; never signal a group.
process.kill(confirmed.pid, "SIGKILL");
await ctx.input.evidence("runtime-owned-native-process-fault.json", { runId: current.id, companyId: current.companyId, agentId: current.agentId,
issueId: current.nativeIssueId, runnerInstanceId: current.runnerInstanceId, processPid: confirmed.pid, processGroupId: confirmed.group, processStartedAt: confirmed.startedAt,
uidMatches: true, executableMatches: true, runtimeRootWithinAttempt: true, identityReadTwice: true, signal: "SIGKILL", processGroupSignalled: false });
// The product settles a lost Runner either as a failed run or, when its
// bounded same-run recovery applies, by relaunching a new Runner for the same
// run. Both are the product's own record; the cause is read from it.
const settled = await pollUntil({ label: "Real owned native infrastructure outcome after verified Runner process loss", deadlineAt: Date.now() + 150_000,
load, accept: run => nativeFaultOutcome(run, confirmed.pid) !== null,
reject: run => ["cancelled", "succeeded", "timed_out"].includes(run.status) ? "The real process fault did not produce a failed or resumed native infrastructure run" : undefined });
const outcome = nativeFaultOutcome(settled, confirmed.pid)!;
// Same-run recovery clears the current row's cause; the attempt's own failure events retain it.
const errorCode = outcome === "failed" ? settled.errorCode : settled.execution?.cause
?? retainedFaultCode(await collectRunEvents<Record<string, unknown>>(afterSeq => ctx.input.api.get(`/api/heartbeat-runs/${settled.id}/events?afterSeq=${afterSeq}&limit=1000`)));
await ctx.input.evidence("runtime-owned-native-process-failure.json", { runId: settled.id, status: settled.status, outcome, errorCode, finishedAt: settled.finishedAt,
nativePhase: settled.nativePhase ?? null, execution: settled.execution ?? null });
if (!NATIVE_INFRASTRUCTURE_FAULT_CODES.includes(errorCode ?? ""))
throw new Error(`The owned process fault did not retain a source-qualified infrastructure/cleanup failure (recorded ${String(errorCode).slice(0, 80)}); actual classification is not relabelled`);
const failed = { ...settled, errorCode } as NativeFaultRun;
return failed;
}