Files
PaperClipAI/tests/runner-e2e/chat-remote-campaign.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

159 lines
15 KiB
TypeScript

import { createHash } from "node:crypto";
import { completeCampaignAttempt, reserveCampaignAttempt, type CampaignAttempt, type ChatCampaign } from "./chat-campaign.js";
import { databaseIdentityMatches, POSTGRES_AMD64_IMAGE, POSTGRES_AMD64_IMAGE_IDS, POSTGRES_VERSION, type DatabaseFingerprintIdentity } from "./docker-postgres.js";
import { CHAT_OPENCODE_MODEL, CHAT_OPENCODE_PROFILE } from "./chat-runtime-profile.js";
import type { RunnerE2EResult } from "./types.js";
const sha = (bytes: string) => createHash("sha256").update(bytes).digest("hex");
const hex = (value: unknown): value is string => typeof value === "string" && /^[a-f0-9]{64}$/.test(value);
function requireProof(condition: unknown, message: string): asserts condition { if (!condition) throw new Error(`Remote import: ${message}`); }
export interface RemoteCellIntent {
campaignId: string; sourceRevision: string;
/** Absent on preserved strict-Spot intents. Only new explicit user-authorized sources opt in. */
hostPolicy?: "aws-fleet-spot-or-on-demand";
/** Explicit new lane selection; absent preserves historical Docker-only intents. */
databaseLane?: DatabaseFingerprintIdentity;
selected: Array<{ scenarioId: string; executionId: string; remoteOrdinal: 1 | 2 }>;
}
/** Obtained by the coordinator through authenticated Actions run/artifact APIs, not from
* files inside an untrusted archive. A reporting job's conclusion is deliberately absent. */
export interface RemoteArtifactProvenance {
repository: "paperclipai/paperclip"; workflow: "runner-full-stack-e2e.yml"; workflowRef: "refs/heads/master";
runId: string; runAttempt: number; artifactId: string; archiveSha256: string;
targetSourceRevision: string;
}
export interface RemoteArtifactDocument { path: string; bytes: string; sha256: string }
export interface ValidatedRemoteCell {
schema: "paperclip.chat-remote-cell-import/v1";
intentCampaignId: string; importKey: string; measurementKey: string; artifactSha256: string;
scenarioId: string; ordinal: 1 | 2; sourceRevision: string;
resultPath: string; resultSha256: string; hostSha256: string; definitionSha256: string;
result: RunnerE2EResult; definitionDigest: string; graderDigest: string;
hostLifecycle: "spot" | "on-demand"; hostPolicy: "spot-only" | "aws-fleet-spot-or-on-demand";
databaseLane: DatabaseFingerprintIdentity;
}
function document(value: RemoteArtifactDocument): Record<string, any> {
requireProof(value.path.startsWith("tests/runner-e2e/results/") && !value.path.split("/").includes("..") && !value.path.includes("\\"), "non-retained artifact path");
requireProof(hex(value.sha256) && sha(value.bytes) === value.sha256, "artifact document bytes changed");
const parsed = JSON.parse(value.bytes);
requireProof(parsed && typeof parsed === "object" && !Array.isArray(parsed), "invalid artifact document");
return parsed;
}
/** Validates measured cell facts only. Final pass qualification still uses the existing
* product/build/native, definition replay, privacy and cleanup campaign gates below. */
export function validateRemoteCell(input: {
intent: RemoteCellIntent; provenance: RemoteArtifactProvenance;
result: RemoteArtifactDocument; host: RemoteArtifactDocument; definition: RemoteArtifactDocument;
}): ValidatedRemoteCell {
const { intent, provenance: p } = input;
requireProof(!!intent.campaignId.trim(), "missing new campaign identity");
requireProof(p.repository === "paperclipai/paperclip" && p.workflow === "runner-full-stack-e2e.yml" && p.workflowRef === "refs/heads/master", "foreign workflow");
requireProof(/^\d+$/.test(p.runId) && p.runAttempt === 1 && /^\d+$/.test(p.artifactId) && hex(p.archiveSha256), "missing artifact identity or unreviewed job rerun");
requireProof(/^[a-f0-9]{40}$/.test(intent.sourceRevision) && p.targetSourceRevision === intent.sourceRevision, "target source mismatch");
const result = document(input.result) as RunnerE2EResult, host = document(input.host), definition = document(input.definition);
const selected = intent.selected.filter(row => row.executionId === result.executionId);
requireProof(selected.length === 1, "execution not uniquely selected");
const selection = selected[0]!;
requireProof([1, 2].includes(selection.remoteOrdinal) && result.attempt === 1, "automatic retry or invalid remote ordinal");
requireProof(result.schema === "paperclip.runner-e2e.result/v2" && ["passed", "failed"].includes(result.status), "missing terminal cell result");
requireProof(result.profileId === CHAT_OPENCODE_PROFILE && result.provider === "opencode" && result.model === CHAT_OPENCODE_MODEL && result.environmentId === "local", "provider/model/profile mismatch");
requireProof(result.source?.sha === intent.sourceRevision && result.source.workflowRunUrl === `https://github.com/paperclipai/paperclip/actions/runs/${p.runId}`, "result source/run mismatch");
requireProof(!!result.accountingIdentity?.campaignId && /^[a-f0-9]{32}$/.test(result.accountingIdentity?.attemptId ?? ""), "missing actual framework accounting identity");
requireProof(Number.isFinite(Date.parse(result.startedAt)) && Date.parse(result.finishedAt) >= Date.parse(result.startedAt) && Number.isFinite(result.durationMs) && result.durationMs >= 0, "invalid actual timing");
const normalFleet = intent.hostPolicy === "aws-fleet-spot-or-on-demand";
const allowedHost = normalFleet ? host.hostPolicy === intent.hostPolicy && ["spot", "on-demand"].includes(host.lifecycle)
&& host.spotVerified === (host.lifecycle === "spot") : host.lifecycle === "spot" && host.spotVerified === true;
requireProof(intent.hostPolicy === undefined || normalFleet, "unknown host policy");
requireProof(host.schema === "paperclip.chat-remote-host/v1" && host.status === "qualified-host-only" && host.scope === "before-evaluation" && host.evaluationAdmitted === false
&& allowedHost && host.architecture === "x86_64" && host.region === "us-east-1", "host not qualified for explicit intent policy");
requireProof(host.workflowRef === "paperclipai/paperclip/.github/workflows/runner-full-stack-e2e.yml@refs/heads/master"
&& host.workflowRunId === p.runId && host.workflowAttempt === p.runAttempt && host.sourceRevision === intent.sourceRevision
&& Array.isArray(host.executionIds) && host.executionIds.includes(result.executionId) && host.automaticRetries === 0, "host/result provenance mismatch");
let databaseLane: DatabaseFingerprintIdentity;
if (intent.databaseLane?.lane === "embedded-postgres") {
requireProof(host.databaseLane === "embedded-postgres" && host.postgres === undefined && host.dockerEngineSha256 === undefined, "host database lane mismatch");
databaseLane = intent.databaseLane;
requireProof(databaseIdentityMatches(databaseLane, result.databaseIdentity), "cell database identity mismatch");
} else {
requireProof(host.databaseLane === undefined || host.databaseLane === "owned-docker-postgres", "host database lane mismatch");
requireProof(hex(host.dockerEngineSha256) && host.postgres?.image === POSTGRES_AMD64_IMAGE && POSTGRES_AMD64_IMAGE_IDS.includes(host.postgres?.imageId) && host.postgres.architecture === "amd64" && host.postgres.version === POSTGRES_VERSION, "foreign database artifact");
databaseLane = { lane: "owned-docker-postgres", image: host.postgres.image, imageId: host.postgres.imageId, version: host.postgres.version, architecture: "amd64" };
requireProof(!intent.databaseLane || databaseIdentityMatches(intent.databaseLane, result.databaseIdentity), "intent database lane mismatch");
requireProof(databaseIdentityMatches(databaseLane, result.databaseIdentity) && result.databaseIdentity?.engineSha256 === host.dockerEngineSha256, "cell database identity mismatch");
}
requireProof(definition.scenarioId === selection.scenarioId && hex(definition.definitionDigest) && hex(definition.graderDigest)
&& definition.suiteDefinitionHash === result.suiteDefinitionHash && hex(result.suiteDefinitionHash), "definition/result mismatch");
return { schema: "paperclip.chat-remote-cell-import/v1", intentCampaignId: intent.campaignId, importKey: `${p.runId}/${p.runAttempt}/${result.executionId}`,
measurementKey: `${result.accountingIdentity!.campaignId}/${result.accountingIdentity!.attemptId}/${result.executionId}`,
artifactSha256: p.archiveSha256, scenarioId: selection.scenarioId, ordinal: selection.remoteOrdinal, sourceRevision: intent.sourceRevision,
resultPath: input.result.path, resultSha256: input.result.sha256, hostSha256: input.host.sha256, definitionSha256: input.definition.sha256,
result, definitionDigest: definition.definitionDigest, graderDigest: definition.graderDigest, databaseLane,
hostLifecycle: host.lifecycle, hostPolicy: normalFleet ? "aws-fleet-spot-or-on-demand" : "spot-only" };
}
/** A pre-attempt qualification refusal is an operation, never a case reservation.
* Only these two source-qualified host-gate branches prove this zero-admission stage. */
export function validateRemoteHostRefusal(input: {
intent: RemoteCellIntent; provenance: RemoteArtifactProvenance; host: RemoteArtifactDocument;
}) {
const { intent, provenance: p } = input, host = document(input.host);
requireProof(p.repository === "paperclipai/paperclip" && p.workflow === "runner-full-stack-e2e.yml" && p.workflowRef === "refs/heads/master"
&& /^\d+$/.test(p.runId) && p.runAttempt === 1 && /^\d+$/.test(p.artifactId) && hex(p.archiveSha256), "unverified qualification artifact");
requireProof(/^[a-f0-9]{40}$/.test(intent.sourceRevision) && p.targetSourceRevision === intent.sourceRevision
&& host.sourceRevision === intent.sourceRevision && host.workflowRunId === p.runId && host.workflowAttempt === p.runAttempt
&& host.workflowRef === "paperclipai/paperclip/.github/workflows/runner-full-stack-e2e.yml@refs/heads/master", "qualification source/run mismatch");
const knownRefusal = host.lifecycle === "on-demand" && host.reason === "on-demand-or-unknown-host-refused-before-evaluation"
|| host.lifecycle === "spot" && host.reason === "owned-linux-amd64-postgres-image-unqualified";
requireProof(host.schema === "paperclip.chat-remote-host/v1" && host.status === "blocked" && host.scope === "before-evaluation"
&& host.evaluationAdmitted === false && host.automaticRetries === 0 && knownRefusal && !host.postgres && !host.dockerEngineSha256
&& host.region === "us-east-1" && host.architecture === "x86_64" && /^i-[a-f0-9]{8,17}$/.test(host.instanceId)
&& /^ami-[a-f0-9]{8,17}$/.test(host.imageId), "not a proven pre-evaluation host refusal");
requireProof(Array.isArray(host.executionIds) && host.executionIds.length === intent.selected.length
&& new Set(host.executionIds).size === host.executionIds.length
&& intent.selected.every(row => host.executionIds.includes(row.executionId)), "qualification selection mismatch");
return { schema: "paperclip.chat-remote-operation/v1", campaignId: intent.campaignId, runId: p.runId,
sourceRevision: intent.sourceRevision, artifactId: p.artifactId, artifactSha256: p.archiveSha256,
hostReceiptPath: input.host.path, hostReceiptSha256: input.host.sha256,
outcome: "infrastructure-blocked-before-evaluation", reason: host.reason,
evaluationAdmitted: false, canonicalQueries: 0, nativeRuns: 0, providerCalls: 0,
caseMeasurements: 0, caseOrdinalsConsumed: 0, initialIntentConsumed: false,
caseExecutionIds: host.executionIds as string[], actualHost: { lifecycle: host.lifecycle as "on-demand" | "spot", region: host.region, architecture: host.architecture },
reporterConclusionIsIndependent: true } as const;
}
export function remoteCellUsage(result: RunnerE2EResult): CampaignAttempt["usage"] {
const usage = result.billing?.llm;
return { tokens: usage && Number.isFinite(usage.totalTokens) ? usage.totalTokens : null,
costUsd: usage && ["reported", "partial"].includes(usage.costStatus) && Number.isFinite(usage.reportedCostUsd) ? usage.reportedCostUsd : null,
coverage: usage?.costStatus ?? "unavailable" };
}
export interface RemoteImportRecord { importKey: string; measurementKey: string; resultSha256: string; artifactSha256: string; ordinal: 1 | 2; scenarioId: string; hostLifecycle: "spot" | "on-demand"; hostPolicy: ValidatedRemoteCell["hostPolicy"] }
export type RemoteCampaign = ChatCampaign & { remoteImports?: RemoteImportRecord[] };
/** Pure transaction: caller is the sole writer and atomically persists this returned
* existing campaign ledger. A failed gate never partially reserves an ordinal.
* Framework accounting campaign IDs are retained, not rewritten to the review intent ID. */
export function applyRemoteCell(campaign: RemoteCampaign, cell: ValidatedRemoteCell, qualification: {
attempt: CampaignAttempt; completion: Parameters<typeof completeCampaignAttempt>[1];
}): { campaign: RemoteCampaign; duplicate: boolean } {
requireProof(campaign.campaignId === cell.intentCampaignId, "cannot import into historical or foreign campaign");
const records = campaign.remoteImports ?? [];
const previous = records.find(row => row.importKey === cell.importKey || row.measurementKey === cell.measurementKey || row.scenarioId === cell.scenarioId && row.ordinal === cell.ordinal);
if (previous) {
requireProof(previous.importKey === cell.importKey && previous.measurementKey === cell.measurementKey && previous.resultSha256 === cell.resultSha256 && previous.artifactSha256 === cell.artifactSha256, "changed or duplicate ordinal measurement");
return { campaign, duplicate: true };
}
const { attempt, completion } = qualification;
requireProof(completion.usage.tokens === remoteCellUsage(cell.result).tokens && completion.usage.costUsd === remoteCellUsage(cell.result).costUsd && completion.usage.coverage === remoteCellUsage(cell.result).coverage, "usage differs from actual cell billing");
requireProof(attempt.ordinal === cell.ordinal && attempt.executionId === cell.result.executionId && attempt.sourceRevision === cell.sourceRevision
&& attempt.startedAt === cell.result.startedAt && completion.finishedAt === cell.result.finishedAt
&& attempt.profile === cell.result.profileId && attempt.model === cell.result.model
&& attempt.definitionDigest === cell.definitionDigest && attempt.graderDigest === cell.graderDigest
&& attempt.suiteDefinitionDigest === cell.result.suiteDefinitionHash
&& JSON.stringify(attempt.databaseLane) === JSON.stringify(cell.databaseLane), "qualification does not describe measured cell");
requireProof(completion.outcome === cell.result.status && completion.cleanup === cell.result.cleanup && completion.evidencePaths.includes(cell.resultPath), "measured outcome or cleanup rewritten");
const next = structuredClone(campaign), scenario = next.scenarios.find(row => row.id === cell.scenarioId);
requireProof(scenario, "scenario absent from frozen campaign");
reserveCampaignAttempt(scenario, structuredClone(attempt));
completeCampaignAttempt(scenario, structuredClone(completion));
next.remoteImports = [...records, { importKey: cell.importKey, measurementKey: cell.measurementKey, resultSha256: cell.resultSha256, artifactSha256: cell.artifactSha256, ordinal: cell.ordinal, scenarioId: cell.scenarioId, hostLifecycle: cell.hostLifecycle, hostPolicy: cell.hostPolicy }];
return { campaign: next, duplicate: false };
}