[Bug]: preview_evaluate rejects top-level await and has a fixed 15s timeout #31892
Before submitting#
- I searched existing issues and did not find a duplicate.
- I included enough detail to reproduce or investigate the problem.
Area#
apps/server
Steps to reproduce#
- Open any page with
preview_open. - Call
preview_evaluatewithexpression: "await new Promise(r => setTimeout(r, 100)); location.pathname". - Call
preview_evaluatewith an async loop that waits for page state longer than 15 s, e.g.(async () => { while (!document.querySelector('#late')) await new Promise(r => setTimeout(r, 500)); return 'ok' })().
Expected behavior#
Step 2 returns location.pathname, as a devtools console would. Step 3 either has a way to raise the limit, or the tool description states it.
Actual behavior#
Step 2: Preview automation evaluate failed: SyntaxError: await is only valid in async functions and the top level bodies of modules.
Step 3: Preview automation evaluate timed out after 15000ms. The tool has no timeout parameter and its description does not mention the limit.
Cause, at 2756da402b:
ServerBrowserPage.evaluatesendsRuntime.evaluatewithawaitPromiseandreturnByValuebut notreplMode, so top-levelawaitis a syntax error.PreviewAutomationEvaluateInputhas notimeoutMs, and thepreview_evaluatehandler passesundefined, so the broker default of 15 000 ms always applies.preview_actandpreview_wait_foraccepttimeoutMs;preview_evaluatedoes not.
Seen in an audit of ~170 Claude Code sessions in T3 Code on one project (Oct 18 – Nov 6 2026):
- 3 sessions hit the
SyntaxErrorwith expressions likelocation.assign('/pr-189/editor'); await new Promise(r=>setTimeout(r,4000)); location.pathname. Agents write top-levelawaitbecause devtools consoles accept it. - 4 calls in 2 sessions hit the 15 s timeout on async loops waiting for page state.
Suggested fix#
- Pass
replMode: truetoRuntime.evaluate. That is how devtools supports top-levelawait, and it keeps the last expression as the result. Alternatively, say in the tool description thatawaitneeds an async IIFE. - Add
timeoutMstoPreviewAutomationEvaluateInputaspreview_acthas, or at least state the 15 s limit in the description.
Impact#
Minor bug or occasional failure
Version or commit#
main @ 2756da402b
Environment#
T3 Code with Claude Code as the provider
Workaround#
Wrap the expression in (async () => { ...; return value })(). Split long waits across several calls or use preview_wait_for.
juliusmarminge closed this
Sign in to join this conversation.