Skip to content

Fix(cli): recover automatically after browser is closed or crashes#220

Open
Jhoan0714 wants to merge 4 commits into
VibiumDev:mainfrom
Jhoan0714:fix/browser-connection-retry
Open

Fix(cli): recover automatically after browser is closed or crashes#220
Jhoan0714 wants to merge 4 commits into
VibiumDev:mainfrom
Jhoan0714:fix/browser-connection-retry

Conversation

@Jhoan0714

Copy link
Copy Markdown

Summary

This PR fixes #219 the CLI not recovering when the browser is closed manually or crashes externally. Instead of failing with broken pipe error, Vibium now detects the dead connection, relaunches the browser, retries the command once, and prints a short notice to the user.

Root Cause

ensureBrowser() only checked whether h.client was nil. When the browser process died externally, the daemon kept a stale WebSocket client reference. The failure only surfaced later as a low-level network error:

Error: failed to get browsing context: failed to send command: write tcp ...: write: broken pipe

The only workaround was running vibium stop and retrying manually.

Why this matters

  • Common scenario: user closes the browser window
  • Error message gave no indication of what happened or how to recover
  • Breaks the "zero config / just works" experience for CLI users and agents

Fix

Reactive retry in Call() — if a command fails with a connection error (broken pipe, closed network connection, etc.), discard the stale state and retry once:

  • isConnectionError() — classifies connection-death errors vs normal app errors
  • resetBrowserState() — clears client, conn, and launchResult
  • Retry via existing ensureBrowser() lazy-launch path (no changes to individual handlers)

User notice via ToolsCallResult.Notice — optional field so the command result stays clean; CLI prefixes it when present:

Browser connection lost, relaunched automatically - Navigated to https://example.com

Validation

Before fix:

vibium go "https://example.com"
# close browser window manually (or kill Chrome process)
vibium go "https://sahitest.com/demo/training/books.htm"
Error: failed to get browsing context: failed to send command: write tcp [::1]:62525->[::1]:62519: write: broken pipe

After fix:

Browser connection lost, relaunched automatically - Navigated to https://sahitest.com/demo/training/books.htm

Note: after rebuilding, restart the daemon (vibium daemon stop && vibium daemon start) so it loads the new binary.

image

@vincebln2 vincebln2 closed this Jul 10, 2026
@vincebln2 vincebln2 reopened this Jul 10, 2026
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.

CLI does not recover when the browser is closed or crashes externally

2 participants