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..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( @@ -802,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)) @@ -889,6 +908,13 @@ describe.skipIf(!asked)( 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);