Skip to content

fix(browser): name the CloakBrowser session cap instead of "target closed" (#225) - #467

Open
Agnik47 wants to merge 1 commit into
agentrhq:mainfrom
Agnik47:fix/225-name-cloak-session-cap
Open

fix(browser): name the CloakBrowser session cap instead of "target closed" (#225)#467
Agnik47 wants to merge 1 commit into
agentrhq:mainfrom
Agnik47:fix/225-name-cloak-session-cap

Conversation

@Agnik47

@Agnik47 Agnik47 commented Aug 28, 2026

Copy link
Copy Markdown
Contributor

Addresses the error-mapping half of #225 (suggested fix 2).

Cause

On CloakBrowser's free tier a second concurrent profile exits with code 76. Playwright surfaces the dead target as Target page, context or browser has been closed, which is also what an externally closed browser, a crash, and a never-started browser all produce. Nothing in the repo matched exit code 76, so the licensing cap arrived as a generic navigation failure:

error:
  code: COMMAND_EXEC
  message: "Pre-navigation to https://x.com failed: page.goto: Target page, context or browser has been closed"

The reporter traced the daemon, profile multiplexing, and CDP end to end before finding the cap — the message pointed nowhere.

Fix

Two mappings onto the BrowserConnectError / 'profile-disconnected' kind that already exists for this:

  • Launch: launchProfileRuntime checks the launch failure for exit code 76 first and reports the session limit and CLOAKBROWSER_LICENSE_KEY.
  • Navigation: when a navigation still fails with a closed-context error after the existing one-shot invalidate-and-retry, the raw error is replaced with one naming the profile that disconnected. The Playwright text is kept in the message, so the cause is not lost.

Another live profile is the one cause that can actually be checked, so it picks the hint rather than being asserted blindly:

  • another profile up → the free-tier one-browser-at-a-time cap, and how to lift it;
  • alone → webcmd daemon restart, and WEBCMD_WINDOW=foreground on macOS.

Deliberately unchanged: the retry ladder itself, non-closed navigation failures (still rethrown by identity), and the page-creation paths — newPage/getPage acquisition still reject with the raw text that existing tests pin.

Not fixed here

Suggested fix 1, the macOS background open -g -n instance being sudden-terminated by LaunchServices, is a CloakBrowser/macOS problem I cannot reproduce or verify on Windows. This PR only makes its symptom legible: a browser that dies on its own now reports a disconnect with a restart hint instead of a navigation error.

Tests

src/browser/runtime/local-cloak/session-manager.test.ts:

  • a launch rejecting with Process exited with code 76 produces BROWSER_CONNECT / profile-disconnected, names the license key, and preserves the original text;
  • with a peer profile alive, a repeatedly closed navigation on actor names peer and the one-browser-at-a-time cap (the issue's concurrent-profile repro);
  • with no other profile alive, the same failure does not blame concurrency and points at daemon restart;
  • net::ERR_NAME_NOT_RESOLVED is still rejected by identity, with no extra launch.

npx vitest run --project unit src/browser — 47 files, 752 passed, 2 skipped. npm run typecheck and npm run check:typed-error-lint clean.

…osed" (agentrhq#225)

A second concurrent profile exits with code 76 on CloakBrowser's free tier, and
webcmd reported it as `page.goto: Target page, context or browser has been
closed` — the same text an externally closed or crashed browser produces. The
reporter traced the daemon and profile multiplexing end to end before finding
the licensing cap, because the error pointed nowhere.

Two mappings, both onto the existing BrowserConnectError / 'profile-disconnected':

- A launch that fails with exit code 76 now says so and names the license key.
- A navigation that still fails with a closed-context error after the existing
  one-shot recovery retry now reports which profile disconnected, and keeps the
  Playwright text as the cause rather than dropping it.

Another live profile is the one cause we can actually check, so it decides the
hint: with a second profile up, the cap is named; alone, the hint points at
`daemon restart` and the macOS foreground window mode. Non-closed navigation
failures and the page-creation paths are untouched.

This is the error-mapping half of agentrhq#225. The macOS background `open -g` launch
that self-terminates is a CloakBrowser/LaunchServices issue and is not fixed here.
@github-actions

Copy link
Copy Markdown
Contributor

🟠 Maintainer review suggested — low confidence

The automated review could not reach a fully supported conclusion.

This review is advisory and does not block merging.

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.

1 participant