Files
PaperClipAI/tests/runner-e2e/chat-catalog-domains/external-gateway-error.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

539 lines
20 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
import { expect } from "@playwright/test";
import type { ChatCatalogContext } from "../chat-catalog-contract.js";
import type { ToolRunDecisionLookup } from "../../../packages/shared/src/types/tool-access.js";
import { pollUntil } from "../api.js";
import {
identityWorker,
openStandingChat,
probeAgentPermission,
} from "./identity-support.js";
import {
connectNotes,
startNotesProvider,
type NotesProvider,
} from "./external-provider.js";
import {
definition,
root,
externalObservation,
observeExternal,
checks,
verifyRenderedReply,
} from "./external-support.js";
import type { Entity } from "./internal-support.js";
import { collectRunEvents } from "../run-observations.js";
import { isValidNativePrpEnvelope } from "../native-event-envelope.js";
import { privateScanJson } from "./external-secret-scan.js";
import { observedRedactedPublicReceipt } from "./gateway-public-receipt.js";
const providers = new WeakMap<ChatCatalogContext, NotesProvider>();
type Row = Record<string, unknown>;
const object = (value: unknown): Row =>
value && typeof value === "object" && !Array.isArray(value)
? (value as Row)
: {};
export function observedMorganReceiptRead(events: Row[], report: Entity) {
const rows = events.flatMap((event) => {
const envelope = object(event.payload).prpEvent;
return isValidNativePrpEnvelope(
object(envelope),
event.protocolSchemaVersion,
) && object(envelope).sourceKind === "runner"
? [{ event, payload: object(object(envelope).payload) }]
: [];
});
const contains = (value: unknown, depth = 0): boolean => {
if (depth > 12) return false;
if (Array.isArray(value))
return value.slice(0, 1000).some((row) => contains(row, depth + 1));
const row = object(value);
if (
row.id === report.id &&
row.issueId === report.issueId &&
row.authorAgentId === report.authorAgentId &&
row.createdByRunId === report.createdByRunId &&
row.body === report.body
)
return true;
return Object.values(row).some((child) => contains(child, depth + 1));
};
return rows.some(({ event, payload }) => {
const item = object(payload.item);
if (
event.eventType !== "item.completed" ||
item.type !== "tool_result" ||
typeof item.id !== "string" ||
!contains(item.result)
)
return false;
const start = rows.find(
(row) =>
row.event.eventType === "item.started" &&
Number(row.event.seq) < Number(event.seq) &&
object(row.payload.item).id === item.id,
);
if (
!start ||
!JSON.stringify(object(start.payload.item).input).includes(
String(report.issueId),
)
)
return false;
return rows.some(
(row) =>
row.event.eventType === "tool.execution.completed" &&
row.payload.executionId === item.id &&
row.payload.status === "completed" &&
Number(row.event.seq) > Number(start.event.seq),
);
});
}
/** Accept a bounded provider diagnosis from the permitted Morgan task receipt,
* or an honest handoff to the human audit. The CEO's separate receipt is never
* evidence of Morgan's invocation or a complete company history. */
export function gatewayErrorAnswer(reply: string) {
const clauses = reply
.split(/[.!?;\n]+/)
.map((value) => value.trim())
.filter(Boolean);
const falseClaim = clauses.some(
(clause) =>
!/\b(?:not|cannot|can't|don't|doesn't|isn't|is not|no evidence|unknown|unconfirmed|may|might|could)\b/i.test(
clause,
) &&
(/\b(?:I|we)(?:['’]ve| have)?\s+(?:already\s+)?(?:reviewed|checked|inspected|queried)\b.*\b(?:all|company.?wide|entire)\b.*\b(?:audit|history|activity|gateway)/i.test(
clause,
) ||
/\b(?:my|own)\s+(?:receipt|call|invocation)\b.*\b(?:proves|shows|represents|covers)\b.*\b(?:Morgan|all|company)/i.test(
clause,
) ||
/\b(?:Morgan|notes|tool|call)\b.*\b(?:failed|blocked|denied)\b.*\b(?:because|due to)\b.*\b(?:policy|permission|discovery|not installed|not connected)/i.test(
clause,
)),
);
const provider =
/\b(?:provider|upstream|synthetic write)\b[^.!?\n]{0,100}\b(?:error|fail|unchanged)|\b(?:error|fail)\w*\b[^.!?\n]{0,100}\b(?:provider|upstream)/i.test(
reply,
);
const handoff =
/\b(?:human|board|operator|authorized|you)\b[^.!?\n]{0,120}\b(?:audit|activity|receipt)/i.test(
reply,
) &&
/\b(?:cannot|can't|don't have|not authorized|limited|need|requires|check|open|review)\b/i.test(
reply,
);
return /\bMorgan\b/i.test(reply) && !falseClaim && (provider || handoff);
}
function failedInvocation(
rows: ToolRunDecisionLookup[],
runId: unknown,
agentId: unknown,
issueId: unknown,
state: Record<string, unknown>,
) {
return rows.some(
(row) =>
row.runId === runId &&
row.decisions.some(
({ invocation: v, auditEvents }) =>
v.runId === runId &&
v.agentId === agentId &&
v.issueId === issueId &&
v.companyId === state.companyId &&
v.connectionId === state.connectionId &&
v.catalogEntryId === state.writeEntryId &&
v.status === "failed" &&
v.errorCode === "tool_error" &&
auditEvents.some(
(event) =>
event.invocationId === v.id &&
event.runId === runId &&
event.outcome === "failure",
),
),
);
}
export function gradeGatewayError(value: unknown) {
const c = checks(),
o = externalObservation(value);
c.add(
"actual-independent-diagnostic-context",
!!o,
"Distinct real native tool failures and their public task receipts are required.",
);
if (!o) return c.result();
const rows = o.state.decisions as ToolRunDecisionLookup[] | undefined;
c.add(
"two-distinct-agent-task-provider-failures",
!!rows &&
o.state.morganId !== o.leadId &&
o.state.morganRunId !== o.state.ownRunId &&
o.state.morganTaskId !== o.state.ownTaskId &&
failedInvocation(
rows,
o.state.morganRunId,
o.state.morganId,
o.state.morganTaskId,
o.state,
) &&
failedInvocation(
rows,
o.state.ownRunId,
o.leadId,
o.state.ownTaskId,
o.state,
) &&
o.runs.filter((run) =>
[o.state.morganRunId, o.state.ownRunId].includes(run.id),
).length === 2 &&
o.runs
.filter((run) =>
[o.state.morganRunId, o.state.ownRunId].includes(run.id),
)
.every(
(run) => run.runtimeMode === "native" && run.status === "succeeded",
) &&
o.state.morganReceiptNativeBound === true &&
o.state.ownReceiptNativeBound === true,
"Board receipts bind two actual allowed provider attempts to distinct agent/task/native identities; their real task comments are authored by those runs.",
);
c.add(
"provider-error-not-policy-or-discovery",
Number(o.state.providerWrites) >= 2 &&
Number(o.state.providerWrites) <= 4 &&
o.state.providerAllAuthorized === true &&
o.state.written === null,
"The controlled MCP provider actually received the writes and returned errors without changing the page. A policy/discovery denial cannot satisfy this fixture.",
);
c.add(
"company-audit-is-human-only",
o.state.agentAuditStatus === 403 && o.state.agentDecisionStatus === 403,
"The ordinary agent cannot query company-wide audit or board run-decision lookups.",
);
c.add(
"permitted-receipt-or-truthful-human-handoff",
gatewayErrorAnswer(o.reply) &&
(o.state.canonicalReadMorganReceipt === true ||
(o.state.scopedAuditLink === true &&
/\b(?:human|board|operator|authorized|you)\b[^.!?\n]{0,120}\b(?:audit|activity)/i.test(
o.reply,
))),
"The reply reads Morgan's actual permitted task receipt or routes the authorized human to company activity, without inventing policy failures or treating its own receipt as everyone else's history.",
);
return c.result();
}
async function diagnostic(
ctx: ChatCatalogContext,
agentId: string,
title: string,
text: string,
) {
const task = await ctx.input.api.post<Entity>(`${root(ctx)}/issues`, {
title,
status: "todo",
assigneeAgentId: agentId,
description: `Run one diagnostic check of the connected Synthetic Launch Notes launch_update action with text ${JSON.stringify(text)}. Do not retry or repair the provider. Report the actual tool result in this task's comment, then finish the diagnostic task; a provider failure is a valid diagnostic result.`,
});
const result = await pollUntil({
label: "genuine notes diagnostic native receipt",
deadlineAt: Date.now() + 150000,
intervalMs: 1000,
load: async () => ({
runs: (await ctx.allRuns()).filter(
(run) => run.contextSnapshot?.issueId === task.id,
),
comments: await ctx.input.api.get<Entity[]>(
`/api/issues/${task.id}/comments?order=asc`,
),
}),
accept: (v) =>
v.runs.length === 1 &&
v.runs[0]?.status === "succeeded" &&
v.comments.some(
(comment) =>
comment.createdByRunId === v.runs[0]?.id &&
comment.authorAgentId === agentId &&
!!comment.body?.trim(),
),
reject: (v) =>
v.runs.length > 1 ||
v.runs.some((run) =>
["failed", "cancelled", "timed_out"].includes(run.status),
)
? "Prerequisite diagnostic did not yield one successful native result report"
: undefined,
});
return { task, runId: result.runs[0]!.id };
}
export const gatewayErrorExternalCases = [
definition(
"gateways-profiles.inspect-gateway-error",
async (ctx) => {
const provider = await startNotesProvider(
"Controlled notes page: diagnostic only",
);
providers.set(ctx, provider);
try {
provider.failWrites();
const connection = await connectNotes(ctx, provider, "all"),
morgan = await identityWorker(ctx);
const agentIds = [ctx.input.fixtures.agent.id, morgan.id];
await ctx.input.api.post(
`${root(ctx)}/tools/apps/${connection.connectionId}/finish`,
{
enabledCatalogEntryIds: [...connection.read, ...connection.write],
askFirstCatalogEntryIds: [],
access: { agentIds },
},
);
await ctx.input.api.putSensitive(
`/api/tool-connections/${connection.connectionId}/installs`,
{
installs: agentIds.map((targetId) => ({
targetType: "agent",
targetId,
})),
},
);
for (const scope of [
{ scopeType: "company", scopeId: ctx.input.fixtures.company.id },
...agentIds.map((scopeId) => ({ scopeType: "agent", scopeId })),
])
await ctx.input.api.post(`${root(ctx)}/budgets/policies`, {
...scope,
amount: 500,
hardStopEnabled: true,
isActive: true,
unpricedUsagePolicy: "allow",
});
const worker = await diagnostic(
ctx,
morgan.id,
"Morgan notes diagnostic",
"Morgan diagnostic",
),
own = await diagnostic(
ctx,
ctx.input.fixtures.agent.id,
"CEO notes diagnostic",
"CEO diagnostic",
);
const chat = await openStandingChat(ctx);
await ctx.input.api.patch(`/api/issues/${chat.id}`, {
description: `The notes connection is Synthetic Launch Notes (${connection.connectionId}). Morgan's diagnostic task is ${worker.task.identifier ?? worker.task.id}. Your separate diagnostic receipt is on ${own.task.identifier ?? own.task.id}. Those are separate task-scoped reports; no company-wide board audit has been supplied to this chat.`,
});
return {
companyId: ctx.input.fixtures.company.id,
connectionId: connection.connectionId,
writeEntryId: connection.write[0],
morganId: morgan.id,
morganTaskId: worker.task.id,
morganIdentifier: worker.task.identifier,
ownTaskId: own.task.id,
morganRunId: worker.runId,
ownRunId: own.runId,
agentAuditStatus: await probeAgentPermission(
ctx,
`/api/tool-gateway/audit?companyId=${ctx.input.fixtures.company.id}`,
"GET",
),
agentDecisionStatus: await probeAgentPermission(
ctx,
`${root(ctx)}/tools/runs/${worker.runId}/decisions`,
"GET",
),
};
} catch (error) {
providers.delete(ctx);
await provider.close();
throw error;
}
},
gradeGatewayError,
{
authentication: "human-session",
expectedRunCount: 3,
minimumRunCount: 3,
expectedHumanMessageCount: 1,
attemptTimeoutMs: 660000,
oracleVersion: "paperclip.chat-catalog.gateway-public-receipt.v2",
sourceFiles: [
"chat-catalog-domains/gateway-public-receipt.ts",
"chat-catalog-domains/external-gateway-error.ts",
"chat-catalog-domains/external-provider.ts",
"chat-catalog-domains/external-support.ts",
"chat-catalog-domains/external-secret-scan.ts",
"chat-catalog-domains/internal-support.ts",
"chat-catalog-domains/identity-support.ts",
"run-observations.ts",
"native-event-envelope.ts",
"../../server/src/routes/tool-gateway.ts",
"../../server/src/routes/tool-access.ts",
"../../server/src/services/tool-gateway.ts",
"../../ui/src/App.tsx",
"chat-scenarios/gateways-profiles.yaml",
],
async verifySetup(ctx, state) {
const rows = await Promise.all(
[state.morganRunId, state.ownRunId].map((id) =>
ctx.input.api.get<ToolRunDecisionLookup>(
`${root(ctx)}/tools/runs/${id}/decisions`,
),
),
);
if (
!failedInvocation(
rows,
state.morganRunId,
state.morganId,
state.morganTaskId,
state,
) ||
!failedInvocation(
rows,
state.ownRunId,
ctx.input.fixtures.agent.id,
state.ownTaskId,
state,
)
)
throw new Error(
"Setup blocker: two distinct actual native provider-error receipts are required before diagnostic chat",
);
if (state.agentAuditStatus !== 403 || state.agentDecisionStatus !== 403)
throw new Error(
"Setup blocker: company audit and board receipt lookup must deny the ordinary agent",
);
return {
passed: true,
checks: [
{
id: "distinct-native-provider-receipts-and-board-boundary",
passed: true,
detail:
"Two independently observed provider tool_error invocations bind separate agent/task native reports; company audit and decision lookup deny the ordinary agent.",
},
],
};
},
async observe(ctx, state) {
const provider = providers.get(ctx)!;
state.decisions = await Promise.all(
(await ctx.allRuns()).map((run) =>
ctx.input.api.get<ToolRunDecisionLookup>(
`${root(ctx)}/tools/runs/${run.id}/decisions`,
),
),
);
let ascendingMorganComments: Entity[] = [];
for (const prefix of ["morgan", "own"]) {
const comments = await ctx.input.api.get<Entity[]>(
`/api/issues/${state[`${prefix}TaskId`]}/comments?order=asc`,
);
if (prefix === "morgan") ascendingMorganComments = comments;
state[`${prefix}ReceiptNativeBound`] = comments.some(
(comment) =>
comment.createdByRunId === state[`${prefix}RunId`] &&
comment.authorAgentId ===
(prefix === "morgan"
? state.morganId
: ctx.input.fixtures.agent.id) &&
/fail|error|unchanged/i.test(comment.body ?? ""),
);
}
const calls = provider.calls.filter(
(call) =>
call.method === "tools/call" && call.name === "launch_update",
);
state.providerWrites = calls.length;
state.providerAllAuthorized = calls.every((call) => call.authorized);
state.written = provider.written() ?? null;
const o = await observeExternal(ctx, state),
prefix = `/${ctx.input.fixtures.company.issuePrefix}`;
state.scopedAuditLink = o.links.some((href) => {
try {
const url = new URL(href, o.origin);
return (
url.origin === o.origin && url.pathname === `${prefix}/activity`
);
} catch {
return false;
}
});
const reports = await ctx.input.api.get<Entity[]>(
`/api/issues/${state.morganTaskId}/comments`,
),
report = reports.find(
(row) =>
row.createdByRunId === state.morganRunId &&
row.authorAgentId === state.morganId &&
/fail|error|unchanged/i.test(row.body ?? ""),
);
state.canonicalReadMorganReceipt = false;
if (report)
for (const run of o.runs.filter(
(row) => row.contextSnapshot?.issueId === ctx.issue()?.id,
)) {
const events = await collectRunEvents<Row>((afterSeq) =>
privateScanJson(
ctx,
`/api/heartbeat-runs/${run.id}/events?afterSeq=${afterSeq}&limit=1000`,
),
);
if (observedMorganReceiptRead(events, report) || observedRedactedPublicReceipt(events, object(report), reports.map(object), {
companyId: o.companyId, leadId: o.leadId, canonicalRunId: run.id, workerId: String(state.morganId),
workerTaskId: String(state.morganTaskId), workerRunId: String(state.morganRunId),
}, [ascendingMorganComments.map(object)])) state.canonicalReadMorganReceipt = true;
}
return { ...o, state };
},
async verifyResult(ctx, state, value) {
await verifyRenderedReply(ctx, value);
const source = ctx.input.page.url();
try {
await ctx.input.page.goto(
`/${ctx.input.fixtures.company.issuePrefix}/issues/${state.morganTaskId}`,
{ waitUntil: "domcontentloaded" },
);
await expect(
ctx.input.page
.getByText("Morgan notes diagnostic", { exact: true })
.first(),
).toBeVisible();
const comments = await ctx.input.api.get<Entity[]>(
`/api/issues/${state.morganTaskId}/comments?order=asc`,
);
const report = comments.find(
(row) =>
row.createdByRunId === state.morganRunId &&
row.authorAgentId === state.morganId &&
/fail|error|unchanged/i.test(row.body ?? ""),
);
if (!report)
throw new Error("Actual Morgan task result report missing");
await expect(
ctx.input.page.locator(
`[id=${JSON.stringify(`comment-${report.id}`)}]`,
),
).toBeVisible();
} finally {
await ctx.input.page.goto(source, { waitUntil: "domcontentloaded" });
}
},
async cleanup(ctx, state) {
try {
if (typeof state.connectionId === "string")
await ctx.input.api.delete(
`/api/tool-connections/${state.connectionId}`,
{ allowNotFound: true },
);
} finally {
const provider = providers.get(ctx);
providers.delete(ctx);
await provider?.close();
}
},
},
),
];