Repository navigation
Description
Before submitting
- I searched existing issues and did not find a duplicate. Related: fix(server): a stuck browser action no longer wedges its tab or other tabs #32866 / [Bug]: Server browser: a browser action that never finishes wedges its tab, evicts the preview host and stops other tabs' setting changes #32849 (stuck action wedging a tab), fix(server): preview hover and drag fail within their timeout, not up to 3x later #33550.
Area
apps/server
Checked against upstream main 92595ab (2026-11-15).
Problem
An agent's browser request carries one timeoutMs, and the broker waits that long (plus a 1 s grace for
actions that update the current tab). Several operations on the server browser do not keep to that budget:
-
Queue time is subtracted only for
click.runOperationreceivesdeadlineMs = performance.now() + request.timeoutMs
when the request arrives, but only theclickcase passes the remaining time to Playwright
(ServerBrowser.ts,case "click").hover,drag,select,typeanduploaduseinput.timeoutMs(or the 15 s
default),evaluateusesrequest.timeoutMs, andwaitForuses its input. A request that waited behind other work on
the same tab therefore starts with its full budget again. fix(server): preview hover and drag fail within their timeout, not up to 3x later #33550 gave hover and drag one deadline across their steps,
but that deadline still starts after queueing. -
selectgrants its budget twice.ServerBrowserPage.selectpasses the sametimeouttolocator.evaluate(reading
the options) and then tolocator.selectOption, so a slow first step leaves the second its full budget. -
Some steps have no limit, others the page's default.
press,type's keyboard steps (select-all, delete,
insertText) andscrollwithout a target (page.evaluate) take no timeout at all.scrollon a target uses
locator.evaluatewith no option, so it falls back to the page's 15 s default rather than the request's budget. -
Snapshot preparation and cleanup run outside the capture timer.
withScreencastsPausedwaits for the capture lock and
for every viewer'spause()(an unbounded CDPPage.stopScreencast) beforeServerBrowserPage.snapshotstarts its 10 s
timer, and it awaitsresume()infinallyafter that timer. If a viewer's pause never answers, the snapshot never
starts, the capture lock stays held, and later snapshots and recording stops on that tab queue behind it. -
openwaits for the page'sloadevent. A new tab with a URL awaits
page.waitForLoadState("load", { timeout: navigationTimeout })after its initial navigation, and an existing tab
navigates withnavigate(tab, url, "load", …); both swallow the timeout and then report the loading tab. So on a page
whoseloadnever fires (one image or script that never answers, long polling), opens with a URL and URL navigations
using the defaultloadreadiness can spend their navigation budget (normally 15 s, the default and cap) waiting for
loadbefore they return a tab that was usable right after commit. A navigation that asks forreadiness: "none"or
"domcontentloaded", or passes a shortertimeoutMs, returns earlier.
When an operation outlives its request, the caller has already received a timeout, but the work still runs and keeps the tab's
queue (or capture lock) busy, so the next calls on that tab also time out.
#32866 (open, fixes #32849) answers each request at timeoutMs + 500 ms, refuses new actions on a tab whose started run is
overdue with a busy reason, and stops mirrorManagerEvent from waiting on per-tab work. That keeps the host and other tabs
alive. It does not make the operations above respect the remaining budget, so with it applied a tab still stays busy for the
extra time each of them spends, and a snapshot whose pause stalls still holds the capture lock.
Minimal reproduction
Each case uses the server browser with controlled timing (fake clock or stubbed Playwright/CDP calls); no real site is needed.
- Queue time,
waitFor(same forevaluate,select,type,hover,drag): on one tab, start an action that takes 7 s.
While it runs, sendwaitForwithtimeoutMs: 9000for a selector that never appears. Expected: the wait gives up about
9 s after it was sent. Actual: it starts at 7 s with a fresh 9 s and gives up at about 16 s. select: stub the<select>locator soevaluateresolves after 7 s andselectOptionnever resolves. Call
selectwithtimeoutMs: 9000. Actual:selectOptionis called withtimeout: 9000, so the call ends at about 16 s.- Snapshot pause: attach a viewer whose
pause()never resolves. Request a snapshot, then advance the clock past 16 s.
Actual: the capture never starts (no snapshot stage has run), the capture lock is still held, and a second snapshot on
the tab is still waiting. Resolving the pause lets both complete. openon a stalled page: serve a page at/that responds at once and contains<img src="/stall.png">, where
/stall.pngnever responds. Callpreview_openwith that URL. Actual: the open returns after about 15 s, although
the document committed and rendered within about a second. Expected: it returns soon after the main document commits (or after
domcontentloaded), reportingloading: true.press: stubpage.keyboard.pressto never resolve. Sendpresswith anytimeoutMs. Actual: the call never settles on
the host; only the broker's own timeout ends it for the caller.
Expected behaviour
- Every operation receives the time remaining on its request (the deadline computed when the request arrived), not a fresh
timeoutMs, and sequential steps inside one operation share that remainder. A zero or negative remainder is refused before
dispatch rather than passed to Playwright, where0disables the timeout. press,scrollandtypekeyboard steps are bounded by the same remainder.openand URLnavigatereturn once the page is usable (commit ordomcontentloaded) and reportloading: true,
rather than spending the navigation budget onload;waitForremains the way to wait for more.- A snapshot's budget covers acquiring the capture lock, pausing viewers and recording, the capture itself, and resuming. If
a pause or resume does not answer in time, the snapshot fails with a timeout that names that stage, and the capture lock is
released, so the tab can take the next snapshot or stop a recording. - Expired work never resumes later and acts on the page after its caller has been told it timed out (the existing rule that
possibly applied actions are never replayed still holds).
Activity
test(server): browser actions keep to their request's remaining timeout