From 5c26f03e3180bf41f002dd120b5f92e36414ef1c Mon Sep 17 00:00:00 2001 From: David McKay Date: Tue, 1 Dec 2026 14:23:25 -0800 Subject: [PATCH 1/2] Diagnostic: repeat first-message-thinking under CI load (not for merge) --- .github/workflows/thinking-repeat.yml | 54 +++++++++++++++++++++++ app/tests/first-message-thinking.test.tsx | 26 ++++++++++- 2 files changed, 78 insertions(+), 2 deletions(-) create mode 100644 .github/workflows/thinking-repeat.yml diff --git a/.github/workflows/thinking-repeat.yml b/.github/workflows/thinking-repeat.yml new file mode 100644 index 0000000000..0982c6565d --- /dev/null +++ b/.github/workflows/thinking-repeat.yml @@ -0,0 +1,54 @@ +name: Thinking repeat (diagnostic, not for main) + +# Diagnostic only, never merged: runs first-message-thinking.test.tsx many times under the real load +# of the app (real browser, WebKit) job, to measure its flake and prove a fix. +on: + pull_request: + +permissions: + contents: read + +jobs: + repeat: + if: github.head_ref == 'diag/first-message-thinking-repeat' + strategy: + fail-fast: false + matrix: + shard: [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12] + runs-on: openbot-ubuntu-16core + timeout-minutes: 40 + env: + PLAYWRIGHT_IMAGE: mcr.microsoft.com/playwright:v1.62.1-noble@sha256:dcc5531e97840b9b5e794f2814476b21571c5124a3fca2267d73041f56e7580e + steps: + - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 + with: + persist-credentials: false + - uses: oven-sh/setup-bun@0c5077e51419868618aeaa5fe8019c62421857d6 # v2.2.0 + with: + bun-version: 1.4.3 + - run: bun install --frozen-lockfile + - run: bun run generate:app-config + - name: Copies of the file, run alongside CI's own list + run: | + for r in 1 2 3; do + cp app/tests/first-message-thinking.test.tsx "app/tests/first-message-thinking-r$r.test.tsx" + done + - name: CI's WebKit-job list, eight at once, with the copies + run: | + set +e + LIST=$(grep -o 'app/tests/chunk-recovery.test.tsx.*artifact-sign-in-refusal-browser.test.tsx' .github/workflows/ci.yml | head -1) + docker run --rm --ipc=host \ + --volume "$GITHUB_WORKSPACE:$GITHUB_WORKSPACE" --workdir "$GITHUB_WORKSPACE" \ + --volume "$(command -v bun):/usr/local/bin/bun:ro" \ + --env OPENBOT_APP_BROWSER=1 --env OPENBOT_APP_ENGINES=chromium,webkit \ + "$PLAYWRIGHT_IMAGE" \ + bun test --parallel=8 --timeout=5000 $LIST \ + app/tests/first-message-thinking-r1.test.tsx app/tests/first-message-thinking-r2.test.tsx app/tests/first-message-thinking-r3.test.tsx \ + > run.log 2>&1 + echo "exit $?" + grep -E "^DIAG|DIAG " run.log | sed 's/.*DIAG /DIAG /' > diag.txt + echo "DIAG lines: $(wc -l < diag.txt)" + cat diag.txt + echo "--- first-message-thinking failures" + grep -E "\(fail\).*(Thinking|starter task)" run.log || echo "none" + grep -B2 -A2 "Received:" run.log | grep -A4 "first-message-thinking" || true diff --git a/app/tests/first-message-thinking.test.tsx b/app/tests/first-message-thinking.test.tsx index 2a82035100..83afe7d8b8 100644 --- a/app/tests/first-message-thinking.test.tsx +++ b/app/tests/first-message-thinking.test.tsx @@ -603,6 +603,14 @@ async function watchFrames(page: Page, by: By) { watch.frames = []; watch.sent = null; watch.watching = true; + const diag = watch as unknown as { long: number[][] }; + diag.long = []; + try { + new PerformanceObserver((list) => { + for (const entry of list.getEntries()) + diag.long.push([Math.round(entry.startTime), Math.round(entry.duration)]); + }).observe({ type: "longtask" }); + } catch {} watch.laidOut = null; watch.free = null; watch.observer?.disconnect(); @@ -635,8 +643,10 @@ async function watchFrames(page: Page, by: By) { if ( watch.sent === null && (by === "starter" || (event as KeyboardEvent).key === "Enter") - ) + ) { watch.sent = performance.now(); + (watch as unknown as { eventAt: number }).eventAt = event.timeStamp; + } }, { capture: true }, ); @@ -762,11 +772,19 @@ async function framesToWords(page: Page) { free: number | null; }; watch.watching = false; + const diag = watch as unknown as { eventAt: number; long: number[][] }; + const s = watch.sent; + const between = watch.frames.filter( + (f) => watch.laidOut !== null && watch.free !== null && f.at > watch.laidOut && f.at < watch.free, + ).length; + const before = watch.frames.filter((f) => f.at >= s && watch.laidOut !== null && f.at < watch.laidOut).length; + (globalThis as unknown as { lastDiag: string }).lastDiag = ""; return { frames: watch.frames, sent: watch.sent, laidOut: watch.laidOut, free: watch.free, + diag: `firstFrameAfterIn=${(() => { const f = watch.frames.find((x) => watch.laidOut !== null && x.at >= watch.laidOut); return f ? Math.round(f.at - s) : null; })()} inputDelay=${Math.round(s - diag.eventAt)} framesSentToIn=${before} framesInToFree=${between} long=${JSON.stringify(diag.long.filter(([at, d]) => at + d >= s - 50 && at <= (watch.free ?? s) + 50).map(([at, d]) => [at - Math.round(s), d]))}`, }; }); } @@ -883,7 +901,11 @@ describe.skipIf(!asked)( while (chunks.sent < chunks.asked) await new Promise((done) => setTimeout(done, 50)); await sendWatched(page, sent.by); - const seen = read(await framesToWords(page)); + const got = await framesToWords(page); + const seen = read(got); + console.log( + `DIAG ${engine} ${named(sent)} laidOut=${seen.laidOutAfterMs} free=${seen.freeAfterMs} shown=${seen.shownAfterMs} ${got.diag}`, + ); expect(new URL(page.url()).pathname).toMatch(OPENS(sent.adds)); expect(seen.wordsDrawn).toBe(true); expect(seen.shownAfterMs).not.toBeNull(); From 50e4e089b35dc9a4622573f76dd4bd207f8c1aa4 Mon Sep 17 00:00:00 2001 From: David McKay Date: Tue, 1 Dec 2026 14:28:03 -0800 Subject: [PATCH 2/2] Diagnostic: the fixed test, repeated under CI load --- app/tests/first-message-thinking.test.tsx | 62 ++++++++++++----------- 1 file changed, 33 insertions(+), 29 deletions(-) diff --git a/app/tests/first-message-thinking.test.tsx b/app/tests/first-message-thinking.test.tsx index 83afe7d8b8..0eaf629434 100644 --- a/app/tests/first-message-thinking.test.tsx +++ b/app/tests/first-message-thinking.test.tsx @@ -584,10 +584,17 @@ type By = "typing" | "starter"; * is when the page next took up a task after that, so whatever the page did straight after putting * the line in, before it could be drawn, counts too. What is left between `free` and the frame that * draws the line is the browser's wait for its next frame, which is what stretches on a loaded - * runner (eight files at once, Chromium and WebKit each). The bound used to be read off the frames' - * own timestamps, and Chromium stamps a frame with when it began it: a frame begun just before Send - * and drawn after the line was in was left out as too early, and the next frame, a starved frame's - * length later, counted instead, so the more starved the frames, the later the line seemed. + * runner (eight files at once, Chromium and WebKit each). + * + * The next task is not always the page's next moment, though: after a click or a key, the browser + * draws first, and the task waits behind that frame, a starved frame's length on a loaded runner. A + * frame begins only once the page's task is over, so the first frame read once the line was in + * marks the page free just as well, and `read` takes whichever came first. + * + * The bound used to be read off the frames' own timestamps, and Chromium stamps a frame with when + * it began it: a frame begun just before Send and drawn after the line was in was left out as too + * early, and the next frame, a starved frame's length later, counted instead, so the more starved + * the frames, the later the line seemed. */ async function watchFrames(page: Page, by: By) { await page.evaluate( @@ -603,14 +610,6 @@ async function watchFrames(page: Page, by: By) { watch.frames = []; watch.sent = null; watch.watching = true; - const diag = watch as unknown as { long: number[][] }; - diag.long = []; - try { - new PerformanceObserver((list) => { - for (const entry of list.getEntries()) - diag.long.push([Math.round(entry.startTime), Math.round(entry.duration)]); - }).observe({ type: "longtask" }); - } catch {} watch.laidOut = null; watch.free = null; watch.observer?.disconnect(); @@ -643,10 +642,8 @@ async function watchFrames(page: Page, by: By) { if ( watch.sent === null && (by === "starter" || (event as KeyboardEvent).key === "Enter") - ) { + ) watch.sent = performance.now(); - (watch as unknown as { eventAt: number }).eventAt = event.timeStamp; - } }, { capture: true }, ); @@ -772,19 +769,11 @@ async function framesToWords(page: Page) { free: number | null; }; watch.watching = false; - const diag = watch as unknown as { eventAt: number; long: number[][] }; - const s = watch.sent; - const between = watch.frames.filter( - (f) => watch.laidOut !== null && watch.free !== null && f.at > watch.laidOut && f.at < watch.free, - ).length; - const before = watch.frames.filter((f) => f.at >= s && watch.laidOut !== null && f.at < watch.laidOut).length; - (globalThis as unknown as { lastDiag: string }).lastDiag = ""; return { frames: watch.frames, sent: watch.sent, laidOut: watch.laidOut, free: watch.free, - diag: `firstFrameAfterIn=${(() => { const f = watch.frames.find((x) => watch.laidOut !== null && x.at >= watch.laidOut); return f ? Math.round(f.at - s) : null; })()} inputDelay=${Math.round(s - diag.eventAt)} framesSentToIn=${before} framesInToFree=${between} long=${JSON.stringify(diag.long.filter(([at, d]) => at + d >= s - 50 && at <= (watch.free ?? s) + 50).map(([at, d]) => [at - Math.round(s), d]))}`, }; }); } @@ -820,9 +809,21 @@ function read({ ); const since = (at: number | null) => at === null ? null : Math.round(at - sent); + // Free once the page took up its next task, or began its next frame if it drew first: either way + // the work it did once the line was in is over (see `watchFrames`). + const drawing = + laidOut === null + ? undefined + : frames.find((frame) => frame.at >= laidOut)?.at; + const freed = + free === null + ? (drawing ?? null) + : drawing === undefined + ? free + : Math.min(free, drawing); return { laidOutAfterMs: since(laidOut), - freeAfterMs: since(free), + freeAfterMs: since(freed), shownAfterMs: since(first?.at ?? null), framesWithout: before .slice(Math.max(from, 0)) @@ -901,16 +902,19 @@ describe.skipIf(!asked)( while (chunks.sent < chunks.asked) await new Promise((done) => setTimeout(done, 50)); await sendWatched(page, sent.by); - const got = await framesToWords(page); - const seen = read(got); - console.log( - `DIAG ${engine} ${named(sent)} laidOut=${seen.laidOutAfterMs} free=${seen.freeAfterMs} shown=${seen.shownAfterMs} ${got.diag}`, - ); + const seen = read(await framesToWords(page)); expect(new URL(page.url()).pathname).toMatch(OPENS(sent.adds)); expect(seen.wordsDrawn).toBe(true); expect(seen.shownAfterMs).not.toBeNull(); // The page's own part, strictly: in, and free to be drawn, within the bound. Every // frame from then on shows it (`framesWithout`), however late the browser draws one. + console.log( + `DIAG AFTER ${engine} ${named(sent)} laidOut=${seen.laidOutAfterMs} free=${seen.freeAfterMs} shown=${seen.shownAfterMs}`, + ); + if (ownWork(seen) > SHOWN_WITHIN_MS) + console.error( + `"Thinking" after Send: in at ${seen.laidOutAfterMs} ms, page free at ${seen.freeAfterMs} ms, first drawn at ${seen.shownAfterMs} ms`, + ); expect(ownWork(seen)).toBeLessThanOrEqual(SHOWN_WITHIN_MS); expect(seen.framesWithout).toEqual([]); expect(seen.goneWithWords).toBe(true);