Files
PaperClipAI/tests/perf/issue-detail/layout-stability.spec.ts
T
DottaandPaperclip d38cdf261a perf(ui): speed up Tasks and Inbox startup (#18492)
## Thinking Path

> - Paperclip is the open source app people use to manage AI agents for
work.
> - Tasks and Inbox are the main entry points for that work.
> - Earlier changes made their data reads and row counts smaller.
> - Those changes remain, but shared controls now pull in the whole
task-detail bundle.
> - A cold open can also read a remembered organization before selecting
the one in the URL.
> - This pull request separates collection code and selects the
addressed organization first.
> - It warms task code after collection paint, so the next task open
stays fast.

## Linked Issues or Issue Description

Refs #17756, #18323, #16849, #17041, #17983, #17960, #18461.

**What happened?**

Tasks and Inbox still use their optimized index reads and row budgets.
However, small shared controls and hooks were placed in the task-detail
chunk. A collection had to download that whole chunk. The HTML also
preloaded it on every route. The original production profile loaded
about 6.5 MB of decoded JavaScript before useful rows, or 1.9 MB
transferred with compression.

Company bootstrap could select a different remembered organization
before Layout selected the URL's organization. This started unnecessary
company reads. A retained multi-company browser fixture reproduced two
attention-count requests for different companies.

**Expected behavior**

Show correctly scoped, stable collection rows without waiting for
task-detail code. Keep compact reads, bounded rendering, direct task
preloading, immediate New Task input, and fast follow-on navigation.

**Steps to reproduce**

1. Use a production UI build with Coordinator enabled and two active
organizations.
2. Remember one organization, then cold-open Tasks or Mine in the other.
3. Inspect startup script and company requests before the first useful
row.

The baseline UI revision is `91fdf02e95`. This is a UI change. It has no
API, schema, migration, or authorization changes.

## What Changed

- Group the static collection dependency trees above the task-detail
group. Keep the existing startup and task grouping strategy.
- Preload task detail and its static dependency closure early on direct
task and agent-chat URLs. Keep collection aliases out of that preload.
- Fetch the immutable task chunk at low priority after a collection
paints, or on a same-origin task-link hint. After a successful immutable
response is fully read, module-preload the cached chunk so it can
compile without executing. A failed HTTP probe skips module preload.
- Prefer an addressed active organization during bootstrap. Preserve
manual selection, archived-company handling, and account-scoped company
lists.
- Preserve a task reading anchor when a programmatic scroll event
reports an unchanged offset during restore reflow. Strengthen the Back
journey to wait for a completed collection navigation.
- Add production-browser checks for delayed indexes, correct company
scope, stable row geometry, failed speculation, and early direct-task
preload. Update collection verification notes and the feature map.

## Verification

Final source: `e402ab7fc6`; baseline UI: `91fdf02e95`.

- All **234 focused unit cases** and **44 production-browser journeys**
passed on the final source: 33 task journeys and 11 collection journeys.
Coverage includes compact history, saved cards, draft persistence,
avatar continuity, failed-probe recovery, delayed data, pagination, deep
links, desktop/mobile and reading-position restoration through Back.
Desktop and mobile screenshots were inspected.
- Workspace typecheck, full production build, map checks, token gates
and diff checks passed. The default local `pnpm test:run` still stops
before executing tests because the existing chat-test line selector
reports `No test found` (1,816 skipped). This is not a passed full local
test suite. Focused tests and remote CI remain separate evidence.
- Greptile reviewed the exact final commit at **5/5**, with zero open
review threads. Final code CI passed. The complete check inventory is
**55 successful, 3 skipped, 1 neutral**. The neutral result is the
separate Paperclip Review: its agent finished without completing an
assessment, so it is not a passing review score.

Five alternating baseline/candidate pairs per scenario, Chromium
151.0.7922.34, 1440×900, 4× CPU, 50ms latency, approximately 9Mbps down
/ 1.5Mbps up. Cold cases use fresh browser contexts with normal cache
writes enabled; warm cases use the same context and normal application
query cache. Both previews use the server's immutable hashed-asset cache
policy and uncached HTML, with real local feature settings and no
request interception. All task-owned builds and suites were stopped
during timing; other host activity was uncontrolled. Readiness requires
useful rows and editable search, or the readable task thread and
editable composer, followed by two animation frames.

| Journey | Baseline median (range) | PR median (range) | Median paired
saving |
| --- | --- | --- | --- |
| Cold Tasks | 3239 ms (3189–3333) | 2545 ms (2441–2682) | +752 ms |
| Cold Inbox | 3207 ms (3203–3268) | 2679 ms (2502–3062) | +541 ms |
| Warm Inbox | 717 ms (701–917) | 760 ms (745–768) | -47 ms |
| Warm Tasks | 1150 ms (1126–1207) | 1136 ms (1119–1174) | +18 ms |
| First task click | 943 ms (932–1008) | 1007 ms (976–1098) | -74 ms |
| Back to Tasks | 584 ms (568–617) | 566 ms (559–575) | +10 ms |
| Cold direct task control | 3389 ms (3377–3402) | 3415 ms (3395–3896) |
-13 ms |

All five pairs improved for each cold collection. The signed saving is
baseline minus candidate for each pair; it is distinct from the
difference of medians. Warm navigation is broadly similar. First task
click was 74ms slower by median paired difference. Direct-task median
paired difference was 13ms slower, with one slower 3.90s candidate
sample retained in the range; this is not a claimed direct-task speedup.

Completed script transfers by collection readiness fell from about
**1.91MB to 1.14MB** (Tasks), and **1.90MB to 1.14MB** (Inbox). Task
code warms after rows paint. At the test bandwidth, the removed 0.77MB
critical transfer represents roughly 0.65s of download time; CPU and
network overlap, so their savings are not added. Unthrottled loopback
API control medians stayed about 17–18ms in both variants. All 30 cold
samples had zero browser errors.

Rejected experiments remain separate: automatic splitting produced over
200 startup requests; disabling recursive grouping slowed direct tasks;
HTTP-only warming improved collection startup but slowed first task
opens. The final correction preloads direct dependencies and compiles
successfully cached code after paint. Routing disables HTTP caching, so
intercepted runs were kept as diagnostic evidence rather than used for
warm-cache acceptance; see [Playwright's cache
behavior](https://playwright.dev/docs/api/class-page#page-route). Vite
preview's default asset `no-cache` policy was also corrected to match
the shipped server before final measurement.


## Risks

- Bundle placement affects shared consumers. Browser checks cover
collections and task navigation; the full PR checks also cover other
routes.
- Code warming still transfers the task chunk if the user stays on a
populated collection. It moves that download past first paint and does
not execute it. This is a startup latency improvement, not a claim that
all eventual bytes disappear.
- A direct click before warming finishes still loads code on demand.
Direct task and chat URLs retain early module preload.
- Local browser evidence does not establish a deployed staging speedup.
This PR does not merge or deploy itself.

## Model Used

OpenAI GPT-6 (Codex), with reasoning, tool use and local code execution.
The context-window size is not exposed in this environment.

## 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 the relevant tests locally and they pass (234 unit
cases and 44 browser journeys; the full-command limitation is documented
above)
- [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 code CI gates are green (the separate Paperclip Review is
neutral because its agent did not complete an assessment)
- [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-10-31 22:12:41 -05:00

339 lines
20 KiB
TypeScript

import fs from "node:fs/promises";
import { expect, test, type Page } from "@playwright/test";
test.setTimeout(90_000);
test.use({ video: "on", trace: "retain-on-failure", viewport: { width: 1440, height: 900 } });
let prefix: string;
let issue: { id: string; identifier: string };
let other: { id: string; identifier: string };
let draftIssue: { id: string; identifier: string };
let oldestCommentId: string;
test.beforeAll(async ({ request }) => {
const company = await (await request.post("/api/companies", { data: { name: `Layout acceptance ${Date.now()}` } })).json();
prefix = company.issuePrefix;
const createIssue = async (title: string) => {
const response = await request.post(`/api/companies/${company.id}/issues`, {
data: { title, status: "backlog", description: "A rich task with a long conversation.\n\n".repeat(15) },
});
expect(response.ok(), await response.text()).toBeTruthy();
return response.json();
};
issue = await createIssue("Stable conversation acceptance");
other = await createIssue("Rapid navigation destination");
draftIssue = await createIssue("Draft stability acceptance");
for (let i = 0; i < 160; i++) {
const response = await request.post(`/api/issues/${issue.id}/comments`, {
data: { body: `## Historical message ${i}\n\n${"Long Markdown with **emphasis**, detail, and enough text to wrap across several lines. ".repeat(8)}\n\n\`\`\`js\nconsole.log(${i});\n\`\`\`\n\n| State | Result |\n|---|---|\n| Complete | Stable |${i === 159 ? `\n\n[Read the oldest message](#comment-${oldestCommentId})` : ""}` },
});
expect(response.ok()).toBeTruthy();
if (i === 0) oldestCommentId = (await response.json()).id;
}
const interaction = await (await request.post(`/api/issues/${issue.id}/interactions`, {
data: { kind: "request_confirmation", title: "Geometry review", payload: { version: 1, prompt: "Inspect the conversation." }, continuationPolicy: "none" },
})).json();
await request.post(`/api/issues/${issue.id}/interactions/${interaction.id}/accept`, { data: {} });
});
async function ready(page: Page) {
await expect(page.getByTestId("task-chat-thread").locator(':scope > [aria-busy="false"]')).toBeVisible({ timeout: 90_000 });
}
async function installMeasurements(page: Page) {
await page.addInitScript(() => {
const evidence = { frames: [] as unknown[], shifts: [] as unknown[] };
Object.assign(window, { taskLayoutEvidence: evidence });
new PerformanceObserver((list) => {
evidence.shifts.push(...list.getEntries().map((e) => e.toJSON()));
}).observe({ type: "layout-shift", buffered: true });
const sample = () => {
const scroller = document.querySelector('[data-testid="task-chat-scroller"]');
const busy = document.querySelector('[data-testid="task-chat-thread"] > [aria-busy]');
if (scroller) {
const viewport = scroller.getBoundingClientRect();
const row = [...scroller.querySelectorAll<HTMLElement>("[data-thread-anchor]")].find((el) => el.getBoundingClientRect().bottom > viewport.top);
evidence.frames.push({ time: performance.now(), busy: busy?.getAttribute("aria-busy"), top: scroller.scrollTop, width: viewport.width, fonts: document.fonts.status, rows: scroller.querySelectorAll("[data-thread-anchor]").length, height: scroller.scrollHeight, anchor: row?.dataset.threadAnchor, offset: row ? row.getBoundingClientRect().top - viewport.top : null });
}
requestAnimationFrame(sample);
};
requestAnimationFrame(sample);
});
}
test.afterEach(async ({ page }, info) => {
const evidence = await page.evaluate(() => (window as unknown as { taskLayoutEvidence?: unknown }).taskLayoutEvidence).catch(() => null);
if (evidence) {
const file = info.outputPath("layout.json");
await fs.writeFile(file, JSON.stringify(evidence));
await info.attach("layout-frames-and-shifts", { path: file, contentType: "application/json" });
}
});
test("Inbox click reveals once after reordered initial responses; refresh retains rows", async ({ page }) => {
await installMeasurements(page);
await page.goto(`/${prefix}/inbox/all`);
const link = page.getByRole("link", { name: new RegExp(`Open ${issue.identifier}:`) });
await expect(link).toBeVisible({ timeout: 90_000 });
let release!: () => void;
const held = new Promise<void>((resolve) => { release = resolve; });
await page.route("**/api/issues/*/comments?*", async (route) => { await held; await route.continue(); });
await link.click();
await expect(page.getByTestId("task-chat-thread").locator(':scope > [aria-busy="true"]')).toBeVisible();
await expect(page.getByText("Historical message 159", { exact: true })).not.toBeVisible();
release();
await ready(page);
const scroller = page.getByTestId("task-chat-scroller");
await expect.poll(() => scroller.evaluate((el) => el.scrollHeight - el.scrollTop - el.clientHeight)).toBeLessThan(2);
await page.waitForTimeout(1200);
const frames = await page.evaluate(() => (window as unknown as { taskLayoutEvidence: { frames: { busy: string; top: number; anchor: string; offset: number }[] } }).taskLayoutEvidence.frames);
const visibleFrames = frames.filter((frame) => frame.busy === "false");
expect(visibleFrames.length).toBeGreaterThan(2);
expect(new Set(visibleFrames.map((f) => f.anchor)).size).toBe(1);
expect(Math.max(...visibleFrames.map((f) => f.offset)) - Math.min(...visibleFrames.map((f) => f.offset))).toBeLessThanOrEqual(2);
});
test("reading anchor survives late media, composer resizing, older history and browser Back", async ({ page }) => {
await page.route("**/api/workspace-preferences/me", async route => {
const response = await route.fetch();
await route.fulfill({ json: { ...await response.json(), coordinatorWorkspaceEnabled: false } });
});
await installMeasurements(page);
await page.goto(`/${prefix}/issues/${issue.identifier}`);
await ready(page);
await expect(page.getByRole("button", { name: "Hide properties", exact: true })).toBeVisible();
const scroller = page.getByTestId("task-chat-scroller");
await page.getByRole("button", { name: "More messages", exact: true }).click();
await expect(page.getByText("Historical message 10", { exact: true })).toBeAttached();
await scroller.evaluate((el) => { el.scrollTop = el.scrollHeight / 2; });
await page.waitForTimeout(100);
const anchor = await scroller.evaluate((el) => {
const top = el.getBoundingClientRect().top;
const row = [...el.querySelectorAll<HTMLElement>("[data-thread-anchor]")].find((r) => r.getBoundingClientRect().bottom > top)!;
return { id: row.dataset.threadAnchor!, top: row.getBoundingClientRect().top - top };
});
// Deterministic late media sizing above the reader, after the initial data
// has arrived. This exercises the actual route's ResizeObserver owner.
await scroller.evaluate((el) => {
const media = document.createElement("div");
media.style.height = "360px";
el.querySelector("[data-thread-anchor]")!.append(media);
});
const offset = () => scroller.evaluate((el, id) => {
const row = [...el.querySelectorAll<HTMLElement>("[data-thread-anchor]")].find((r) => r.dataset.threadAnchor === id)!;
return row.getBoundingClientRect().top - el.getBoundingClientRect().top;
}, anchor.id);
await expect.poll(async () => Math.abs(await offset() - anchor.top)).toBeLessThanOrEqual(2);
await page.getByRole("button", { name: "Hide properties", exact: true }).click();
await page.waitForTimeout(300);
await expect.poll(async () => Math.abs(await offset() - anchor.top)).toBeLessThanOrEqual(2);
await page.getByRole("button", { name: "Show properties", exact: true }).click();
await page.waitForTimeout(300);
await expect.poll(async () => Math.abs(await offset() - anchor.top)).toBeLessThanOrEqual(2);
await page.locator('[contenteditable="true"]').last().fill("A multiline draft\n".repeat(8));
await expect.poll(async () => Math.abs(await offset() - anchor.top)).toBeLessThanOrEqual(2);
// Invoke the real older-history control without scrolling it into view.
await page.getByRole("button", { name: /Load earlier/ }).evaluate((el) => (el as HTMLButtonElement).click());
await expect(page.getByText("Historical message 0", { exact: true })).toBeAttached();
await expect.poll(async () => Math.abs(await offset() - anchor.top)).toBeLessThanOrEqual(2);
await page.getByRole("link", { name: "Tasks", exact: true }).first().click();
await page.waitForURL(`**/${prefix}/issues`);
await expect(page.getByRole("main").getByRole("textbox", { name: "Search tasks", exact: true })).toBeEditable();
await expect(page.getByTestId("task-chat-thread")).toHaveCount(0);
await page.goBack();
await ready(page);
await expect.poll(async () => Math.abs(await offset() - anchor.top)).toBeLessThanOrEqual(2);
await page.getByRole("button", { name: "Scroll to latest" }).click();
await page.locator('[contenteditable="true"]').last().fill("Change the composer during the glide\n".repeat(5));
await expect.poll(() => scroller.evaluate((el) => el.scrollHeight - el.scrollTop - el.clientHeight)).toBeLessThan(2);
});
test("explicit comment links resolve older pages before revealing at the target", async ({ page }) => {
await page.goto(`/${prefix}/issues/${issue.identifier}#comment-${oldestCommentId}`);
await ready(page);
const target = page.locator(`[id="comment-${oldestCommentId}"]`);
await expect(target).toBeVisible();
await expect.poll(async () => {
const row = await target.boundingBox();
const viewport = await page.getByTestId("task-chat-scroller").boundingBox();
return Math.abs(row!.y - viewport!.y);
}).toBeLessThanOrEqual(2);
});
test("a loaded comment target positions after the reveal deadline when live-run metadata stalls", async ({ page }) => {
let release!: () => void;
let metadataReads = 0;
const held = new Promise<void>(resolve => { release = resolve; });
await page.route("**/api/issues/*/live-runs", async route => { metadataReads++; await held; await route.continue().catch(() => {}); });
try {
await page.goto(`/${prefix}/issues/${issue.identifier}#comment-${oldestCommentId}`);
await expect(page.getByTestId("task-chat-thread").locator(':scope > [aria-busy="false"]')).toBeVisible({ timeout: 20_000 });
expect(metadataReads).toBeGreaterThan(0);
await expect(page.getByText("Some task history is still loading.", { exact: true })).toBeVisible();
const target = page.locator(`[id="comment-${oldestCommentId}"]`);
await expect(target).toBeVisible();
await expect.poll(() => target.evaluate(el => Math.abs(el.getBoundingClientRect().top - document.querySelector('[data-testid="task-chat-scroller"]')!.getBoundingClientRect().top)))
.toBeLessThanOrEqual(2);
await expect(page.getByTestId("task-chat-composer-stack").locator('[contenteditable="true"]')).toBeVisible();
} finally { release(); }
});
test("a late linked comment positions after the reveal deadline without losing the draft", async ({ page }) => {
let release!: () => void;
const held = new Promise<void>(resolve => { release = resolve; });
await page.route(`**/api/issues/*/comments/${oldestCommentId}`, async route => { await held; await route.continue().catch(() => {}); });
try {
await page.goto(`/${prefix}/issues/${issue.identifier}#comment-${oldestCommentId}`);
await expect(page.getByTestId("task-chat-thread").locator(':scope > [aria-busy="false"]')).toBeVisible({ timeout: 20_000 });
const target = page.locator(`[id="comment-${oldestCommentId}"]`);
await expect(target).toHaveCount(0);
const editor = page.getByTestId("task-chat-composer-stack").locator('[contenteditable="true"]');
await editor.fill("Keep this draft while the linked comment loads.");
const originalEditor = await editor.elementHandle();
release();
await expect(target).toBeVisible();
await expect.poll(() => target.evaluate(el => Math.abs(el.getBoundingClientRect().top - document.querySelector('[data-testid="task-chat-scroller"]')!.getBoundingClientRect().top)))
.toBeLessThanOrEqual(2);
await expect(editor).toHaveText("Keep this draft while the linked comment loads.");
expect(await originalEditor!.evaluate(element => element.isConnected)).toBe(true);
} finally { release(); }
});
test("a draft survives background task refresh, reload, and one persisted reply", async ({ page, request }) => {
await page.goto(`/${prefix}/issues/${draftIssue.identifier}`);
await ready(page);
const editor = page.getByTestId("task-chat-composer-stack").locator('[contenteditable="true"]');
const draft = "This draft survives task refresh and is submitted exactly once.";
await editor.fill(draft);
await editor.evaluate((el) => { el.setAttribute("data-draft-mount-proof", "retained"); });
await expect.poll(() => page.evaluate((id) => localStorage.getItem(`paperclip:issue-comment-draft:${id}`), draftIssue.id)).toBe(draft);
let release!: () => void;
const held = new Promise<void>((resolve) => { release = resolve; });
let refreshing = false;
await page.route(/\/api\/issues\/[^/?]+$/, async (route) => {
if (route.request().method() === "GET") {
refreshing = true;
await held;
}
await route.continue();
});
const title = "Draft stability after background update";
const updated = await request.patch(`/api/issues/${draftIssue.id}`, { data: { title } });
expect(updated.ok(), await updated.text()).toBeTruthy();
try {
await expect.poll(() => refreshing).toBe(true);
await expect(page.getByTestId("task-chat-history-loading")).toHaveCount(0);
await expect(editor).toHaveAttribute("data-draft-mount-proof", "retained");
await expect(editor).toHaveText(draft);
} finally {
release();
}
await expect(page.getByText(title, { exact: true }).first()).toBeVisible();
await expect(editor).toHaveAttribute("data-draft-mount-proof", "retained");
await page.reload();
await ready(page);
await expect(editor).toHaveText(draft);
await page.getByTestId("task-chat-composer-send").click();
await expect.poll(async () => {
const comments = await (await request.get(`/api/issues/${draftIssue.id}/comments`)).json();
return comments.filter((comment: { body: string }) => comment.body === draft).length;
}).toBe(1);
await page.reload();
await ready(page);
await expect(editor).toHaveText("");
await expect(page.getByText(draft, { exact: true })).toHaveCount(1);
});
test("failed initial comments expose retry, then recover without an indefinite skeleton", async ({ page }) => {
await page.route("**/api/issues/*/recent-comments", (route) => route.fulfill({ status: 500, contentType: "application/json", body: '{"error":"Comment read failed"}' }));
await page.goto(`/${prefix}/issues/${issue.identifier}`);
await expect(page.getByRole("button", { name: "Retry", exact: true })).toBeVisible({ timeout: 30_000 });
await page.unroute("**/api/issues/*/recent-comments");
await page.getByRole("button", { name: "Retry", exact: true }).click();
await ready(page);
await expect(page.getByText("Historical message 159", { exact: true })).toBeAttached();
await expect(page.getByRole("button", { name: "Retry", exact: true })).toBeHidden();
});
test("mobile reduced-motion cold open and rapid task switching", async ({ page }) => {
await page.setViewportSize({ width: 390, height: 844 });
await page.emulateMedia({ reducedMotion: "reduce" });
await page.goto(`/${prefix}/issues/${issue.identifier}`);
await ready(page);
const scroller = page.getByTestId("task-chat-scroller");
const distanceToLatest = () => scroller.evaluate(el => el.scrollHeight - el.scrollTop - el.clientHeight);
await expect.poll(distanceToLatest).toBeLessThan(2);
await scroller.evaluate(el => { el.scrollTop = 1200; });
await page.waitForTimeout(100);
const saved = await scroller.evaluate(el => el.scrollTop);
await page.reload();
await ready(page);
await expect.poll(distanceToLatest).toBeLessThan(2);
// A fresh navigation must show the new task, never retain the previous feed.
await page.goto(`/${prefix}/issues/${other.identifier}`);
await ready(page);
await expect(page.getByText("Historical message 159", { exact: true })).not.toBeAttached();
expect(saved).toBe(1200);
});
for (const mobile of [false, true]) {
test(`same-task comment links and Back restore the mounted ${mobile ? "mobile" : "desktop"} conversation`, async ({ page }) => {
if (mobile) await page.setViewportSize({ width: 390, height: 844 });
await page.goto(`/${prefix}/issues/${issue.identifier}`);
await ready(page);
await page.getByText("Historical message 159", { exact: true }).waitFor({ state: "attached" });
await expect(page.locator(`[id="comment-${oldestCommentId}"]`)).toHaveCount(0);
const originalThread = await page.getByTestId("task-chat-thread").elementHandle();
const before = await page.evaluate(() => {
const root = document.querySelector('[data-testid="task-chat-scroller"]')!;
const top = root.getBoundingClientRect().top;
const row = [...root.querySelectorAll<HTMLElement>("[data-thread-anchor]")].find((el) => el.getBoundingClientRect().bottom > top)!;
return { id: row.dataset.threadAnchor!, offset: row.getBoundingClientRect().top - top };
});
await page.getByRole("link", { name: "Read the oldest message", exact: true }).click();
const target = page.locator(`[id="comment-${oldestCommentId}"]`);
await expect(target).toBeAttached();
const targetOffset = () => target.evaluate(el => el.getBoundingClientRect().top - document.querySelector('[data-testid="task-chat-scroller"]')!.getBoundingClientRect().top);
await expect.poll(async () => Math.abs(await targetOffset())).toBeLessThanOrEqual(2);
expect(await originalThread!.evaluate((el) => el === document.querySelector('[data-testid="task-chat-thread"]'))).toBe(true);
await page.goBack();
await expect.poll(async () => Math.abs(await page.evaluate(before => {
const root = document.querySelector('[data-testid="task-chat-scroller"]')!;
const row = [...root.querySelectorAll<HTMLElement>("[data-thread-anchor]")].find((el) => el.dataset.threadAnchor === before.id)!;
return row.getBoundingClientRect().top - root.getBoundingClientRect().top - before.offset;
}, before))).toBeLessThanOrEqual(2);
});
}
test("stalled native and log history reveal loaded content with Retry after the request deadline", async ({ page }) => {
const runId = "20000000-0000-4000-8000-000000000001";
const at = new Date().toISOString();
await page.route(/\/api\/issues\/[^/]+\/runs(?:\?|$)/, (route) => route.fulfill({ json: [{ runId, runtimeMode: "native", status: "succeeded", agentId: "20000000-0000-4000-8000-000000000002", adapterType: "paperclip_runner", createdAt: at, startedAt: at, finishedAt: at }] }));
let stalled = true;
let release!: () => void;
const held = new Promise<void>((resolve) => { release = resolve; });
await page.route(`**/api/heartbeat-runs/${runId}/events?*`, async (route) => {
if (stalled) await held;
await route.fulfill({ json: [] }).catch(() => {});
});
await page.route(`**/api/heartbeat-runs/${runId}/log?*`, async (route) => {
if (stalled) await held;
await route.fulfill({ json: { runId, content: "", nextOffset: 0 } }).catch(() => {});
});
try {
await page.goto(`/${prefix}/issues/${issue.identifier}`);
await expect(page.getByTestId("task-chat-history-loading")).toBeVisible();
await expect(page.getByText("Some task history could not be loaded.")).toBeVisible({ timeout: 25_000 });
await ready(page);
await expect(page.getByText("Historical message 159", { exact: true })).toBeVisible();
stalled = false;
await page.getByRole("button", { name: "Retry", exact: true }).click();
await expect(page.getByText("Some task history could not be loaded.")).not.toBeVisible();
} finally {
release();
}
});