Skip to content

fix: release child-frame references when pages close - #3129

Open
antonvishal wants to merge 4 commits into
browserbase:mainfrom
antonvishal:vishal/perf-frame-cleanup
Open

antonvishal wants to merge 4 commits into
browserbase:mainfrom
antonvishal:vishal/perf-frame-cleanup

Conversation

@antonvishal

@antonvishal antonvishal commented Oct 7, 2026 •

Copy link
Copy Markdown
Contributor

Why

Closing 100 pages with nested frames left 200 stale child-frame owners. This fix leaves zero, confirmed in three runs of the cleanup fixture. Reused contexts no longer retain those disposed pages.

Metric Stagehand before Playwright This PR
Wall time 11.44 s 16.61 s 11.33 s
Flow p50 255 ms 456 ms 253 ms
Session p50 317 ms 484 ms 315 ms
Browser CPU seconds 50.82 39.33 49.99
Peak browser RSS 5,693 MB 4,443 MB 5,664 MB
Failures 0/384 0/384 0/384

Medians of three local runs, each with 128 billing flows and four reused browsers. No LLM calls.

The billing flow measures general overhead; the nested-frame fixture measures the cleanup fix.

What

Clear ownership and frame caches for removed subtrees and dispose pages during context shutdown. Preserve process swaps. Finish cleanup even when disposal or connection close fails, while retaining the errors.

How

1,177 extension/TypeScript tests and four browser lifecycle tests passed. Coverage includes nested frames, OOPIF detach, process swaps and failed cleanup. Builds and extension typecheck passed.


Summary by cubic

Fixes stale frame ownership and cache entries after pages close. A 100-page nested-frame cleanup fixture retained 200 child-frame owners before and zero after, with the same result in three runs.

  • Prunes frame ownership for the entire removed subtree instead of only the detached frame, covering page close, frame removal, and OOPIF detach.
  • Clears frame caches and ordinals for every removed subtree frame while preserving ownership on process swaps.
  • Disposes pages before closing CDP and clears all context bookkeeping even when disposal or connection close fails, preserving original errors or aggregating multiple failures.
  • Adds tests for nested frame removal, OOPIF detach, process swaps, and failed cleanup paths; rebuilds the Go extension asset ZIP and syncs its protocol version.

Written for commit 62943a4. Summary will update on new commits.

View guided diff

@changeset-bot

changeset-bot Bot commented Oct 7, 2026 •

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 62943a4

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

This PR includes changesets to release 24 packages
Name Type
@browserbasehq/stagehand Patch
@browserbasehq/stagehand-go Patch
@browserbasehq/stagehand-python Patch
@browserbasehq/stagehand-extension Patch
browse Patch
@browserbasehq/stagehand-examples Patch
@browserbasehq/stagehand-integrations-claude-cua-sdk Patch
@browserbasehq/stagehand-integrations Patch
@browserbasehq/eve Patch
@browserbasehq/stagehand-integrations-gemini-cua-sdk 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-example-cursor-facade 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

github-actions Bot commented Oct 7, 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 Oct 7, 2026
@antonvishal
antonvishal marked this pull request as ready for review October 7, 2026 16:45
…leanup

# Conflicts:
#	packages/sdk-go/internal/extensionassets/stagehand-extension.zip
…erf-frame-cleanup

# Conflicts:
#	packages/sdk-go/internal/extensionassets/stagehand-extension.zip

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.

1 participant