Repository navigation
Conversation
Track close generations on DriverSessionManager so an initialize() call that finishes after close() tears down the newly created Stagehand and browser instead of installing them on a closed session.
🦋 Changeset detectedLatest commit: c14322d The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
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 |
Contributor
|
This PR is from an external contributor and must be approved by a stagehand team member with write access before CI can run. |
This branch has not been deployed
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
Fixes #3485.
If
browse stop(orSIGTERM) closes the driver daemon while its initial browser launch is still in flight — for example after thebrowse openclient disconnects via Ctrl+C or a request timeout —DriverSessionManager.close()seesthis.stagehand === nullandthis.browser === nulland returns immediately, allowing the daemon to unlink its socket and PID files. When the pendinginitialize()call then finishes, it unconditionally assignsthis.browser,this.stagehand, andthis.context, leaving the newly launched browser (or remote Browserbase session) open inside an unreachable daemon process.what changed
packages/cli/src/lib/driver/session-manager.ts: track acloseGenerationcounter incremented inclose(). Capture the generation at the start ofinitialize(), and ifclose()ran beforeStagehand.create()completed, close theStagehandinstance and throw so the existingcatchblock closesbrowserinstead of installing it on the closed manager.packages/cli/tests/driver-foundation.test.ts: add unit and real daemon-socket regression tests coveringDriverSessionManager.close()and astoprequest arriving over the daemon socket whileopen's browser launch is still pending..changeset/close-in-flight-browser-launch.md: add abrowsepatch changeset.test plan
main(8901460d,closeStagehand/closeBrowsercalled0times) and pass with the fix.browse daemonprocess and headless Chrome: dropping an in-flightopenclient and sendingstopover the unix socket previously left bothdaemonand headless Chrome alive after.sock/.pidremoval; with this fix, Chrome closes anddaemonexits with code0.pnpm --filter browse lint(format:check,oxlint,tsc --noEmit),pnpm --filter browse build, and the fullpackages/clivitest suite (44 passedfiles,589 passedtests) pass.Summary by cubic
Fixes
browse stop(orSIGTERM) leaving a browser running in an unreachable daemon when the close happens while the initial browser launch is still in flight.DriverSessionManagernow tracks a close generation, so aninitialize()that finishes afterclose()tears down the newly created Stagehand and browser instead of installing them on the closed session.browsepatch changeset.Written for commit c14322d. Summary will update on new commits.