PageWebView: a script call during the Chromium start waits for it

Merged
TE
3d ago
+110-17

What

PageWebView.callPageScript now waits for an in-flight Chromium start before it picks an engine.

Why

When a page shows in Chromium, startChromium hides the WebKit view and never loads the document in it. Until attachChromium sets chromiumSession, though, callPageScript fell through to that hidden, empty WebKit view. On a cold chat open, the chat-open bench's first debug.agent_pane layout_watch call arrives about 0.2 s after the click and lands in that window. DebugAgentPane.script then waited its full 5 s for window.cmuxAcpmuxDebug in a document that would never have it, and the next call answered about 5.2 to 6.2 s after the click. That is outside the 2.5 s frame strip, so the cold click cell had no transcript_ms and read FAILED, even though the pixels showed the transcript settled at about 1.1 to 1.3 s.

Evidence from step eb7a5aa241bc7bdfd4d57b9a (layout_watch_errors on each cold click): {"asked_ms": 207, "took_ms": 5425, "error": "the page has no cmuxAcpmuxDebug.layoutWatch"}, followed by a successful watch with first_rows: 7.

The page's hook was never late. It is installed on mount from the statically imported debug.ts, not behind a lazy chunk. The call just went to the wrong engine. Production callers of callPageScript (copy and key handlers, transport, wake state) hit the same window on a page whose Chromium start is still running. For them, running in the never-loaded WebKit view always returned a meaningless result, so waiting is correct there too. A finished or absent start costs nothing. A start that falls back to WebKit clears chromiumStart and loads the document in WebKit, and the call then runs there.

Test

PageWebViewEngineNeutralTests.aScriptCalledWhileChromiumStartsRunsInChromium calls a script before the fake Chromium page exists and checks that it ran through the Chromium page's Runtime.evaluate, not in the hidden WebKit view.

Refs manaflow-ai/cmuxterm-hq#6338, #34118.

Agent session: agent session

🤖 Generated with Claude Code


Autofix with [code]smith
Open in [code]smith · Need help on this PR? Tag @codesmith-bot with what you need.


Summary by cubic

PageWebView.callPageScript now waits for an in-flight Chromium start before it picks an engine. Previously, calls made while Chromium was starting fell through to the hidden WebKit view that never loads the document, so the chat-open bench's first layout_watch call waited its full 5 s hook timeout and answered ~6 s after a cold click, failing the frame strip. The call now waits for startChromium to either attach Chromium or fall back to WebKit, then runs in whichever engine shows the page. A finished or absent start costs nothing.

The bench now says why an open is invalid, since an open's trace reads timed_out false when the loading watchdog ends the wait, undercounting opens that never showed content. Each open gets an invalid_reason (error, timed_out, no_content, no_frames, no_empty_time), the summary counts them, and a FAILED cell names them. marks_median_ms now covers every open that ran a mark, complete case or not, with marks_n.

Bug Fixes

  • Script calls during Chromium startup now run in the Chromium page once it exists, instead of the hidden, never-loaded WebKit view.
  • Adds a test covering a script called before the fake Chromium page exists.