Skip to content

fix(cli): size the daemon transport from a command's own page timeout - #3390

Open
lhy-dcf wants to merge 1 commit into
browserbase:mainfrom
lhy-dcf:fix/daemon-command-transport-timeout
Open

lhy-dcf wants to merge 1 commit into
browserbase:mainfrom
lhy-dcf:fix/daemon-command-transport-timeout

Conversation

@lhy-dcf

@lhy-dcf lhy-dcf commented Nov 4, 2026 •

Copy link
Copy Markdown

Refs #3369.

What breaks

daemonRequestTimeoutMs gives every request a fixed 35s socket deadline, except open, which is sized from its navigation timeout:

if (request.type !== "open") return DEFAULT_DAEMON_REQUEST_TIMEOUT_MS; // 35s

Commands that wait on the page longer than that are killed by the transport before the page action finishes. browse wait timeout 40000 exits at ~39s with Timed out waiting for driver daemon session "<name>". while the 40s wait is still in flight; the same applies to the documented --timeout 45000 on reload / back / forward.

Fix

daemonRequestTimeoutMs now reads the deadline the command itself declared and keeps the socket open for it:

request transport deadline
wait {type:"selector"} (no declared timeout) 35s (unchanged)
wait {type:"timeout", arg:"40000"} 45s
reload {timeoutMs:45000} 50s
wait {type:"timeout", arg:"1000"} 35s (never shortens the default)
wait {type:"timeout", arg:"soon"} 35s (unparsable → unchanged)
very long wait clamped to 2_147_483_647

The sources are the two places the handlers already read their page timeout from: params.timeoutMs (navigation, selector/load waits) and params.arg for wait timeout <ms> (commands/runtime.ts parses exactly that). 5s of headroom covers the round trip and the action's own teardown. Commands that declare nothing keep today's 35s, so the change cannot stretch an unrelated request.

Tests

New packages/cli/tests/daemon-command-timeout.test.ts (6 cases, one per row above).

  • Before the fix: 3 failed | 3 passed — the wait timeout 40000 case fails with expected 35000 to be 45000, which is the reported abort.
  • After the fix: 6 passed (6).
  • The unchanged-behaviour cases are green before and after by design; they are what keeps this from becoming "make every timeout longer".

Run in an isolated vitest harness with the driver closure taken verbatim from main 18b96f2 (@browserbasehq/* and session-manager are not needed by the client.ts closure and were not installed).

Not verified / evidence boundary: no live remote browser session, so the end-to-end browse wait timeout 40000 run from the report was not repeated here — the assertion is on the deadline the client computes, which is the exact value the abort happens at. tsc --noEmit over the isolated closure reports 9 diagnostics, all in files this PR does not touch (server.ts, remote-types.ts, commands/types.ts) and all from the missing third-party types above; daemon/client.ts itself is clean.


Summary by cubic

Fixes #3369. The daemon transport imposed a fixed 35s socket deadline on every command except open, so browse wait timeout 40000 and --timeout 45000 on reload/back/forward were aborted mid-wait with Timed out waiting for driver daemon session. daemonRequestTimeoutMs now derives the deadline from the command's own page timeout — params.timeoutMs, or wait timeout <ms>'s arg — plus 5s headroom for the round trip and teardown.

Notes for review

  • Commands that declare no timeout, or an unparsable one, keep the 35s default; the deadline never goes below 35s and is capped at Node's maximum timer delay.
  • New daemon-command-timeout.test.ts covers the default, long and short wait timeout, a navigation timeout, an unparsable duration, and the cap.
  • No live remote browser session was run; the test asserts the computed deadline, which is the value the abort occurs at.

Written for commit 01bf51d. Summary will update on new commits.

View guided diff

The browse daemon client gives every request a fixed 35s socket deadline,
except `open`, which is sized from its navigation timeout. Commands that
wait on the page longer than that are cut off by the transport before the
page action finishes: `browse wait timeout 40000` exits ~39s in with
`Timed out waiting for driver daemon session "<name>".` while the 40s wait
is still running. The same applies to `--timeout 45000` on
reload/back/forward, which the README documents.

`daemonRequestTimeoutMs` now reads the deadline the command itself declared
(`params.timeoutMs`, plus `arg` for `wait timeout <ms>`) and keeps the
socket alive for that long plus 5s of headroom, clamped to the transport
default on the low side and to Node's maximum timer delay on the high side.
Commands that declare nothing — and every unparsable duration — keep
today's 35s deadline, so nothing that works now changes shape.

Tests in `packages/cli/tests/daemon-command-timeout.test.ts` cover the
default, `wait timeout`, a navigation `timeoutMs`, a command asking for
less than the default, an unparsable duration, and the timer cap.
@changeset-bot

changeset-bot Bot commented Nov 4, 2026

Copy link
Copy Markdown

⚠️ No Changeset found

Latest commit: 01bf51d

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@github-actions

github-actions Bot commented Nov 4, 2026

Copy link
Copy Markdown
Contributor

This PR is from an external contributor and must be approved by a stagehand team member with write access before CI can run.
Approving the latest commit mirrors it into an internal PR owned by the approver.
If new commits are pushed later, the internal PR stays open but is marked stale until someone approves the latest external commit and refreshes it.

@github-actions github-actions Bot added external-contributor Tracks PRs mirrored from external contributor forks. external-contributor:awaiting-approval Waiting for a stagehand team member to approve the latest external commit. labels Nov 4, 2026

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

external-contributor:awaiting-approval Waiting for a stagehand team member to approve the latest external commit. external-contributor Tracks PRs mirrored from external contributor forks.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

CLI daemon aborts commands after 35s despite longer requested waits

1 participant