Repository navigation
[fix]: don't auto-relaunch on daemon response - #3426
Merged
Merged
Conversation
🦋 Changeset detectedLatest commit: 32dc50f 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
There was a problem hiding this comment.
1 issue found across 8 files
Confidence score: 3/5
- In
packages/cli/src/lib/driver/command-cli.ts, if another command replaces the daemon on the session socket first, this command can run against the replacement instead of returningdaemon_not_running. Preserve the selected daemon identity and verify it at dispatch.
Prompt for AI agents (unresolved issues)
Check if these issues are valid — if so, understand the root cause of each and fix them. When an issue isn't valid or won't be fixed in this PR, reply in its thread with the reason and then resolve the thread. If appropriate, use sub-agents to investigate and fix each issue separately.
<file name="packages/cli/src/lib/driver/command-cli.ts">
<violation number="1" location="packages/cli/src/lib/driver/command-cli.ts:92">
P2: Preserve the selected daemon identity and verify it at dispatch; otherwise, if another command replaces it on the session socket first, this command runs against the replacement instead of returning `daemon_not_running`.</violation>
</file>
Architecture diagram
sequenceDiagram
participant CLI as CLI Command
participant F as Flags Parser
participant R as resolveDriverSession()
participant DC as Daemon Client
participant RT as runDriverCommand()
participant CD as Create Daemon
participant SD as Session Daemon
participant UC as User Code
Note over CLI,UC: Session Selection and Reuse Flow
CLI->>F: Parse command flags
F-->>CLI: DriverFlags
CLI->>R: resolveDriverSession(session, flags)
alt Explicit target with mode-only flags
R->>DC: getDriverStatus(session)
DC-->>R: Status reply (if running)
else No explicit target
R->>DC: getDriverStatus(session)
DC-->>R: Status reply (if running)
end
alt Daemon running
R->>R: Check target compatibility
alt Compatible or no explicit target
R-->>CLI: { kind: "existing" }
else Incompatible target
R-->>CLI: Throw conflict error
end
else No daemon running
R->>F: resolveConnectionTarget(flags)
F-->>R: ConnectionTarget
R-->>CLI: { kind: "create", target }
end
CLI->>RT: runDriverCommand(session, selection, command, params)
alt Selection kind is "create"
RT->>CD: ensureDriverDaemon(session, target)
CD->>SD: Spawn daemon process
SD-->>CD: Daemon ready
else Selection kind is "existing"
Note over RT: No daemon creation - reuse only
end
alt Command is "open"
RT->>SD: openViaDaemon(session, url, params)
else Other commands
RT->>SD: runDriverCommandViaDaemon(session, command, params)
end
alt Daemon still running
SD-->>RT: Command result
RT-->>CLI: Output result
CLI-->>UC: Result JSON
else Daemon vanished
SD-->>RT: Connection error
RT-->>CLI: daemon_not_running error
CLI-->>UC: Error output
end
Reply with feedback, questions, or to request a fix.
View guided diff | Turn on auto-fix | Re-trigger cubic
| } | ||
| // A status reply describes a running session; it must never supply the | ||
| // launch options for a replacement if that daemon subsequently disappears. | ||
| return { kind: "existing" }; |
Contributor
There was a problem hiding this comment.
P2: Preserve the selected daemon identity and verify it at dispatch; otherwise, if another command replaces it on the session socket first, this command runs against the replacement instead of returning daemon_not_running.
Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. When an issue isn't valid or won't be fixed in this PR, reply in its thread with the reason and then resolve the thread. At packages/cli/src/lib/driver/command-cli.ts, line 92:
<comment>Preserve the selected daemon identity and verify it at dispatch; otherwise, if another command replaces it on the session socket first, this command runs against the replacement instead of returning `daemon_not_running`.</comment>
<file context>
@@ -69,23 +69,33 @@ export async function runDriverCommandFromFlags(
}
+ // A status reply describes a running session; it must never supply the
+ // launch options for a replacement if that daemon subsequently disappears.
+ return { kind: "existing" };
}
</file context>
akeimach
approved these changes
Nov 9, 2026
This was referenced Nov 9, 2026
shrey150
pushed a commit
that referenced
this pull request
Nov 13, 2026
Release Browse independently of the Stagehand SDKs. Merging this PR publishes the CLI from the merged commit. ## 0.11.4 ### Patch Changes - [#3426](#3426) [`f93e6d1`](f93e6d1) Thanks [@seanmcguire12](https://github.com/seanmcguire12)! - Report an error when an active browser session disconnects during command startup instead of automatically starting a replacement. - [#3379](#3379) [`73fdba0`](73fdba0) Thanks [@seanmcguire12](https://github.com/seanmcguire12)! - remove unused deepmerge dependency - [#3330](#3330) [`dc8eb40`](dc8eb40) Thanks [@seanmcguire12](https://github.com/seanmcguire12)! - bump zod to 4.6.6 - [#3289](#3289) [`aa67fee`](aa67fee) Thanks [@shrey150](https://github.com/shrey150)! - Add `--stagehand` flag to `browse cloud extensions upload`. - [#3439](#3439) [`2fe947c`](2fe947c) Thanks [@github-actions](https://github.com/apps/github-actions)! - Make `browse doctor` fail and show the cause when the session's last browser start failed - [#3400](#3400) [`ce298c6`](ce298c6) Thanks [@seanmcguire12](https://github.com/seanmcguire12)! - Add token validation to internal local Functions runtime requests - [#3408](#3408) [`6a56cbb`](6a56cbb) Thanks [@seanmcguire12](https://github.com/seanmcguire12)! - Fix Windows package-manager command launching for Functions and templates, and terminate child processes when skill installation times out. - [#3391](#3391) [`3fbda6b`](3fbda6b) Thanks [@seanmcguire12](https://github.com/seanmcguire12)! - Validate daemon directory locations before connecting to a session. Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
3 tasks done
cursor Bot
pushed a commit
that referenced
this pull request
Nov 17, 2026
…emetry The browse CLI regression in v0.11.4 (10% 'unexpected' errors vs 2.2% in v0.11.3) occurred because PR #3426 optimized session reuse to skip daemon re-initialization, exposing paths where daemon errors lacked proper error codes. Root cause: When the daemon or browser is in a bad state, plain Error exceptions are thrown. These propagate to the client without error codes, resulting in 'result_code: unexpected' in telemetry. Changes: - server.ts: formatError now returns 'driver_error' code for non-DriverError exceptions, ensuring all daemon errors have proper telemetry codes - client.ts: Add proper result codes for all error paths: - incompleteResponseError -> daemon_connection_lost - JSON parse errors -> daemon_protocol_error - Socket errors -> daemon_socket_error_{code} - Mode conflicts -> session_mode_conflict - runtime.ts: Auto-recover on 'open' command for recoverable errors: - daemon_not_running: socket connection failed - daemon_connection_lost: daemon closed mid-request - daemon_socket_error_*: socket errors (EPIPE, ECONNRESET, etc) - Excludes daemon_socket_timeout to avoid risking two daemons on one session Fixes the regression by ensuring daemon errors have proper codes (preventing 'unexpected' telemetry) and recovering gracefully for the 'open' command. Co-authored-by: Shrey Pandya <[email protected]>
cursor Bot
pushed a commit
that referenced
this pull request
Nov 17, 2026
…emetry The browse CLI regression in v0.11.4 (10% 'unexpected' errors vs 2.2% in v0.11.3) occurred because PR #3426 optimized session reuse to skip daemon re-initialization, exposing paths where daemon errors lacked proper error codes. Root cause: When the daemon or browser is in a bad state, plain Error exceptions are thrown. These propagate to the client without error codes, resulting in 'result_code: unexpected' in telemetry. Changes: - server.ts: formatError now returns 'driver_error' code for non-DriverError exceptions, ensuring all daemon errors have proper telemetry codes - client.ts: Add proper result codes for all error paths: - incompleteResponseError -> daemon_connection_lost - JSON parse errors -> daemon_protocol_error - Socket errors -> daemon_socket_error_{code} - Mode conflicts -> session_mode_conflict - runtime.ts: Auto-recover on 'open' command for recoverable errors: - daemon_not_running: socket connection failed - daemon_connection_lost: daemon closed mid-request - daemon_socket_error_*: socket errors (EPIPE, ECONNRESET, etc) - Excludes daemon_socket_timeout to avoid risking two daemons on one session Fixes the regression by ensuring daemon errors have proper codes (preventing 'unexpected' telemetry) and recovering gracefully for the 'open' command. Co-authored-by: Shrey Pandya <[email protected]>
cursor Bot
pushed a commit
that referenced
this pull request
Nov 17, 2026
…emetry The browse CLI regression in v0.11.4 (10% 'unexpected' errors vs 2.2% in v0.11.3) occurred because PR #3426 optimized session reuse to skip daemon re-initialization, exposing paths where daemon errors lacked proper error codes. Root cause: When the daemon or browser is in a bad state, plain Error exceptions are thrown. These propagate to the client without error codes, resulting in 'result_code: unexpected' in telemetry. Changes: - server.ts: formatError now returns 'driver_error' code for non-DriverError exceptions, ensuring all daemon errors have proper telemetry codes - client.ts: Add proper result codes for all error paths: - incompleteResponseError -> daemon_connection_lost - JSON parse errors -> daemon_protocol_error - Socket errors -> daemon_socket_error_{code} - Mode conflicts -> session_mode_conflict - runtime.ts: Auto-recover on 'open' command for recoverable errors: - daemon_not_running: socket connection failed - daemon_connection_lost: daemon closed mid-request - daemon_socket_error_*: socket errors (EPIPE, ECONNRESET, etc) - Excludes daemon_socket_timeout to avoid risking two daemons on one session Fixes the regression by ensuring daemon errors have proper codes (preventing 'unexpected' telemetry) and recovering gracefully for the 'open' command. Co-authored-by: Shrey Pandya <[email protected]>
cursor Bot
pushed a commit
that referenced
this pull request
Nov 17, 2026
…emetry The browse CLI regression in v0.11.4 (10% 'unexpected' errors vs 2.2% in v0.11.3) occurred because PR #3426 optimized session reuse to skip daemon re-initialization, exposing paths where daemon errors lacked proper error codes. Root cause: When the daemon or browser is in a bad state, plain Error exceptions are thrown. These propagate to the client without error codes, resulting in 'result_code: unexpected' in telemetry. Changes: - server.ts: formatError now returns 'driver_error' code for non-DriverError exceptions, ensuring all daemon errors have proper telemetry codes - client.ts: Add proper result codes for all error paths: - incompleteResponseError -> daemon_connection_lost - JSON parse errors -> daemon_protocol_error - Socket errors -> daemon_socket_error_{code} - Mode conflicts -> session_mode_conflict - runtime.ts: Auto-recover on 'open' command for recoverable errors: - daemon_not_running: socket connection failed - daemon_connection_lost: daemon closed mid-request - daemon_socket_error_*: socket errors (EPIPE, ECONNRESET, etc) - Excludes daemon_socket_timeout to avoid risking two daemons on one session Fixes the regression by ensuring daemon errors have proper codes (preventing 'unexpected' telemetry) and recovering gracefully for the 'open' command. Co-authored-by: Shrey Pandya <[email protected]>
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
what changed
test plan
Summary by cubic
Stops the CLI from auto-relaunching a session with the daemon's reported launch settings when the daemon disappears.
daemon_not_runninginstead of starting a replacement.browse stop --session <name>before changing them.README.Written for commit 32dc50f. Summary will update on new commits.