Skip to content

fix(cli): classify page-level failures with stable error codes - #3515

Merged
shrey150 merged 3 commits into
mainfrom
cursor/error-classifier-8cef
Nov 20, 2026
Merged

shrey150 merged 3 commits into
mainfrom
cursor/error-classifier-8cef

Conversation

@shrey150

@shrey150 shrey150 commented Nov 20, 2026 •

Copy link
Copy Markdown
Collaborator

why

PostHog data (14 days to Nov 20 2026) shows ~18k browse CLI failures landing as unexpected instead of typed codes:

command unexpected fails installs
open 8,139 1,462 (3.1% of opens)
get/click/fill 6,467 1,057 (~2%)
wait 2,429 401 (mostly 30s timeouts)
screenshot 1,207 247

Root cause: daemon/server.ts formatError only attached a code for DriverError instances, so everything else came through as unexpected.

what changed

Add packages/cli/src/lib/driver/error-classifier.ts with classifyDriverError(error): DriverError | null called in daemon/server.ts formatError for non-DriverError errors. Also handle DriverError in 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 timeout
  • navigation_timeout — page.goto RPC timeout, navigation start timeout
  • page_unresponsive — page.title/url/evaluate/screenshot RPC timeout, enabling DOM timeout
  • invalid_url — invalid navigation URL
  • browser_disconnected — RPC client closed
  • cdp_unreachable — CDP endpoint resolution failed
  • last_tab — cannot close the last tab
  • session_mode_conflict — session mode mismatch

Also rewrites the element_not_found message from the misleading "xPath(s)" to:

No element matches "selector". Run browse snapshot for fresh refs or check the selector.

before (main)

$ browse click .nonexistent
Could not find an element for the given xPath(s): .nonexistent
# telemetry: result_code=unexpected

$ browse wait selector .loading --timeout 2000
waitForSelector timed out after 2000ms while waiting for selector
# telemetry: result_code=unexpected

$ browse tab close
Cannot close the last tab.
# telemetry: result_code=unexpected

$ browse open http://localhost:8000 --cdp 9998
Error: Unable to resolve CDP endpoint from port 9998. Is Chrome running with remote debugging?
# telemetry: result_code=unexpected

after (this branch)

$ browse click .nonexistent
No element matches ".nonexistent". Run browse snapshot for fresh refs or check the selector.
# telemetry: result_code=element_not_found

$ browse wait selector .loading --timeout 2000
waitForSelector timed out after 2000ms while waiting for selector
# telemetry: result_code=wait_timeout

$ browse tab close
Cannot close the last tab.
# telemetry: result_code=last_tab

$ browse open http://localhost:8000 --cdp 9998
DriverError: Unable to resolve CDP endpoint from port 9998. Is Chrome running with remote debugging?
Code: cdp_unreachable
# telemetry: result_code=cdp_unreachable

test plan

  • pnpm build --filter=browse — TypeScript compiles
  • pnpm vitest run tests/error-classifier.test.ts — 17 test cases covering all patterns
  • pnpm vitest run tests/driver-errors.test.ts — includes formatError integration test
  • pnpm vitest run (all CLI tests) — 719 tests pass
  • Live testing against local Chrome (--local --headless) with BROWSERBASE_TELEMETRY_HOST to a local listener
  • Formatting check passes
Open in Web Open in Cursor 

Summary by cubic

Classifies common browse CLI failures with stable error codes so telemetry stops reporting them as unexpected. Previously only DriverError instances 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 the element_not_found message to mention the selector instead of "xPath(s)".

  • Adds classifyDriverError in error-classifier.ts, called from daemon/server.ts formatError for non-DriverError errors.
  • Reports typed codes in CLI telemetry by handling DriverError in base.ts; matches wait_timeout against the actual "waitForSelector timed out after" message format.
  • Adds typed codes at throw sites: cdp_unreachable, last_tab, and session_mode_conflict.
  • navigation_timeout also covers page.reload, page.go_back, and page.go_forward timeouts.
  • Includes 19 classifier test cases plus formatError integration tests; all 719 CLI tests pass.

Written for commit 28a39fd. Summary will update on new commits.

View guided diff Turn on auto-fix

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-bot

changeset-bot Bot commented Nov 20, 2026 •

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 28a39fd

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
browse Patch

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

@cubic-dev-ai cubic-dev-ai Bot left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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
Loading

Reply with feedback, questions, or to request a fix.

View guided diff | Turn on auto-fix | Re-trigger cubic

cursoragent and others added 2 commits November 20, 2026 19:16
… 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]>
@shrey150
shrey150 merged commit b3391cd into main Nov 20, 2026
30 checks passed
@shrey150
shrey150 deleted the cursor/error-classifier-8cef branch November 20, 2026 22:55
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]>
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]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants