mirror of
https://github.com/paperclipai/paperclip.git
synced 2026-11-12 06:10:44 +01:00
## Thinking Path
> - Paperclip is the open source app people use to manage AI agents for
work
> - The chat evaluation lane runs each chat case in a paid runner and
keeps the private evidence of each attempt in a bounded private archive
> - A failed attempt keeps its Playwright trace and video, and the
bundle has a 256 MB allowance
> - Playwright's HTML reporter copies each attachment into
`html-report/data/<sha1>.<ext>`, and the same bytes also stay in
`playwright-output/`
> - The bundle holds the original tree and the packaged tree, so a 30 MB
trace used about 125 MB of the allowance before the blob report copies
> - Large failed attempts went over the allowance, and then all of their
private evidence was lost
> - This pull request removes the `playwright-output/` copy only when
the HTML report holds the identical bytes
> - A second gap lost the whole merged campaign report of failed cells:
the report copied trace viewer font, SVG and manifest files to a place
where the trusted seal refuses them
> - This pull request stops that copy, and it names a refused report
carrier with a closed category
> - The benefit is that large failed attempts keep their evidence, the
merged report is kept, and the HTML report and its trace viewer still
open the trace
## Linked Issues or Issue Description
**What happened**
Failed chat evaluation attempts with large Playwright traces lost all of
their private evidence. The bundle went over the 256 MB private evidence
allowance. For example, the failed `tasks.organize-open-work` cell made
a 254 MB bundle. That bundle held the same 30.7 MB trace four times
(`playwright-output/.../trace.zip` and `html-report/data/<sha1>.zip`, in
both the original tree and the packaged tree), plus two blob report
copies. Larger traces went over the limit, and then the transfer refused
the whole bundle.
Also, the merged campaign report of a failed cell was refused with
`refusal: unsupported-packaged-evidence-carrier` (for example
`runs-adapters.inspect-failed-run`, run 42431162923). The cell's
evidence manifest lists its trace viewer files
`html-report/trace/codicon.*.ttf`, `playwright-logo.svg` and
`manifest.webmanifest`. `report.ts` copied them to
`normalized/evidence/<id>/attempt-1/html-report/trace/`. The
generated-report seal accepts trace viewer files only under
`html/trace/`, so it refused these three files and lost the whole
report. I reproduced this from the retained cell archive: a merge of its
blob report passes the seal rule, and the three normalized copies are
the only files that fail it.
**Expected behavior**
A failed attempt keeps its trace, and the trace uses as little of the
allowance as possible. The HTML report and the trace viewer still open
the trace for a person who downloads the bundle. The merged report of a
failed cell is kept. If the seal refuses a carrier, the refusal names
its category, not its path. No privacy, integrity or size check changes.
**Steps to reproduce**
1. Dispatch `runner-full-stack-e2e.yml` with `cadence=manual` for a
private chat case that fails with a large trace, for example
`chat-features.runner-opencode.local.tasks.organize-open-work`.
2. Download `manual-cell-<sha256(executionId)>.zip` from the private
history bucket.
3. List the archive. The trace bytes are in `playwright-output/` and in
`html-report/data/` in both `originals/` and `sealed-results/`.
4. For the report refusal: look at the "Retain complete manual merged
evidence only in restricted storage" step of the same run. It prints
`refusal: unsupported-packaged-evidence-carrier` and no
`manual-report.zip` is retained.
## What Changed
- Add `tests/runner-e2e/private-report-copies.ts` with
`dropDuplicatePlaywrightOutput`. It removes a `playwright-output/` file
only when `html-report/data/<sha1 of content><ext>` is a regular file
(not a symlink) with the same size and the same SHA-256. It writes the
removed paths, their kept paths and digests to
`snapshots/playwright-output-copies.json`.
- The function does nothing when the cell has a framework JSON report
(`framework-report.json` or `snapshots/playwright-framework.json`),
because that report registers `playwright-output/` attachments by path.
It also does nothing when `playwright-output`, `html-report` or
`html-report/data` is missing or is a symlink.
- Call it in the private manual branch of `tests/runner-e2e/launch.ts`,
before packaging and before both seals. Both evidence trees then keep
one HTML report copy of each trace and video.
- The HTML report, its trace viewer assets and the blob report do not
change.
- `tests/runner-e2e/report.ts` does not stage a cell file into
`normalized/evidence/` when its type is one the generated-report seal
refuses (the same `isStandardEvidenceFile("html-report/...")` rule). The
merged report has its own authenticated trace viewer under
`html/trace/`. The cell archive still keeps the files.
- `tests/runner-e2e/manual-private-transfer.ts` adds
`assertGeneratedReportCarriers`, which runs before the report seal. It
throws a fixed message per closed category (`font`, `svg`,
`webmanifest`, `image`, `source map`, `no extension`, `other`, `trace
viewer asset`, `trace viewer bytes`), so the refusal line names, for
example, `unsupported-generated-report-carrier-font`. It never names a
path, and the seal stays the authority.
- No change to the target-checked trusted files
(`manual-private-handoff.ts`, `manual-private-retention.ts`,
`manual-private-report-assets.ts`), so candidate branches do not need an
update. No change to the limits or the secret scans.
## Verification
- `vitest run --config tests/runner-e2e/vitest.config.ts
tests/runner-e2e/private-report-copies.test.ts
tests/runner-e2e/manual-private-cell-report-assets.test.ts
tests/runner-e2e/private-framework-report.test.ts
tests/runner-e2e/manual-private-handoff.test.ts`: 79 passed.
- The new tests use a real failed Playwright run with the HTML, JUnit
and blob reporters and a real retained trace. They show these things:
- Only the duplicate `playwright-output/` files are removed. The HTML
report and blob report bytes do not change.
- The deduplicated cell passes `packageEvidence`,
`sealStandardOriginalEvidence`, `sealManualResultEvidence`, the trusted
`validateSealedOriginals` and `validateSealedInventory`, the strict
archive pack and unpack, and `stageSealedPrivateCell`.
- A tampered or symlinked HTML report copy keeps the original file.
- Framework JSON cells and symlinked data directories are not changed.
- `vitest run --config tests/runner-e2e/vitest.config.ts manual-private
private-report private-refusal private-framework generated-report
report`: 25 files, 311 passed.
- `generated-report-carriers.test.ts` shows each refused carrier gets
its closed category code, the code has no path, and the real seal
refuses the same tree. `report.test.ts` shows the font, SVG and manifest
are not staged and the other files are.
- A new test runs the real launcher private branch from `launch.ts`. It
shows that the sealed originals keep one trace copy, in
`html-report/data/`.
- Live run: I applied the commit to a branch from
`chat-eval/master-candidate` (`chat-eval/case-evidence-dedupe`) and
dispatched
`chat-features.runner-opencode.local.tasks.organize-open-work` (run
42432263920). I will add the bundle size result in a comment.
## Risks
- Low risk. The change runs only in the private manual evidence branch.
It removes a file only after a full content comparison with the kept
copy. If a check fails, the file stays.
- A person who wants the trace must open `html-report/data/<sha1>.zip`
(the HTML report links to it), not `playwright-output/<test>/trace.zip`.
The receipt in `snapshots/playwright-output-copies.json` names the new
location.
- `report.ts` and `manual-private-transfer.ts` run from the master
checkout in the report job, so the report fix takes effect only after
merge. The normalized per-cell HTML report copy no longer has the viewer
font, logo and manifest. The merged report under `html/` and the cell
archive keep a complete viewer.
- The blob report still has a compressed copy of the trace, and the
bundle still holds the original and the packaged tree. A trace over
about 60 MB can still go over the allowance. This change does not fix
that case.
> 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`), run in Claude Code with
tool use (shell, file editing, GitHub CLI and AWS CLI).
## 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
- [x] All Paperclip CI gates are green
- [x] 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>
101 lines
5.1 KiB
TypeScript
101 lines
5.1 KiB
TypeScript
import { createHash } from "node:crypto";
|
|
import { createReadStream } from "node:fs";
|
|
import { lstat, mkdir, readdir, realpath, rmdir, unlink, writeFile } from "node:fs/promises";
|
|
import path from "node:path";
|
|
|
|
/** Records which Playwright output files were dropped because the per-cell HTML
|
|
* report already holds the identical bytes. It names paths and digests only. */
|
|
export const PRIVATE_REPORT_COPIES_RECEIPT = "snapshots/playwright-output-copies.json";
|
|
|
|
export interface DroppedReportCopy { path: string; keptAt: string; bytes: number; sha256: string }
|
|
|
|
const outputDirectory = "playwright-output";
|
|
const dataDirectory = "html-report/data";
|
|
const entryAllowance = 4096;
|
|
const depthAllowance = 16;
|
|
// The JSON framework reporter registers playwright-output attachments by path;
|
|
// those trees have no HTML report copy and must stay untouched.
|
|
const frameworkReports = ["framework-report.json", "snapshots/playwright-framework.json"];
|
|
|
|
async function entry(file: string) {
|
|
return lstat(file).catch((error: NodeJS.ErrnoException) => {
|
|
if (error.code === "ENOENT") return undefined;
|
|
throw error;
|
|
});
|
|
}
|
|
|
|
async function digests(file: string) {
|
|
const sha1 = createHash("sha1"), sha256 = createHash("sha256");
|
|
let bytes = 0;
|
|
for await (const chunk of createReadStream(file, { flags: "r" }) as AsyncIterable<Buffer>) {
|
|
sha1.update(chunk); sha256.update(chunk); bytes += chunk.length;
|
|
}
|
|
return { sha1: sha1.digest("hex"), sha256: sha256.digest("hex"), bytes };
|
|
}
|
|
|
|
/**
|
|
* Playwright's HTML reporter copies every test attachment, including the failure
|
|
* trace and video, into html-report/data/<sha1 of content><extension>. The same
|
|
* bytes also stay in playwright-output, so a retained failure stores its largest
|
|
* files twice before the blob report adds a third (compressed) copy.
|
|
*
|
|
* This removes a playwright-output file only when the HTML report holds an
|
|
* independently verified, byte-identical regular file under the content-derived
|
|
* name. The HTML report and its trace viewer keep working, the blob report is
|
|
* untouched, and every remaining file still passes the normal packaging,
|
|
* sealing and transfer checks. Anything unexpected leaves the file in place.
|
|
*/
|
|
export async function dropDuplicatePlaywrightOutput(cellDirectory: string): Promise<DroppedReportCopy[]> {
|
|
const root = await realpath(cellDirectory);
|
|
const rootInfo = await lstat(cellDirectory);
|
|
if (!rootInfo.isDirectory() || rootInfo.isSymbolicLink() || root !== path.resolve(cellDirectory))
|
|
throw new Error("Invalid private report cell directory");
|
|
for (const relative of frameworkReports) if (await entry(path.join(root, relative))) return [];
|
|
const output = path.join(root, outputDirectory), data = path.join(root, dataDirectory);
|
|
for (const directory of [output, path.join(root, "html-report"), data]) {
|
|
const info = await entry(directory);
|
|
if (!info || !info.isDirectory() || info.isSymbolicLink()) return [];
|
|
}
|
|
const dropped: DroppedReportCopy[] = [];
|
|
let visited = 0;
|
|
async function visit(relative: string, depth: number): Promise<boolean> {
|
|
if (depth > depthAllowance) return false;
|
|
const directory = path.join(root, relative);
|
|
let remaining = 0;
|
|
for (const item of await readdir(directory, { withFileTypes: true })) {
|
|
if (++visited > entryAllowance) throw new Error("Playwright output exceeds entry allowance");
|
|
const name = `${relative}/${item.name}`, file = path.join(root, name);
|
|
if (item.isDirectory() && !item.isSymbolicLink()) {
|
|
if (await visit(name, depth + 1)) await rmdir(file); else remaining++;
|
|
continue;
|
|
}
|
|
remaining++;
|
|
if (!item.isFile() || item.isSymbolicLink()) continue;
|
|
const before = await lstat(file);
|
|
if (!before.isFile() || before.isSymbolicLink() || before.size === 0) continue;
|
|
const extension = path.extname(item.name);
|
|
if (!/^\.[A-Za-z0-9]{1,16}$/.test(extension)) continue;
|
|
const source = await digests(file);
|
|
const keptAt = `${dataDirectory}/${source.sha1}${extension}`, kept = path.join(root, keptAt);
|
|
const keptInfo = await entry(kept);
|
|
if (!keptInfo || !keptInfo.isFile() || keptInfo.isSymbolicLink() || keptInfo.size !== before.size || source.bytes !== before.size) continue;
|
|
const copy = await digests(kept);
|
|
const after = await lstat(file);
|
|
if (copy.sha256 !== source.sha256 || copy.bytes !== source.bytes || after.ino !== before.ino
|
|
|| after.size !== before.size || after.mtimeMs !== before.mtimeMs) continue;
|
|
await unlink(file);
|
|
remaining--;
|
|
dropped.push({ path: name, keptAt, bytes: source.bytes, sha256: source.sha256 });
|
|
}
|
|
return remaining === 0;
|
|
}
|
|
await visit(outputDirectory, 0);
|
|
if (!dropped.length) return dropped;
|
|
dropped.sort((a, b) => a.path.localeCompare(b.path));
|
|
const receipt = path.join(root, PRIVATE_REPORT_COPIES_RECEIPT);
|
|
await mkdir(path.dirname(receipt), { recursive: true, mode: 0o700 });
|
|
await writeFile(receipt, `${JSON.stringify({ schema: "paperclip.private-report-copies/v1",
|
|
meaning: "playwright-output files removed because html-report/data holds identical bytes", dropped }, null, 2)}\n`, { mode: 0o600, flag: "wx" });
|
|
return dropped;
|
|
}
|