Skip to content
Source
Sign inSign up
pingdotgg/t3code

[Bug]: preview_evaluate rejects top-level await and has a fixed 15s timeout #31892

ClosedGuria(GitHub profile, opens in a new tab) opened this issue 0 comments

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

  1. Open any page with preview_open.
  2. Call preview_evaluate with expression: "await new Promise(r => setTimeout(r, 100)); location.pathname".
  3. Call preview_evaluate with 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:

Seen in an audit of ~170 Claude Code sessions in T3 Code on one project (Oct 18 – Nov 6 2026):

  • 3 sessions hit the SyntaxError with expressions like location.assign('/pr-189/editor'); await new Promise(r=>setTimeout(r,4000)); location.pathname. Agents write top-level await because 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: true to Runtime.evaluate. That is how devtools supports top-level await, and it keeps the last expression as the result. Alternatively, say in the tool description that await needs an async IIFE.
  • Add timeoutMs to PreviewAutomationEvaluateInput as preview_act has, 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.

  1. juliusmarminge closed this

Sign in to join this conversation.