stagehand-python@4.0.3a0.dev1476
stagehand-python@4.0.3a0.dev1476: [fix]: align `browser.close` and `context.close` semantics (#2827)
# why `browser.close()` & `browser.context.close()` should both explicitly terminate the browser before this PR, `browser.close()` only terminated launched browsers when `keepAlive` was false. keepalive browsers were disconnected, connected local browsers did not receive `Browser.close`, & connected Browserbase sessions were not released `browser.context.close()` disposed worker state without terminating the browser. this was semantically weird, because it was never really clear what it was supposed to be "closing". it was not a full `stagehand.close()`, nor was it a full `browser.close()`. this method is being left in place so as to not break downstream callers, but it is now just an alias for `browser.close()` ### after this PR: - `browser.close()` & `browser.context.close()` invoke the same close operation. `context.close` is also removed from the protocol - explicit close terminates launched local browsers for either `keepAlive` value; - explicit close sends CDP `Browser.close` to connected local browsers; - explicit close requests release of launched & connected Browserbase sessions; & - `keepAlive` only affects internal invalidation after initialization failure, not explicit close # what changed - stopped calling public `browser.close()` when `Stagehand.create()` fails; failed initialization now makes the SDK browser handle unusable & applies the existing keepalive cleanup behavior - changed ambiguous `Stagehand.create()` failure cleanup to invalidate the browser without overriding its keepalive policy - made explicit close invoke the local process termination callback for both keepalive values - added explicit Browserbase session release for launched & connected sessions - added root CDP `Browser.close` handling for connected local browsers - kept the host CDP transport open until the provider-specific termination request is dispatched - continued cleanup after termination or transport errors & preserved combined failures - changed each public context wrapper to call its owning browser's memoized close operation instead of sending `context.close` - removed the unused `context.close` operation from the protocol, extension, generated SDK models, & RPC timeout tables # test plan - [x] TypeScript, Python, & Go tests verify explicit close terminates launched local browsers for both keepalive values. - [x] TypeScript, Python, & Go tests verify connected local close sends CDP `Browser.close`. - [x] TypeScript, Python, & Go tests verify launched & connected Browserbase close requests session release. - [x] TypeScript, Python, & Go tests verify initialization failure uses internal invalidation instead of explicit termination. - [x] TypeScript, Python, & Go tests verify browser & context close share one memoized operation. - [x] TypeScript, Python, & Go tests verify context close no longer sends the legacy `context.close` RPC.