Skip to content

feat(sdk-ts): add configurable RPC call controls - #2925

Open
pr1m8 wants to merge 1 commit into
browserbase:mainfrom
pr1m8:replit/configurable-rpc-timeouts
Open

pr1m8 wants to merge 1 commit into
browserbase:mainfrom
pr1m8:replit/configurable-rpc-timeouts

Conversation

@pr1m8

@pr1m8 pr1m8 commented Sep 12, 2026

Copy link
Copy Markdown

why

Long-running Stagehand RPCs need two forms of caller control:

  • A bounded response wait for environments that cannot wait indefinitely.
  • A way to stop waiting when the current caller or notebook cell is cancelled.

Cancellation must not implicitly close Stagehand or the underlying browser. A later operation should still be able to use the existing session.

what changed

  • Add TypeScript-only rpcTimeouts to Stagehand.create():
    • defaultMs sets a response deadline for ordinary RPC calls.
    • methods overrides the default for specific Stagehand RPC methods.
    • Timeout values must be positive integers and are capped at 2_147_473_647 ms.
    • Configured values take precedence over Stagehand’s existing computed response deadlines.
  • Add TypeScript-only getCallOptions() to Stagehand.create():
    • Invoked once immediately before each ordinary outbound RPC call.
    • May return { signal?: AbortSignal }.
    • Its signal is combined with an existing call signal and the response-timeout signal.
    • A pre-aborted signal fails before the RPC is sent.
  • Keep stagehand.init and stagehand.callback_batch outside both hooks:
    • Initialization retains its existing lifecycle deadline.
    • experimentalBatch() retains its existing whole-batch timeout and cancellation behavior.
  • Re-throw transport send errors after rejecting their pending RPC request.
  • Export schemas and types, document the options, and add a minor Changeset.

test plan

  • pnpm --filter @browserbasehq/stagehand typecheck
  • pnpm --filter @browserbasehq/stagehand build
  • Production build passed publint.
  • pnpm --filter @browserbasehq/stagehand test:unit
    • 20 test files passed
    • 290 tests passed
  • Published-package consumer coverage verifies the new schemas and types.

Focused coverage verifies:

  • configured per-method timeout overrides the configured default;
  • existing fallback timeout behavior remains unchanged without configuration;
  • initialization and callback batches ignore the new hooks;
  • getCallOptions() is called once per ordinary RPC;
  • pre-aborted signals do not send an RPC;
  • aborting one ordinary RPC leaves the client usable for a later RPC;
  • transport send failures propagate to the caller.

Summary by cubic

Adds configurable response wait deadlines and per-call abort signals to ordinary Stagehand RPC calls, so callers can bound how long they wait and cancel a single call without closing the session.

  • Stagehand.create() accepts two new TypeScript-only options: rpcTimeouts (defaultMs with per-method overrides) and getCallOptions() returning an optional AbortSignal.
  • Configured timeouts take precedence over the SDK's existing computed deadlines; values must be positive integers capped at 2_147_473_647 ms.
  • getCallOptions() is invoked once before each ordinary RPC call, and a pre-aborted signal fails before the call is sent.
  • stagehand.init and experimentalBatch() ignore both hooks and keep their existing lifecycle timeout and cancellation behavior.
  • Aborting a single call leaves the Stagehand instance and its browser usable for later calls.
  • Transport send failures now surface to the caller as errors after their pending request is rejected.

Written for commit 807a930. Summary will update on new commits.

Review in cubic

@pr1m8
pr1m8 requested a review from a team as a code owner September 12, 2026 02:22
@changeset-bot

changeset-bot Bot commented Sep 12, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 807a930

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 16 packages
Name Type
@browserbasehq/stagehand Minor
@browserbasehq/stagehand-integrations Patch
@browserbasehq/stagehand-integrations-example-eve-facade Patch
@browserbasehq/stagehand-integrations-example-pi-facade Patch
@browserbasehq/stagehand-integrations-claude-agent-sdk Patch
@browserbasehq/stagehand-integrations-example-claude-code-facade Patch
@browserbasehq/stagehand-integrations-codex-sdk Patch
@browserbasehq/stagehand-integrations-example-codex-facade Patch
@browserbasehq/stagehand-integrations-cursor-sdk Patch
@browserbasehq/stagehand-integrations-deepagents-sdk Patch
@browserbasehq/stagehand-integrations-eve-sdk Patch
@browserbasehq/stagehand-integrations-fx-sdk Patch
@browserbasehq/stagehand-integrations-mastra-sdk Patch
@browserbasehq/stagehand-integrations-example-mastra-facade Patch
@browserbasehq/stagehand-integrations-pi-sdk Patch
@browserbasehq/stagehand-integrations-example-vercel-ai-facade Patch

Not sure what this means? Click here to learn what changesets are.

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

@github-actions

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 Sep 12, 2026
@pr1m8 pr1m8 closed this Sep 12, 2026
@pr1m8
pr1m8 deleted the replit/configurable-rpc-timeouts branch September 12, 2026 05:04
@pr1m8
pr1m8 restored the replit/configurable-rpc-timeouts branch September 14, 2026 19:32
@pr1m8 pr1m8 reopened this Sep 14, 2026
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.

1 participant