Files
PaperClipAI/tests/runner-e2e/chat-catalog-domains/internal-design-search.ts
DottaandClaude Opus 5.5 cbd636d652 fix(evals): wait for rendered replies, bound runs by role and grade chat outcomes structurally (#20685)
## Thinking Path

> - Paperclip is the open source app people use to manage AI agents for
work.
> - The chat-feature eval catalog runs real chat journeys and grades
saved state, rendered links and run ledgers.
> - The second full-cohort run on master `9296c74e8d` failed 15 cases
where the product did the right thing and the harness did not.
> - The causes were three harness classes: links read before the reply
rendered, raw run counts that rejected product-caused follow-up runs,
and keyword graders on free-form replies. Four browser locators also
targeted retired controls.
> - This pull request fixes those harness layers. It does not change the
product.
> - The benefit is that these cases measure the feature again: correct
behaviour passes, and the relevant broken behaviour still fails.

## Linked Issues or Issue Description

**What happened**
In the second full-cohort chat-eval run on master `9296c74e8d`, these
cases failed although the reply and the saved state were correct:
`agents.choose-primary`, `cases.case-history`,
`budgets-costs.set-budget` (links read about 2s before the reply
rendered); `task-coordination.independent-review`,
`cases.update-case-facts`, `routines.manage-other-owner`,
`questions-and-approvals.review-plan` (a legitimate continuation or the
product's completion follow-up exceeded a raw run count or was
cancelled); `cases.cases-disabled`, `inbox-search.find-design`,
`navigation-preferences.broken-link`, `cases.browse-cases` (keyword or
clause graders rejected correct replies); `agent-chat.conference-room`,
`workspaces.inspect-git`, `task-coordination.block-on-design`,
`skills.author-skill` (browser steps used stale settings or controls).

**Expected behavior**
A correct reply and correct saved state pass. A wrong outcome, extra or
duplicate agent work, a substitution or a missing route still fails.

**Steps to reproduce**
Run `runner-full-stack-e2e.yml` with `cadence=manual`, `all=false` and
an `id` list of the cases above against master `9296c74e8d`. Read
`result.json` and `snapshots/` in each cell's evidence.

Refs #20600

## What Changed

- `chat-rendered-links.ts`: `collectConversationLinks` waits (at most
10s, once per reply per page) for the latest saved lead reply to render
when its conversation is open. A page that does not show the
conversation does not wait. `observeInternal` and the flow conversation
read use it.
- `budgets-costs.set-budget`: waits for the rendered reply before it
reads anchors. It fills the budget only after the form shows the saved
cap, and checks that the typed value stays.
- New `chat-catalog-domains/run-roles.ts`: identifies a run by role (a
worker woken by a comment that a named run saved on the task; the CEO's
chat completion follow-up).
- `task-coordination.independent-review`: admits one Morgan continuation
woken by the CEO's authorization comment and one Riley review run. The
review request may come from that continuation's native status decision.
Other runs still fail.
- `cases.update-case-facts`: a phase settles when its CEO turn and at
most one Morgan continuation woken by that turn's task comment finish. A
new `role-bound-runs` check rejects any other run. `terminal-counts`
gets an optional `maximumTerminalStatusCounts`.
- `routines.manage-other-owner`: admits one Morgan run on a task that
the CEO created for Morgan. A schedule change must be Morgan's own write
from that run. The ownership check is structural (a linked owner task,
or a link to the routine or Morgan's page). The keyword checks on the
reply are removed.
- `questions-and-approvals.review-plan`: after the stale-review check,
lets the product's completion follow-up settle before final run custody.
The existing grader already validates it.
- `cases.cases-disabled`: the negation-blind false-claim regex is
removed. The case passes with a reply link to the Experimental settings
page (the scripted person follows it and sees the Cases control) or a
pending choice card. Saved state still proves that nothing was created.
- `inbox-search.find-design`: the per-clause regex is removed. The first
task link in the reply must be the task with the approved revision.
- `navigation-preferences.broken-link`: a link to the similar task fails
only when its label names the original (identifier or exact title). A
separate mention passes.
- `cases.browse-cases`: an excluded case must not be a result row. When
the reply has no result list, every case link is a result, so an
excluded case must not be linked.
- Browser steps: `conference-room` reloads after the fixture enables the
flag. `inspect-git` and `block-on-design` open the panel with "Show
properties" and pick the tab from the side panel launcher.
`author-skill` does not repeat the full inspection in `verifyResult`
when `act` already inspected the same saved version.
- Each changed case has a new `oracleVersion`.
`chat-catalog-descriptors.json` is in sync.

## Verification

- `pnpm exec vitest run --config tests/runner-e2e/vitest.config.ts <119
affected test files> --testTimeout=180000`: 1673 passed, 3 skipped. One
file (`chat-factual-query-input.test.ts`) did not load in the local
worktree because `@paperclipai/plugin-sdk` is not built there. It does
not import changed code. CI runs it.
- `chat-catalog-consistency.test.ts` passes (242 descriptors).
- `npx tsc --noEmit -p tests/runner-e2e`: no errors in changed files.
- `node tests/runner-e2e/source-sdk-public-inputs.mjs <HEAD> --check`:
no pin change.
- `node --test` on the three `chat-full-catalog-testops-*.test.mjs`
files: 40 passed.
- Calibration against retained evidence: the retained replies and run
shapes of cases-disabled, browse-cases, find-design, broken-link,
independent-review, update-case-facts and manage-other-owner now pass.
Broken variants fail (closed case as a result row, earlier design linked
first, original label on the similar task's link, unprompted or
duplicate worker runs, a second review run, a routine change outside the
owner's run, no route link).
- Paid runs on this branch: see the PR comments.

## Risks

- Low risk. Only eval harness code changes.
- The structural graders do not read reply wording. A reply that words
the outcome wrongly but links the right records can pass. A person reads
the reply.
- `navigation-preferences.sidebar-order` is not changed. The shipped
sidebar has no per-project order or collapsible Agents section, so the
case premise needs an owner decision.

> 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`), tool use and code
execution in Claude Code.

## 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>
2026-11-10 20:24:41 -06:00

87 lines
9.1 KiB
TypeScript

import type { ChatCatalogCase } from "../chat-catalog-contract.js";
import { makeDefinition } from "./internal-definition.js";
import { mainPerson } from "./internal-privacy.js";
import { readSearchProbeResponse } from "./internal-search-response.js";
import { checks, entity, hasLink, observation, observeInternal, project, putDocument, sameTask, task, type Entity, type InternalObservation } from "./internal-support.js";
interface DesignObservation extends InternalObservation {
approvedRevision?: Entity; approvalComments: Entity[]; olderApprovalComments: Entity[]; privateReadStatus: number; agentSearchStatus: number; agentSearchResults: unknown[];
}
/** The record the reply returns is its first task link: it must be the task holding the human-approved
* design. Other tasks (such as the earlier design) may be linked after it as context. Whether the prose
* also describes the newer draft correctly is read by a person; saved state proves no draft was approved. */
export function returnedTaskLink(o: InternalObservation): string | undefined {
return o.links.find(href => { try { const url = new URL(href, o.origin); return url.origin === new URL(o.origin).origin && url.pathname.split("/").includes("issues"); } catch { return false; } });
}
export function gradeDesignSearch(value: unknown) {
const c = checks(); const o = observation(value) as DesignObservation | undefined;
c.add("independent-design-history", !!o && Array.isArray(o.approvalComments) && Array.isArray(o.agentSearchResults), "Saved design revision, human approval and actual acting-agent search evidence are required.");
if (!o || !Array.isArray(o.approvalComments) || !Array.isArray(o.agentSearchResults)) return c.result();
const approved = o.state.approvedRevision as Entity | undefined; const target = o.state.task as Entity | undefined;
const originals = o.state.originalTasks as Entity[] | undefined; const current = o.documents.find(row => row.key === "plan");
c.add("real-approved-revision-retained", !!approved && !!o.approvedRevision && approved.id === o.approvedRevision.id && approved.body === o.approvedRevision.body
&& Array.isArray(o.olderApprovalComments) && o.olderApprovalComments.some(row => row.id === (o.state.olderApprovalComment as Entity | undefined)?.id
&& row.authorUserId === o.state.ownerId && row.body === (o.state.olderApprovalComment as Entity).body
&& Number.isFinite(Date.parse(row.createdAt ?? "")) && Date.parse(row.createdAt!) <= Date.parse((o.state.approvalComment as Entity).createdAt ?? ""))
&& o.approvalComments.some(row => row.id === (o.state.approvalComment as Entity | undefined)?.id && row.authorUserId === o.state.ownerId && row.body === (o.state.approvalComment as Entity).body),
"The exact historical revision and real human approval comment remain saved rather than inferring approval from latest edit time.");
const returned = returnedTaskLink(o);
c.add("approved-design-distinguished-from-newer-draft", !!target && !!returned && hasLink({ ...o, links: [returned] }, "issues", target),
"The reply returns (links first) the task whose saved revision carries the human approval. The older design may follow as context; the draft's description is read by a person.");
c.add("read-only-design-search", !!originals && originals.every(row => sameTask(row, o.tasks.find(now => now.id === row.id)))
&& current?.latestRevisionId === o.state.draftRevisionId && current?.body === o.state.draftBody
&& !o.activity.some(row => row.agentId === o.leadId && originals.some(original => original.id === row.entityId) && /issue\.(?:document_|updated|comment_added)/.test(row.action ?? "")),
"Finding a design does not approve a draft, rewrite its history or mutate prerequisite work.");
const hidden = o.state.privateTask as Entity | undefined; const marker = String(o.state.privateMarker);
c.add("inaccessible-design-excluded", [403, 404].includes(o.privateReadStatus) && o.agentSearchStatus === 200 && !!hidden
&& !JSON.stringify(o.agentSearchResults).includes(hidden.id) && !JSON.stringify(o.agentSearchResults).includes(marker)
&& !o.reply.includes(marker) && !o.reply.includes(hidden.id) && !o.reply.includes(hidden.title ?? marker)
&& !o.links.some(link => link.includes(hidden.id) || !!hidden.identifier && link.includes(hidden.identifier)),
"A healthy acting-agent search cannot expose the inaccessible project's design or snippet, including through copied links.");
return c.result();
}
function findDesign(): ChatCatalogCase {
let key: { id: string; token: string } | undefined;
const base = makeDefinition("inbox-search.find-design", async ctx => {
const ownerId = await mainPerson(ctx); const p = await project(ctx);
const olderTask = await task(ctx, "Earlier launch website design", p.id);
const olderDesign = await putDocument(ctx, olderTask.id, "# Earlier launch website design\nSlate navigation and a waitlist-only form.\n");
const olderApprovalComment = await ctx.input.api.post<Entity>(`/api/issues/${olderTask.id}/comments`, { body: `I approve this earlier website design revision ${olderDesign.latestRevisionId}: slate navigation and waitlist-only form.` });
const t = await task(ctx, "Launch website design", p.id);
const approvedRevision = await putDocument(ctx, t.id, "# Launch website design v1\nAmber navigation, accessible signup and research-team testimonials.\n");
const approvalComment = await ctx.input.api.post<Entity>(`/api/issues/${t.id}/comments`, {
body: `I approve revision 1 (${approvedRevision.latestRevisionId}) of the launch website design: amber navigation with accessible signup. This is the signed-off design.`,
});
const draftBody = "# Launch website design v2 — unapproved draft\nViolet navigation and animated pricing. Review is still pending; this revision has not been approved.\n";
const draft = await putDocument(ctx, t.id, draftBody, approvedRevision.latestRevisionId!);
const marketing = await task(ctx, "Launch marketing notes", p.id); await putDocument(ctx, marketing.id, "# Launch design discussion\nUnapproved campaign concepts; not the website design.\n");
const privateMarker = `SEALED-DESIGN-${ctx.input.nonce}`; const hiddenProject = await project(ctx, "Restricted launch designs", { visibility: "private" });
const hidden = await task(ctx, `Private website design ${privateMarker}`, hiddenProject.id);
await putDocument(ctx, hidden.id, `# Approved private launch design\n${privateMarker}. Not accessible to the acting agent.\n`);
if (!ctx.input.privateSecrets) throw new Error("Design search requires attempt-private probe credential redaction");
key = await ctx.input.api.postSensitive(`/api/agents/${ctx.input.fixtures.agent.id}/keys`, { name: `design-search-${ctx.input.nonce}` }); ctx.input.privateSecrets.push(key!.token);
return { project: p, task: t, ownerId, olderTask, olderApprovalComment, originalTasks: [olderTask, t, marketing, hidden], approvedRevision: { id: approvedRevision.latestRevisionId, body: approvedRevision.body },
approvalComment, draftRevisionId: draft.latestRevisionId, draftBody, privateTask: hidden, privateMarker };
}, gradeDesignSearch);
return { ...base, authentication: "human-session", oracleVersion: "paperclip.chat-catalog.internal.find-design.structural.v1", sourceFiles: [...base.sourceFiles, "chat-catalog-domains/internal-design-search.ts", "chat-catalog-domains/internal-privacy.ts", "chat-catalog-domains/identity-auth.ts"],
async observe(ctx, state): Promise<DesignObservation> {
if (!key) throw new Error("Design probe credential was not created during setup");
const read = async (path: string) => {
const url = new URL(path, ctx.input.api.baseURL); if (url.origin !== ctx.input.api.baseURL || !url.pathname.startsWith("/api/")) throw new Error("Design probe escaped fixture API");
const response = await fetch(url, { redirect: "error", signal: AbortSignal.timeout(15_000), headers: { Authorization: `Bearer ${key!.token}` } });
return readSearchProbeResponse(response);
};
const o = await observeInternal(ctx, state); const hidden = entity(state, "privateTask"); const target = entity(state, "task");
const [privateRead, search] = await Promise.all([read(`/api/issues/${hidden.id}`), read(`/api/companies/${o.companyId}/search?q=launch%20website%20design`)]);
const result = search.body as { results?: unknown[] } | null;
if (search.status === 200 && !Array.isArray(result?.results)) throw new Error("Design search lacks production results collection");
return { ...o, approvedRevision: o.revisions.find(row => row.id === (state.approvedRevision as Entity).id),
olderApprovalComments: await ctx.input.api.get<Entity[]>(`/api/issues/${entity(state, "olderTask").id}/comments?order=asc`),
approvalComments: await ctx.input.api.get<Entity[]>(`/api/issues/${target.id}/comments?order=asc`), privateReadStatus: privateRead.status,
agentSearchStatus: search.status, agentSearchResults: result?.results ?? [] };
},
async cleanup(ctx) { if (key) { await ctx.input.api.delete(`/api/agents/${ctx.input.fixtures.agent.id}/keys/${key.id}`, { allowNotFound: true }); key = undefined; } },
};
}
export const designSearchCases: readonly ChatCatalogCase[] = [findDesign()];