Files
PaperClipAI/tests/runner-e2e/project-context-readback.spec.ts
T
DottaandPaperclip 62033b9994 fix(qa): schedule recovered cleanup promptly and wait for task panels (#21660)
## Thinking Path

> - Paperclip lets people manage AI agents and their saved work.
> - QA journeys check browser controls and the cleanup of owned agent
resources.
> - A recovered workspace queues sandbox destruction after its files are
saved.
> - The cleanup queue treated that first attempt as a retry and waited
five minutes.
> - Agent termination correctly waited for destruction, so QA cleanup
failed first.
> - This PR runs that first cleanup attempt promptly and keeps the
existing safety gates.
> - It also waits for task-panel transitions before the browser acts
again.

## Linked Issues or Issue Description

**What happened?**

The full scheduled QA smoke completed with 23 passed and 1 failed.
Stop/redirect passed all eleven behavior checks but failed cleanup. The
cancelled run had a saved workspace and a bound stop receipt before
agent termination. Its sandbox was destroyed about five minutes later.
The shared cleanup schedule applied the retry delay before the first
destruction attempt.

The browser regressions also found that the current panel helper can
consume all four actions while an opener remains visible during panel
mounting.

**Expected behavior**

A recovered workspace's first cleanup attempt runs on the next eligible
worker pass. A failed attempt retains normal backoff. Agent termination
still waits for completed resource cleanup. Task-panel navigation waits
for the next controls before it acts again.

**Steps to reproduce**

1. Queue recovered-workspace destruction after the cleanup worker has
become idle.
2. Read the next cleanup deadline and advance one normal worker pass.
Before this fix, the deadline is five minutes late and no teardown runs.
3. Open task document controls with a delayed side-panel transition.
Before the panel fix, both collapsed-panel controls fail.

Refs #19224 and #19292 for retaining stop proof during workspace
recovery. This change keeps the full cleanup requirement for agent
termination. Current master supplies the shared task-panel helper; this
branch uses it and retains additional browser regressions.

## What Changed

- Use one shared first-attempt predicate for the cleanup deadline, sweep
selection and ownership report. It now includes recovered workspace
cleanup bound to the same run.
- Preserve worker spacing, in-flight claims, ownership and saved-file
checks, retry delays and attempt limits.
- Wait for panel controls after opening the panel. Wait for the selected
tab or menu action to finish.
- Add real PostgreSQL cleanup regressions, keep the Chromium controls,
and document the cleanup timing.

## Verification

Tested on Linux x86_64, Node v25.9.0. Local commit
`7c8e0f12aa4b19aaf53669141ab3299ce76db963` and published head
`892c5dd4b4638796a138400d8bbe30aee19c71dd` have the same tree,
`d135a98bdff58e3320cdc83976ffe1cf47f48b66`.

- Red: both new real-PostgreSQL cleanup tests failed on the old code.
The deadline was five minutes late and the first normal sweep made zero
teardown calls.
- Green: 87 cleanup, ownership and lifecycle tests pass. The
restored-work case stays unconfirmed until the real cleanup worker
destroys the lease; failure still backs off and the worker becomes idle
again.
- Red after master integration: both delayed document-panel browser
cases failed. Green: all 18 Chromium support checks pass.
- 77 journey contract tests pass.
- Product E2E typecheck passes with the documented low-memory path. The
initial ordinary attempt was killed by the local memory limit and is not
counted as a pass.
- The only follow-up after the passing checks removes new code comments
to follow the contribution guide. Runtime and test behavior are
unchanged. Final-head [CI run
43714742904](https://github.com/paperclipai/paperclip/actions/runs/43714742904)
completed successfully at this exact head. All 63 PR checks are
terminal: 58 success, 2 neutral and 3 conditional skips; no failures or
pending checks. Typecheck, build, tests and the final verify gate pass.
Greptile and Paperclip Review both score this head 5/5 with no
actionable findings; both historical inline threads are resolved.
- Hosted QA recovery is still unverified. No extra model run, merge,
deployment or QA setting change was made.

## Risks

Recovered workspace destruction starts sooner. Existing producer,
file-preservation, ownership, claim and provider checks still decide
whether teardown is allowed. Failed attempts retain the existing
cooldown. Agent termination and purge gates are unchanged. The panel
helper waits for visible controls and still fails when controls or saved
values are absent.

The PostgreSQL integration uses a controlled provider boundary. It does
not prove a new live Daytona or deployed QA pass. That requires the
fixed revision on QA and a later normal scheduled smoke.

## Model Used

OpenAI GPT-6-based Codex, with tool use and code execution. The host
does not expose a more specific model ID or context-window size for this
run.

## 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 references)
- [x] My branch name describes the change 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

---------

Co-authored-by: Paperclip <noreply@paperclip.ing>
2026-11-15 08:52:49 -06:00

63 lines
5.1 KiB
TypeScript

import { expect, test, type Page } from "@playwright/test";
import { openProjectTaskThroughList, reopenProjectThroughList } from "./product-journeys/project-context-readback.js";
const origin = "https://project-context.test", projectName = "Journey QA project owned-campaign";
const taskTitle = "Journey QA project task owned-campaign", prompt = "I will review this task myself.";
const projectPath = "/QA/projects/owned-project-f962db91/issues", taskPath = "/QA/issues/QA-201";
const projectInput = { origin, issuePrefix: "QA", projectName, projectRef: "owned-project-f962db91" };
const taskInput = { origin, issuePrefix: "QA", projectName, taskTitle, prompt, taskRef: "QA-201" };
async function fixture(page: Page, changes: { missingProject?: boolean; wrongProject?: boolean; missingTask?: boolean; wrongTask?: boolean; wrongProperty?: boolean; sidePanel?: boolean } = {}) {
const requests: string[] = [];
await page.route(`${origin}/**`, async route => {
const path = new URL(route.request().url()).pathname;
requests.push(path);
// Layout can retain a hidden sidebar label. ProjectDetail renders its
// production InlineEditor as h2; IssueRow has an overlay link with sr-only text.
const sidebar = `<aside hidden><a href="/wrong-sidebar">${projectName}</a><a href="/wrong-task">${taskTitle}</a><p>${prompt}</p></aside>`;
const propertyValue = changes.wrongProperty ? "Other project" : projectName;
const panel = changes.sidePanel
? `<button aria-label="Toggle side panel" aria-pressed="false" onclick="const p=document.querySelector('#properties');p.removeAttribute('inert');p.removeAttribute('aria-hidden');p.style.width='300px';this.setAttribute('aria-pressed','true')">Open</button><aside id="properties" inert aria-hidden="true" style="width:0;overflow:hidden"><div style="width:300px"><div data-property-row><span data-property-label="Project">Project</span><div data-property-value>${propertyValue}</div></div></div></aside>`
: `<button onclick="document.querySelector('#properties').hidden=false;this.hidden=true">Show properties</button><section id="properties" hidden><div data-property-row><span data-property-label="Project">Project</span><div data-property-value>${propertyValue}</div></div></section>`;
const body = path === "/QA/projects" ? `${sidebar}<main id="main-content">${changes.missingProject ? "" : `<a href="${changes.wrongProject ? "/QA/projects/foreign/issues" : projectPath}"><span>${projectName}</span></a>`}</main>`
: path.includes("/projects/") ? `${sidebar}<main id="main-content"><h2>${projectName}</h2>${changes.missingTask ? "" : `<div data-issue-row-id="owned-task" style="position:relative;min-height:44px"><a style="position:absolute;inset:0" href="${changes.wrongTask ? "/QA/issues/QA-999" : taskPath}"><span class="sr-only">Open QA-201: ${taskTitle}</span></a><span>${taskTitle}</span></div>`}</main>`
: `${sidebar}<main id="main-content"><h1>${taskTitle}</h1><p>${prompt}</p>${panel}</main>`;
await route.fulfill({ contentType: "text/html", body: `<style>.sr-only{position:absolute;width:1px;height:1px;overflow:hidden;clip:rect(0,0,0,0)}</style>${body}` });
});
return requests;
}
test("reopens and reloads the owned project and task despite hidden duplicate sidebar labels", async ({ page }) => {
const requests = await fixture(page);
await reopenProjectThroughList({ ...projectInput, page });
await openProjectTaskThroughList({ ...taskInput, page });
expect(requests.filter(path => path === projectPath)).toHaveLength(2);
expect(requests.filter(path => path === taskPath)).toHaveLength(2);
await expect(page.locator("main#main-content [data-property-value]")).toContainText(projectName);
});
test("opens the current collapsed inert side panel before reading the saved project", async ({ page }) => {
await fixture(page, { sidePanel: true });
await page.goto(`${origin}${projectPath}`);
await openProjectTaskThroughList({ ...taskInput, page });
await expect(page.getByRole("button", { name: "Toggle side panel" })).toHaveAttribute("aria-pressed", "true");
});
for (const [name, changes, code] of [
["missing project list row", { missingProject: true }, "project_context_project_open_failed"],
["wrong project route with a matching label", { wrongProject: true }, "project_context_project_open_failed"],
] as const) test(`rejects ${name} with a closed stage code`, async ({ page }) => {
await fixture(page, changes);
await expect(reopenProjectThroughList({ ...projectInput, page })).rejects.toMatchObject({ outcome: "failed", code, message: code });
});
for (const [name, changes, code] of [
["missing task in the project", { missingTask: true }, "project_context_project_task_open_failed"],
["wrong task route with a matching label", { wrongTask: true }, "project_context_project_task_open_failed"],
["wrong saved project property", { wrongProperty: true }, "project_context_project_property_failed"],
] as const) test(`rejects ${name} with a closed stage code`, async ({ page }) => {
await fixture(page, changes);
await page.goto(`${origin}${projectPath}`);
await expect(openProjectTaskThroughList({ ...taskInput, page })).rejects.toMatchObject({ outcome: "failed", code, message: code });
});