fix(integrations): propagate facade close lifecycle - #2788
Conversation
|
4e8b9ef to
60ad167
Compare
There was a problem hiding this comment.
All reported issues were addressed across 11 files
Architecture diagram
sequenceDiagram
participant Model as AI Model (Agent)
participant Facade as Facade Tools (tools.ts)
participant Runtime as Playwright Compat Runtime
participant Host as Eve/Pi/Stdio Host
participant Browserbase as Browserbase API
Note over Model,Facade: Tool Call: run("await browser.close()")
Model->>Facade: run(code: "await browser.close()")
Facade->>Runtime: experimentalBatch(code)
Runtime->>Runtime: context.close() → closeRequested = true
Runtime-->>Facade: { value, closeRequested: true }
alt closeRequested is true
Facade->>Facade: Clear hydrated snapshots
Facade->>Host: lifecycle.close()
Host->>Host: Detach facade, close Stagehand
Host->>Host: Close local browser
alt Eve host with Browserbase session
Host->>Browserbase: POST /v1/sessions/{id} (REQUEST_RELEASE)
Browserbase-->>Host: 200 OK
Host->>Host: Clear persisted session ID
else Release failed
Browserbase-->>Host: Error / non-200
Host->>Host: Mark session as suspect
Host-->>Facade: throw Error("Failed to release...")
end
alt Browser code also threw error
Facade-->>Model: AggregateError (execution + close)
else Clean close
Facade-->>Model: Return value
end
end
Note over Host,Model: Next Tool Call (after close)
Model->>Facade: run(...) or snapshot(...)
alt Eve host
Host->>Host: No existing resources
Host->>Host: createResources() → new browser session
Host-->>Facade: Fresh facade tools
else Pi host
Host->>Host: closeResources() replaced with new
Host-->>Facade: Fresh facade tools
end
Facade-->>Model: Result from new session
Reply with feedback, questions, or to request a fix.
Re-trigger cubic
There was a problem hiding this comment.
All reported issues were addressed across 7 files (changes from recent commits).
Reply with feedback, questions, or to request a fix.
Re-trigger cubic
There was a problem hiding this comment.
All reported issues were addressed across 6 files (changes from recent commits).
Tip: Review your code locally with the cubic CLI to iterate faster.
Re-trigger cubic
There was a problem hiding this comment.
All reported issues were addressed across 6 files (changes from recent commits).
Tip: Review your code locally with the cubic CLI to iterate faster.
Re-trigger cubic
There was a problem hiding this comment.
All reported issues were addressed across 6 files (changes from recent commits).
Tip: Review your code locally with the cubic CLI to iterate faster.
Re-trigger cubic
8ceb1d4 to
7c01ec7
Compare
Signed-off-by: Shrey Pandya <shrey@browserbase.com>
Signed-off-by: Shrey Pandya <shrey@browserbase.com>
8bd4e99 to
73aed48
Compare
Signed-off-by: Shrey Pandya <shrey@browserbase.com>
why
Current
mainalready recognizesbrowser.close()inside the Playwright-shaped worker runtime, thanks to #2769 /544ec87f. The worker setscloseRequested, but the batch result drops that signal and the Node host never consumes it. A tool call can therefore report success without releasing the host-owned browser resources.Cleanup must stay in the host: the Chrome extension worker should not receive Browserbase credentials or own session state. This PR establishes the shared facade contract and implements it for the core stdio host. Eve and Pi adoption are intentionally separated into stacked follow-ups so each host's ownership policy can be reviewed independently.
what changed
closeRequestedalongside the model value/error. JSON serialization is preflighted so a circular result cannot discard a prior close request.StagehandFacadeToolsawaits a host lifecycle callback before returning. Execution and close failures are both preserved, and hydrated snapshots are cleared.browser.close()throws a typedStagehandFacadeLifecycleErrorinstead of silently claiming cleanup.@browserbasehq/sdkwith a 10-second per-attempt timeout and two transient retries. An ambiguous failed update is verified withsessions.retrieve; onlyCOMPLETEDis accepted.browser.close()from page-onlypage.close().mainintentionally permits unlistednoindex: truedocs pages; the navigation invariant now excludes those pages instead of failing every newly based PR.This is PR 1 of a three-PR stack:
behavior before and after
test plan
The live Eve before/after and Online-Mind2Web-style evidence is reported in the stacked Eve PR, where the Eve-owned persistence and release behavior is introduced.
No changeset is included because the shared integration package and both examples are private.