Repository navigation
fix(cli): classify page-level failures with stable error codes - #3515
Merged
Merged
Conversation
Add error-classifier.ts to map known error patterns to typed DriverError instances with stable codes. This replaces 'unexpected' telemetry results for common failures like element_not_found, wait_timeout, navigation_timeout, page_unresponsive, invalid_url, browser_disconnected, cdp_unreachable, and last_tab. Also: - daemon/client.ts: add session_mode_conflict code - local-cdp-discovery.ts, resolve-ws.ts: add cdp_unreachable code - commands/tabs.ts: add last_tab code Co-authored-by: Shrey Pandya <[email protected]>
🦋 Changeset detectedLatest commit: 28a39fd 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.
All reported issues were addressed across 9 files
Architecture diagram
sequenceDiagram
participant CLI as browse CLI
participant Daemon as daemon/server.ts
participant Classifier as error-classifier.ts
participant Handler as Driver Command Handlers
participant CDP as CDP / Browser
Note over CLI,CDP: Error Classification Flow - Page-Level Failures
CLI->>Daemon: Send command request
Daemon->>Handler: Dispatch command (click, wait, open, etc.)
alt Direct DriverError thrown
Handler-->>Daemon: DriverError with code
else Plain Error thrown
Handler->>CDP: Browser operation (goto, waitForSelector, evaluate)
CDP-->>Handler: Error response
Handler-->>Daemon: Plain Error (unexpected)
Daemon->>Classifier: classifyDriverError(error)
alt Pattern match found
Classifier->>Classifier: Match against regex patterns
Classifier-->>Daemon: DriverError with typed code
alt element_not_found
Classifier->>Classifier: Rewrite message with selector
else page_unresponsive
Classifier->>Classifier: Append reset hint message
end
Daemon-->>CLI: Error response with code + message
CLI->>CLI: Report telemetry with result_code
else No pattern match
Classifier-->>Daemon: null
Daemon-->>CLI: Error response (unexpected)
CLI->>CLI: Report telemetry with result_code=unexpected
end
end
Note over CDP: CDP endpoint resolution path
CLI->>Daemon: Request CDP connection
Daemon->>CDP: resolveWsTarget (local port / HTTP endpoint)
alt CDP unreachable
CDP-->>Daemon: DriverError cdp_unreachable
Daemon-->>CLI: Error response with cdp_unreachable
end
Note over Daemon: Session mode conflict check
CLI->>Daemon: Connect to existing session
Daemon->>Daemon: assertCompatibleTarget()
alt Mode mismatch
Daemon-->>CLI: Error with session_mode_conflict
end
Note over CLI: Last tab close protection
CLI->>Handler: tab close command
Handler->>CDP: Get pages
alt Only one tab remaining
Handler-->>Daemon: DriverError last_tab
Daemon-->>CLI: Error with last_tab code
end
Reply with feedback, questions, or to request a fix.
View guided diff | Turn on auto-fix | Re-trigger cubic
… catch - Fix wait_timeout pattern to match actual message format - Handle DriverError in CLI catch block to report codes in telemetry - Update tests with real error messages from live testing Co-authored-by: Shrey Pandya <[email protected]>
Co-authored-by: Shrey Pandya <[email protected]>
Kylejeong2
approved these changes
Nov 20, 2026
cursor Bot
pushed a commit
that referenced
this pull request
Nov 21, 2026
Resolve conflict in packages/sdk-ts/src/cdpClient.ts by integrating: - Stale service worker detection and reload from main (#3515) - Protocol incompatibility auto-replacement from this PR Consolidate changesets into single fix-cdp-attach-extension-install.md Co-authored-by: Shrey Pandya <[email protected]>
This was referenced Nov 21, 2026
cursor Bot
pushed a commit
that referenced
this pull request
Nov 26, 2026
Merge origin/main into cursor/fix-remote-session-status-propagation-38a5 Conflicts resolved: - packages/cli/src/lib/driver/remote.ts: Keep PR's extractHttpStatus/extractUpstreamMessage helpers for cause chain extraction and 402/429 handling, incorporate main's removal of redundant JSDoc comments - packages/cli/src/lib/driver/remote.disabled.ts: Keep PR's extractHttpStatus function for consistent httpStatus extraction in disabled stub Changes from main: - locator.filter() feature (#3567) - page-level error classification (#3515) - bare hostname URL fix (#3512) - comment removal cleanup (#3538) - other SDK and CLI improvements 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
PostHog data (14 days to Nov 20 2026) shows ~18k browse CLI failures landing as
unexpectedinstead of typed codes:openwaitRoot cause:
daemon/server.tsformatErroronly attached acodeforDriverErrorinstances, so everything else came through asunexpected.what changed
Add
packages/cli/src/lib/driver/error-classifier.tswithclassifyDriverError(error): DriverError | nullcalled indaemon/server.tsformatErrorfor non-DriverError errors. Also handleDriverErrorin CLI catch block to report codes in telemetry for errors thrown before the daemon starts.Classified codes:
element_not_found— "Could not find an element for the given xPath(s): …"wait_timeout— waitForSelector timeoutnavigation_timeout— page.goto RPC timeout, navigation start timeoutpage_unresponsive— page.title/url/evaluate/screenshot RPC timeout, enabling DOM timeoutinvalid_url— invalid navigation URLbrowser_disconnected— RPC client closedcdp_unreachable— CDP endpoint resolution failedlast_tab— cannot close the last tabsession_mode_conflict— session mode mismatchAlso rewrites the
element_not_foundmessage from the misleading "xPath(s)" to:before (main)
after (this branch)
test plan
pnpm build --filter=browse— TypeScript compilespnpm vitest run tests/error-classifier.test.ts— 17 test cases covering all patternspnpm vitest run tests/driver-errors.test.ts— includes formatError integration testpnpm vitest run(all CLI tests) — 719 tests pass--local --headless) withBROWSERBASE_TELEMETRY_HOSTto a local listenerSummary by cubic
Classifies common
browseCLI failures with stable error codes so telemetry stops reporting them asunexpected. Previously onlyDriverErrorinstances carried a code; now a new classifier maps known error messages (element not found, wait/navigation timeouts, unresponsive pages, invalid URLs, disconnected browsers, unreachable CDP endpoints, closing the last tab) and rewrites theelement_not_foundmessage to mention the selector instead of "xPath(s)".classifyDriverErrorinerror-classifier.ts, called fromdaemon/server.tsformatErrorfor non-DriverErrorerrors.DriverErrorinbase.ts; matcheswait_timeoutagainst the actual "waitForSelector timed out after" message format.cdp_unreachable,last_tab, andsession_mode_conflict.navigation_timeoutalso coverspage.reload,page.go_back, andpage.go_forwardtimeouts.Written for commit 28a39fd. Summary will update on new commits.