mirror of
https://github.com/paperclipai/paperclip.git
synced 2026-10-07 07:23:08 +02:00
## Thinking Path > - Paperclip is the open source app people use to manage AI agents for work. > - Paid runner E2E tests verify the complete runner, control-plane, and UI path. > - A server restart could load a fresh task page while Playwright still waited on an unsettled Vite navigation lifecycle. > - The current server also ignored the isolated Vite cache path and skipped Vite's per-request HTML transform from the known-green runner snapshot. > - A one-cell paid run then exposed that download-artifact v8 removes the artifact-name directory for one pattern match. > - This pull request restores the Vite contract, proves a fresh document after restart, and accepts only the exact singleton artifact layout. > - The benefit is reliable local runner qualification without weaker UI, source, or artifact checks. ## Linked Issues or Issue Description Refs #12769 Refs #12828 Refs #12829 Refs #12833 **What happened?** The structured-question restart test could time out after the replacement server returned the task route and rendered the durable pending interaction. A focused one-cell rerun passed the paid test but failed aggregation because download-artifact v8 flattened its single artifact. **Expected behavior** The test must prove that a new document loaded after the server restart and that the same pending interaction survived. The aggregate must accept the exact documented singleton download layout while it continues to reject ambiguous or foreign artifacts. **Steps to reproduce** 1. Run the local ACPX-Codex structured-question restart-resume cell. 2. Restart the isolated server while the question waits for an answer. 3. Observe that the route and task UI can reload before Playwright settles the navigation promise. 4. Run a paid campaign with one selected cell. 5. Observe download-artifact v8 extract the sole campaign directory directly into the requested path. **Paperclip version or commit** The local campaign reproduced the navigation failure at `3586956a1b794b3cb4a9c5f57ffb7355e2b0c46d`. The one-cell aggregate reproduced the singleton layout at `f487660c0a06ba06ca140b57386f21ed39f13120`. This fix is `de4ccceff453a4b39436bf9a2eb8f03924151af7`. **Deployment mode** Local development and paid GitHub Actions. **Installation method** Built from source. **Agent adapter(s) involved** ACPX-Codex. The Vite and aggregate fixes are provider-neutral. ## What Changed - Prove a new post-restart browser document with an in-memory sentinel. - Tolerate only Playwright's navigation timeout before the exact UI and API checks run. - Honor `PAPERCLIP_VITE_CACHE_DIR` in the embedded Vite server. - Limit dependency optimization to the real UI entry. - Run `vite.transformIndexHtml` for each request while caching only the branded source template. - Accept download-artifact v8's flattened layout only for one expected cell with one unique recognized campaign. - Keep source SHA, source ref, workflow URL, execution ID, attempt, and unexpected-entry validation. - Add focused positive and negative regressions for Vite rendering and singleton artifact selection. ## Verification - Exact 45-cell local campaign https://github.com/paperclipai/paperclip/actions/runs/33888939013 passed 44/45. Its only failure was the post-restart navigation false negative fixed here. - Exact focused rerun https://github.com/paperclipai/paperclip/actions/runs/33891207957 passed the ACPX-Codex restart cell first attempt with the same session, two durable runs, the terminal marker once, and cleanup complete. - The focused Vite renderer suite passed 2/2 tests. - The focused rerun-artifact selector suite passed 12/12 tests. - Prettier and `git diff --check` passed. - An exact-head 45-cell confirmation is pending. ## Risks Low to medium risk. The Vite change restores known-green per-request transforms and isolated cache behavior. It can affect all development UI loads. The paid matrix and ordinary CI will verify that behavior. The singleton selector remains fail-closed for ambiguous layouts and validates every result source. ## Model Used OpenAI Codex, `gpt-5.6-sol`, extended reasoning, tool use, code execution, and parallel focused agents. ## 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 - [ ] 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
71 lines
2.1 KiB
TypeScript
71 lines
2.1 KiB
TypeScript
import fs from "node:fs";
|
|
import path from "node:path";
|
|
|
|
type ViteWatcherEvent = "add" | "change" | "unlink";
|
|
|
|
export interface ViteWatcherHost {
|
|
transformIndexHtml(url: string, html: string): Promise<string>;
|
|
watcher?: {
|
|
on?: (event: ViteWatcherEvent, listener: (file: string) => void) => unknown;
|
|
off?: (event: ViteWatcherEvent, listener: (file: string) => void) => unknown;
|
|
};
|
|
}
|
|
|
|
export interface CachedViteHtmlRenderer {
|
|
render(_url: string): Promise<string>;
|
|
dispose(): void;
|
|
}
|
|
|
|
const WATCHER_EVENTS: ViteWatcherEvent[] = ["add", "change", "unlink"];
|
|
|
|
export function createCachedViteHtmlRenderer(opts: {
|
|
vite: ViteWatcherHost;
|
|
uiRoot: string;
|
|
brandHtml?: (html: string) => string;
|
|
}): CachedViteHtmlRenderer {
|
|
const uiRoot = path.resolve(opts.uiRoot);
|
|
const templatePath = path.resolve(uiRoot, "index.html");
|
|
const brandHtml = opts.brandHtml ?? ((html: string) => html);
|
|
let cachedTemplate: string | null = null;
|
|
|
|
function loadTemplate(): string {
|
|
if (cachedTemplate === null) {
|
|
const rawTemplate = fs.readFileSync(templatePath, "utf-8");
|
|
cachedTemplate = brandHtml(rawTemplate);
|
|
}
|
|
return cachedTemplate;
|
|
}
|
|
|
|
function invalidate(): void {
|
|
cachedTemplate = null;
|
|
}
|
|
|
|
function onWatchEvent(filePath: string): void {
|
|
const resolvedPath = path.resolve(filePath);
|
|
if (resolvedPath === templatePath) {
|
|
invalidate();
|
|
}
|
|
}
|
|
|
|
for (const eventName of WATCHER_EVENTS) {
|
|
opts.vite.watcher?.on?.(eventName, onWatchEvent);
|
|
}
|
|
|
|
return {
|
|
render(url): Promise<string> {
|
|
// Vite's transform does more than inject the dev client and React
|
|
// refresh preamble. It also keeps entry-module timestamps aligned with
|
|
// the module graph after an HMR invalidation. Serving the raw entry tag
|
|
// can otherwise evaluate main.tsx twice (unversioned + timestamped),
|
|
// creating two React roots in the same container.
|
|
return opts.vite.transformIndexHtml(url, loadTemplate());
|
|
},
|
|
|
|
dispose(): void {
|
|
for (const eventName of WATCHER_EVENTS) {
|
|
opts.vite.watcher?.off?.(eventName, onWatchEvent);
|
|
}
|
|
},
|
|
};
|
|
}
|