fix(pi): close facade browser resources - #2794
Open
shrey150 wants to merge 2 commits into
Open
Conversation
|
This was referenced Aug 20, 2026
shrey150
force-pushed
the
shrey/eve-facade-session-close-pi
branch
from
August 20, 2026 23:34
0fe2eb3 to
f468ef6
Compare
shrey150
marked this pull request as ready for review
August 20, 2026 23:35
Contributor
There was a problem hiding this comment.
All reported issues were addressed across 2 files
Architecture diagram
sequenceDiagram
participant Pi as Pi Extension
participant ST as StagehandFacadeTools
participant SM as Stagehand Manager
participant BB as Browserbase SDK
participant Q as cleanupTargets/cleanupPromise
Note over Pi,Q: Pi Browser Cleanup Lifecycle
Pi->>SM: facadeTools() – first tool call
SM->>SM: cleanupPromise.then(retryCleanupTargets)
alt cleanupTargets non-empty
SM->>Q: retryCleanupTargets()
loop each releaseSession
Q->>BB: releaseBrowserbaseSession()
Q->>Q: delete from cleanupTargets
end
end
SM->>BB: browserbase.launch()
BB-->>SM: browser + sessionId
SM->>SM: capture releaseSession() immediately
SM->>SM: Stagehand.create({browser, ...})
alt Stagehand.create success
SM->>ST: new StagehandFacadeTools(stagehand, {close: closeCallback})
SM-->>Pi: resources
else Stagehand.create failure
SM->>BB: browser.close()
alt browser.close fails AND releaseSession exists
SM->>BB: releaseSession()
alt releaseSession also fails
BB-->>SM: error
SM->>Q: add releaseSession to cleanupTargets
end
SM-->>Pi: AggregateError
else browser.close fails without releaseSession
SM-->>Pi: error
else browser.close succeeds
SM-->>Pi: original error
end
end
Note over Pi,BB: browser.close() Callback
Pi->>ST: run() with await browser.close()
ST->>ST: lifecycle.close()
ST->>Pi: closeResources(tools, reportErrors=true)
Pi->>SM: closeResources(expected, reportErrors)
SM->>SM: wait for pending launch
alt expected tools mismatch (replaced)
SM-->>Pi: return (no-op)
else match
SM->>SM: resources = undefined
SM->>Q: cleanupPromise.then(closeResource)
Q->>SM: closeResource(current)
SM->>SM: stagehand.close()
alt stagehand.close fails
SM->>Q: collect error
end
SM->>BB: browser.close()
alt browser.close fails
SM->>SM: browserCloseFailed = true
SM->>BB: releaseSession() (if exists)
alt releaseSession fails
SM->>Q: add to cleanupTargets
else succeeds
SM->>Q: remove from cleanupTargets
end
else browser.close succeeds
SM->>BB: releaseSession() (if exists)
SM->>Q: remove from cleanupTargets
end
alt any errors
SM-->>Pi: single error or AggregateError
else clean
SM-->>Pi: undefined
end
end
SM-->>ST: result
ST-->>Pi: propagate error
Note over Pi,BB: session_shutdown Event
Pi->>Pi: on("session_shutdown")
Pi->>SM: closeResources() – no expected, reportErrors=false
SM->>SM: wait for pending launch
SM->>Q: cleanupPromise.then(closeResource)
Q->>SM: closeResource(current) – same as above
SM->>BB: stagehand.close() – best-effort
SM->>BB: browser.close() – best-effort
SM->>BB: releaseSession() if needed – best-effort
SM->>Q: retryCleanupTargets() – best-effort
SM-->>Pi: undefined (errors suppressed)
Reply with feedback, questions, or to request a fix.
Re-trigger cubic
shrey150
force-pushed
the
shrey/eve-facade-session-close-pi
branch
2 times, most recently
from
August 21, 2026 00:20
235c76d to
c97375d
Compare
Signed-off-by: Shrey Pandya <shrey@browserbase.com>
Signed-off-by: Shrey Pandya <shrey@browserbase.com>
shrey150
force-pushed
the
shrey/eve-facade-session-close-pi
branch
from
August 21, 2026 00:26
c97375d to
a34f281
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
why
This is PR 3 of the facade-close stack. It depends on #2793, which in turn depends on #2788.
Pi is a separate native facade host with its own launch and shutdown lifecycle. Once the shared facade propagates
browser.close(), Pi must provide a real host callback; otherwise the compatibility boundary correctly reports that cleanup is unsupported. Keeping this adapter in a separate PR makes Pi's shutdown and retry policy reviewable without mixing it into the Eve implementation.what changed
session_shutdownremains best-effort.Stagehand.create(), so an initialization failure cannot lose the remote session.StagehandFacadeCleanupErrorwith a fixed sanitized message and no raw SDK/CDP causes or aggregate members.behavior before and after
await browser.close()test plan
This PR does not claim a separate live Pi-agent E2E; the shared remote lifecycle behavior is covered by the Eve live A/B in #2793, while this PR focuses on Pi-specific ownership, error, retry, and shutdown paths.
No changeset is included because the Pi integration is a private example.
Summary by cubic
Pi now closes facade-launched browser resources and serializes cleanup. Previously model-requested
browser.close()had no host callback and failures could be swallowed; now explicit close surfaces a sanitized error while shutdown remains best-effort.browser.close()through a lifecycle callback inStagehandFacadeTools;session_shutdownuses the same path.StagehandFacadeCleanupError(sanitized); shutdown suppresses errors but retains release targets for retry.packages/integrations/pi/tests/lifecycle.test.ts.Written for commit a34f281. Summary will update on new commits.