Files
PaperClipAI/tests/runner-e2e/chat-catalog-domains/privileged-instance.ts
T
DottaandClaude Opus 5.5 65ff80a4bb fix(evals): grade chat acknowledgements, saved replies and links on saved state (#21000)
## Thinking Path

> - Paperclip is the open source app people use to manage AI agents for
work
> - The chat eval catalog runs real chat journeys against real agents
and grades saved product state
> - A review of full cohort 3 found three cases whose oracle passed
wrong behavior, and eight passes whose final evidence saved no rendered
links
> - `companies.agent-observability` passed although the agent denied the
saved collector. `inbox-search.show-my-work` counted links that existed
only in run-stream prose. `instance-operations.restart-service` accepted
a reply whose only link was the `/<prefix>/` placeholder
> - The final evidence read ran on a page that had not rendered the
conversation yet, so it saved no links
> - This pull request grades those cases on saved-state reads, the saved
reply and resolved links, and reads final evidence from the rendered
conversation
> - The benefit is that these cases fail when the product is wrong and
keep their links when it is right

## Linked Issues or Issue Description

Refs #20998
Refs #20999

**What happened?**
- `companies.agent-observability`: the board saved and tested a
collector. Asked to acknowledge it, the agent said there was no endpoint
or credentials. The oracle graded only human-side state, so it passed.
- `inbox-search.show-my-work`: the saved reply said "Answered above"
over nothing. The links the oracle counted came from run-stream prose
that the bubble also shows.
- `instance-operations.restart-service`: the reply's only action link
was `/<prefix>/company/settings/instance`. The oracle did not check
links.
- Eight cohort-3 passes (`access.other-company`, `agents.agent-api-key`,
`assistant-connections.revoke-personal-grant`,
`budgets-costs.resolve-budget`, `recovery.retry-exhausted`,
`steering.stop-versus-pause`, `task-coordination.pause-tree`,
`teams.install-team`) saved a final observation with no links and a
failed grade. The graded reload had the links. The final evidence read
ran after `verifyResult` left the page mid-load, and an expired render
wait from an earlier document made the read instant.

**Expected behavior**
Each oracle fails the observed wrong behavior and passes valid, reworded
behavior. Final evidence holds the links that the conversation renders.

**Steps to reproduce**
Grade the retained cohort-3 observations with the old oracles. They
pass. Grade them with these oracles. The three wrong cases fail.

## What Changed

- `companies.agent-observability` (oracle v4): each acknowledgement turn
must read the saved trace export status successfully. The read is bound
to the company by its redaction-safe `call_api` receipt. A reply must
also render a link to `/<prefix>/company/settings` for the fixture
company. The reply's wording is not matched.
- `inbox-search.show-my-work` (oracle v5): actionable links must be
carried by the saved reply: a Markdown link target in the saved body, or
a task identifier written in it, which the conversation links. New
shared helper `savedReplyLinks`.
- `instance-operations.restart-service` (oracle v3): new check
`reply-links-resolve` rejects any rendered or saved link target that
keeps a template placeholder (`<...>` or `{...}`). New helpers
`markdownLinkTargets` and `unresolvedLinkTarget` in
`chat-rendered-links.ts`.
- Link capture: the final success-path evidence read reopens the
rendered conversation first. An expired render wait now belongs to its
loaded document, not to the Playwright page.
- Updated `chat-catalog-descriptors.json` for the three oracle versions
and source files. No scenario yaml changed, so the TestOps manifest does
not change.

## Verification

- `npx vitest run --config tests/runner-e2e/vitest.config.ts
tests/runner-e2e/chat-catalog-domains/identity-observability.test.ts
tests/runner-e2e/chat-catalog-domains/internal.test.ts
tests/runner-e2e/chat-catalog-domains/privileged-oracles.test.ts
tests/runner-e2e/chat-catalog-domains/privileged-restart-history.test.ts
tests/runner-e2e/chat-rendered-links.test.ts
tests/runner-e2e/chat-catalog-consistency.test.ts
tests/runner-e2e/chat-catalog-fingerprint.test.ts`
- Calibration tests for each case: a valid result, a reworded valid
result, and the broken cohort-3 behavior.
- Red/green: the new render-wait test fails on the old wait logic and
passes with this change.
- `npx tsc -p tests/runner-e2e/tsconfig.json --noEmit` passes. `node
tests/runner-e2e/source-sdk-public-inputs.mjs <HEAD> --check` reports no
change.
- A paid run on a combined branch with the two product fixes is recorded
in a comment on this pull request.

## Risks

- `companies.agent-observability` needs the agent-readable status route
from #20998. Without it, the case fails, which is correct.
- The show-my-work check needs links in the saved reply. Before #20999,
an OpenCode reply that left its answer in the run stream fails this
case.
- The final evidence read can wait up to 30 seconds to reopen the
conversation. The read is still bounded.

## Model Used

- Claude Opus 5.5 (`claude-opus-5-5`), Anthropic, with 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-11 20:49:38 -06:00

78 lines
6.5 KiB
TypeScript

import { expect } from "@playwright/test";
import { readFile, realpath } from "node:fs/promises";
import path from "node:path";
import { runnerE2EServerControlPaths } from "../harness-env.js";
import { markdownLinkTargets, unresolvedLinkTarget } from "../chat-rendered-links.js";
import { checks, type Entity } from "./internal-support.js";
import { privilegedDefinition, privilegedObservation, settlePrivilegedChat } from "./privileged-support.js";
export function gradeRestartService(value: unknown) {
const c = checks(), o = privilegedObservation(value);
c.add("owned-restart-observation", !!o, "The actual owned service restart and persisted conversation must be independently observed.");
if (!o) return c.result();
const receipt = o.state.restartReceipt as { requestId?: string; status?: string; completedAt?: string } | undefined;
c.add("service-stopped-and-replaced", receipt?.status === "ready" && receipt.requestId === o.state.expectedRequestId
&& o.state.stopStartLogVerified === true && typeof receipt.completedAt === "string"
&& Date.parse(receipt.completedAt) >= Number(o.state.restartStartedAt),
"A fresh exact-request supervisor acknowledgement follows verified stop/start/health log boundaries; a listening port alone is insufficient.");
c.add("same-conversation-and-history", o.state.sourceBefore === o.state.sourceAfter && typeof o.state.sourceBefore === "string"
&& o.state.persistedHistoryRetained === true && o.state.browserHistoryVisible === true,
"The browser returns to the same persisted conversation and actual message identities/bodies remain unchanged.");
c.add("no-duplicate-admission", o.runs.length === 1 && o.state.runBefore === o.runs[0]?.id && o.runs[0]?.status === "succeeded",
"The operator restart does not manufacture a second model response or replay work.");
// Only the harness's own request restarted the service (exact receipt above), so the agent
// could not have restarted it. Whether the reply's wording describes the operator path and
// avoids claiming a restart or offline responsiveness is left to a human reader.
c.add("pre-restart-reply-recorded", typeof o.reply === "string" && o.reply.trim().length > 0,
"The canonical run leaves its own reply before the operator restart.");
// A link the person clicks must open a real page. A placeholder copied from guidance, such as
// /<prefix>/company/settings/instance, renders as /%3Cprefix%3E/... and opens nothing.
c.add("reply-links-resolve", ![...o.links, ...markdownLinkTargets(o.reply)].some(unresolvedLinkTarget),
"Every link in the saved and rendered reply is a resolved path; none keeps a template placeholder such as <prefix>.");
return c.result();
}
export const privilegedInstanceCases = [{ ...privilegedDefinition("instance-operations.restart-service", "privileged-instance", {
async setup(ctx) {
if (ctx.input.execution.environment.id !== "local") throw new Error("Owned service restart requires the launcher's local disposable instance");
const root = process.env.PAPERCLIP_RUNNER_E2E_TEMP_ROOT, log = process.env.PAPERCLIP_RUNNER_E2E_SERVER_LOG;
if (!root || !log) throw new Error("Owned restart control directory and supervisor log are required");
const owned = await realpath(root), logPath = await realpath(log);
if (!logPath.startsWith(owned + path.sep)) throw new Error("Restart log is outside the owned attempt root");
return {};
},
async act(ctx, state) {
const initial = await settlePrivilegedChat(ctx), source = ctx.issue()!;
const history = await ctx.input.api.get<Entity[]>(`/api/issues/${source.id}/comments?order=asc`);
const url = ctx.input.page.url();
const reply = history.filter(row => row.authorAgentId === ctx.input.fixtures.agent.id).at(-1)!;
const replyBody = () => ctx.input.page.locator(`[id=${JSON.stringify(`comment-${reply.id}`)}]`).locator(".paperclip-markdown").first();
await expect(replyBody()).toBeVisible();
const renderedReplyBefore = await replyBody().innerText();
if (!renderedReplyBefore.trim()) throw new Error("Pre-restart reply has no visible rendered body");
state.sourceBefore = source.id; state.runBefore = initial.runs[0]!.id;
state.expectedRequestId = `chat-${ctx.input.nonce}`; state.restartStartedAt = Date.now();
const logPath = process.env.PAPERCLIP_RUNNER_E2E_SERVER_LOG!;
const beforeLogLength = (await readFile(logPath, "utf8")).length;
// The existing operator callback stops the process, waits for HTTP to stop,
// launches a replacement and requires its exact ready acknowledgement.
await ctx.input.restart();
const receipt = JSON.parse(await readFile(runnerE2EServerControlPaths(process.env.PAPERCLIP_RUNNER_E2E_TEMP_ROOT!).restartAcknowledgementPath, "utf8"));
const log = (await readFile(logPath, "utf8")).slice(beforeLogLength);
const stop = log.indexOf(`Restart request ${state.expectedRequestId}: stopping Paperclip`);
const start = log.indexOf(`Restart request ${state.expectedRequestId}: starting Paperclip`);
const ready = log.indexOf(`Restart request ${state.expectedRequestId}: Paperclip is healthy`);
state.stopStartLogVerified = stop >= 0 && start > stop && ready > start;
state.restartReceipt = { requestId: receipt.requestId, status: receipt.status, completedAt: receipt.completedAt };
await ctx.input.page.goto(url, { waitUntil: "domcontentloaded" });
await expect(ctx.input.page.getByTestId("task-chat-composer-input")).toBeVisible();
await ctx.refreshIssue(); state.sourceAfter = ctx.issue()?.id;
const after = await ctx.input.api.get<Entity[]>(`/api/issues/${source.id}/comments?order=asc`);
state.persistedHistoryRetained = after.length === history.length && history.every(row => after.some(saved => saved.id === row.id && saved.body === row.body && saved.createdByRunId === row.createdByRunId));
await expect(replyBody()).toBeVisible();
await expect(replyBody()).toHaveText(renderedReplyBefore, { useInnerText: true });
state.browserHistoryVisible = true;
await ctx.input.evidence("chat-catalog-owned-service-restart.json", { ...state, retainedCommentIds: after.map(row => row.id) });
}, grade: gradeRestartService,
async verifyResult(ctx) { await expect(ctx.input.page.getByTestId("task-chat-composer-input")).toBeVisible(); },
}), sourceFiles: ["chat-catalog-domains/privileged-support.ts", "chat-catalog-domains/turn-response-card.ts", "chat-catalog-domains/privileged-instance.ts", "chat-rendered-links.ts", "chat-scenarios/instance-operations.yaml"], oracleVersion: "paperclip.chat-catalog.privileged.restart-service.v3" }];