Skip to content

fix: preserve OOPIF frame registry parent edge#2077

Merged
monadoid merged 3 commits intomainfrom
stg-1808-oopif-frame-registry-repro
May 5, 2026
Merged

fix: preserve OOPIF frame registry parent edge#2077
monadoid merged 3 commits intomainfrom
stg-1808-oopif-frame-registry-repro

Conversation

@monadoid
Copy link
Copy Markdown
Contributor

@monadoid monadoid commented May 4, 2026

why

Stagehand could lose a known parent-child frame relationship after adopting an OOPIF child session. In practice, that meant the registry could forget that a child frame still belonged under the top-level page, leaving later iframe resolution with an incomplete frame tree.

what changed

Added a deterministic FrameRegistry unit test for the OOPIF adoption ordering. Updated seedFromFrameTree() to preserve an already-known parent when a child frame tree snapshot does not include parent metadata.

test plan

Before the fix, the new test failed with expected null to be 'root-frame'. After the fix, this passes:

pnpm --dir packages/core run build:esm && pnpm --dir packages/core run test:core -- packages/core/dist/esm/tests/unit/frame-registry-oopif-adoption.test.js


Summary by cubic

Fixes a bug where the frame registry could lose a known parent-child link after adopting an OOPIF child session. Preserves the parent edge when seeding from a child frame tree that lacks parent metadata to keep the iframe tree complete.

  • Bug Fixes
    • Updated FrameRegistry.seedFromFrameTree() to retain an existing parent when parentId is missing and to sync child sets accordingly.
    • Added a unit test for OOPIF adoption ordering and seeding to prevent regressions, and a changeset for @browserbasehq/stagehand patch release.

Written for commit 1e50e9c. Summary will update on new commits.

@changeset-bot
Copy link
Copy Markdown

changeset-bot Bot commented May 4, 2026

🦋 Changeset detected

Latest commit: 1e50e9c

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

This PR includes changesets to release 4 packages
Name Type
@browserbasehq/stagehand Patch
@browserbasehq/stagehand-evals Patch
@browserbasehq/stagehand-server-v3 Patch
@browserbasehq/stagehand-server-v4 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

@monadoid monadoid marked this pull request as ready for review May 4, 2026 13:45
Copy link
Copy Markdown
Contributor

@cubic-dev-ai cubic-dev-ai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No issues found across 2 files

Confidence score: 5/5

  • Automated review surfaced no issues in the provided summaries.
  • No files require special attention.
Architecture diagram
sequenceDiagram
    participant Driver as Stagehand Driver
    participant Registry as FrameRegistry
    participant Store as this.frames (Internal Map)
    participant CDP as CDP (Browser Sessions)

    Note over Driver, CDP: Phase 1: Parent Session Discovery
    CDP->>Registry: onFrameAttached(childId, parentId)
    Registry->>Store: ensureNode(childId)
    Registry->>Store: set parentId and update children Set

    Note over Driver, CDP: Phase 2: OOPIF Adoption
    Driver->>Registry: adoptChildSession(childSessionId, childId)
    Registry->>Store: setOwnerSessionIdInternal(childId, childSessionId)

    Note over Driver, CDP: Phase 3: Seeding from Child Session (OOPIF)
    CDP->>Registry: seedFromFrameTree(childSessionId, frameTree)
    
    loop For each node in tree (walk)
        Registry->>Store: get existing info (previousParent)
        
        Note over Registry, Store: CHANGED: Determine nextParent
        Registry->>Registry: nextParent = tree.parentId ?? previousParent

        alt previousParent exists and changed
            Registry->>Store: Remove childId from previousParent's children Set
        end

        Registry->>Store: Update info.parentId = nextParent
        
        opt nextParent is valid
            Registry->>Store: ensureNode(nextParent)
            Registry->>Store: Add childId to nextParent's children Set
        end

        Note over Registry, Store: CHANGED: Reconstruct lastSeen frame metadata
        Registry->>Store: lastSeen = frame + (injected parentId if missing)
        
        opt ownerSessionId unknown
            Registry->>Store: setOwnerSessionIdInternal
        end
    end

    Note over Driver, Registry: Frame resolution now sees complete tree across sessions
Loading

@monadoid monadoid merged commit f437f73 into main May 5, 2026
203 checks passed
@github-actions github-actions Bot mentioned this pull request May 4, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants