Skip to content

first-message-thinking: count the page free at its next frame too, not only its next task - #2662

Merged
davidmckayv merged 1 commit into
mainfrom
fix/first-message-thinking-flake
Dec 2, 2026
Merged

davidmckayv merged 1 commit into
mainfrom
fix/first-message-thinking-flake

Conversation

@davidmckayv

@davidmckayv davidmckayv commented Dec 1, 2026 •

Copy link
Copy Markdown
Contributor

What this changes

Fixes #2389
Fixes #2396

first-message-thinking.test.tsx checks that "Thinking" is in the page, and the page is free to draw it, within 200 ms of Send. It knocked pull requests out of the merge queue three times on 1 Dec: #2504 and #2642 (a starter task on a new conversation with a Bot, WebKit, 258 ms and 274 ms) and #2631 (home, Chromium, 267 ms).

Part of the cause is where the test stopped the clock. It took the page as free when its next task ran: a MessageChannel message posted once the line was in. After a click or a key press, the browser draws a frame first, and that message waits behind the frame. So the 200 ms the test gave the page also held the browser's own frame, which is exactly the time a loaded runner stretches. The test's own comments already say that frame wait is not the page's to shorten. Under CI's load, every slow send in the repeat runs below had that frame inside the measured time, worth up to 48 ms.

A frame begins only once the page's task is over, so the first frame read after the line is in marks the page free just as well. The test now takes whichever comes first, the next task or that frame. The 200 ms bound is unchanged, and so is everything else it checks: every frame from then on shows "Thinking" until the Bot's first words. When the bound is missed, the log now says where the time went (in, free, first drawn), so the next miss can be read straight off CI.

Thanks to @ykakade for #2572, which went after the same tests by changing where they start. Its renderer crash is now caught by renderer-crash.ts, which reruns a test whose WebKit page crashed: there were no crash reruns in 96 runs of the file under CI's load. The timing misses also happen away from Home and in Chromium, so this measures the page from the right moment instead of changing Home.

Where it runs

Only the browser test changes. No new state, no second-replica behaviour, nothing serialised, no fan-out, no listener, port or schedule.

Boundary and audit

  • Every acting call still goes through the gateway: no app or server code changes.
  • New refusals and new failures each write a row: none added.
  • Nothing new is trusted from the client.

API and database

  • This changes nothing under api/, no app's requests, no database change and no release-policy.json.

Changelog

  • A deployment behaves no differently: only a test changes.

Proof

Under CI's own load, repeated. Draft #2657, which will not be merged, ran CI's exact WebKit-job list (8 files at once, Chromium and WebKit, the Playwright image, openbot-ubuntu-16core) in 12 shards, each with 3 extra copies of this file: 48 full runs of the file per engine, 288 sends per engine, for each version.

Page's own time from Send, in ms:

Chromium p50 / p95 / max WebKit p50 / p95 / max Over 200 ms
Before (next task) 39 / 82 / 113 59 / 132 / 181 0 of 576
After (next task or frame) 28 / 61 / 89 42 / 95 / 150 0 of 576

With the fix, all 96 runs passed, with no renderer crash reruns. WebKit's worst case now has 50 ms of room under the bound, up from 19 ms. Neither 48-run sample happened to catch a miss before the fix, so the proof is that room, plus the frame time it removes, not a failure count flipping.

What this does not prove: the CI logs of the 1 Dec misses don't say how their 258 to 274 ms split, and the frame this removes was worth up to 48 ms in these samples. The rest of the time is the app's own work (putting the line in), which a loaded runner slows 4 to 5 times over (in at up to 146 ms here, against 15 to 35 ms on an unloaded machine). If a miss comes back, its log now gives that split, and the next step can be chosen from it.

Still catches a real delay. With "Thinking" delayed 300 ms in the app itself (before setSent on a new conversation, and before Home's navigate to the placeholder), every delayed case failed in both engines, at 313 to 371 ms:

"Thinking" after Send: in at 341 ms, page free at 343 ms, first drawn at 343 ms   (home, chromium)
"Thinking" after Send: in at 321 ms, page free at 322 ms, first drawn at 322 ms   (a starter task on new-conversation-with-a-bot, webkit)
8 pass, 8 fail   (the 8 fails are exactly the delayed paths, in both engines)

The existing test where the page stays busy for 400 ms once "Thinking" is in still misses the bound in both engines. Nothing can draw until that busy task ends, so the frame end point cannot hide it.

Local runs were single and unloaded (Chromium and WebKit, 16 pass); the repeated runs under load were on CI.

@davidmckayv
davidmckayv marked this pull request as ready for review December 1, 2026 22:49
@davidmckayv
davidmckayv added this pull request to the merge queue Dec 1, 2026
@davidmckayv
davidmckayv removed this pull request from the merge queue due to a manual request Dec 2, 2026
@davidmckayv
davidmckayv merged commit 937ba4f into main Dec 2, 2026
19 checks passed
@davidmckayv
davidmckayv deleted the fix/first-message-thinking-flake branch December 2, 2026 01:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

1 participant