browser-search icon indicating copy to clipboard operation
browser-search copied to clipboard

smart-extract hangs and loses results when Camofox gets stuck after a session destroy

Open Johell1NS opened this issue 1 month ago • 0 comments

Problem

When Camofox gets stuck, smart-extract.mjs keeps retrying on a dead server and, once killed by an outer timeout, prints nothing, even for URLs it had already extracted successfully.

Observed on Raspberry Pi 5 with Camofox 1.18.1:

  1. Two pages were extracted fine (Readability in ~25 ms).
  2. A third page (a forum behind a Cloudflare challenge) crashed the page: evaluate failed: Target page, context or browser has been closed, followed by destroying session.
  3. From then on every POST /tabs hung and failed with tab create timed out after 30000ms (7 consecutive requests, across two separate smart-extract runs), while /health kept reporting browserRunning: true, browserConnected: true.
  4. The server only recovered when the idle shutdown killed the browser a few minutes later.

The skill made it worse:

  • camofox.mjs only recovers from 503; the stuck state returns 500 (the body is just Internal server error, the real reason is masked by the server), so no recovery was attempted.
  • smart-extract.mjs has no notion of a stuck Camofox: every remaining URL goes through readability (45s) -> snapshot (30s) -> tab open (15s).
  • JSON is written only at the very end, so the two URLs already extracted were lost when the 120s outer timeout killed the process.

Fix

  • camofox.mjs: after a 500 on POST /tabs, probe the browser by opening http://example.com with a short client timeout (camofox-client.mjs createTab gets an optional timeoutMs). If the probe works, the problem is the URL (dead domain, slow site) and nothing is restarted. If it fails, the browser is stopped (/stop, with docker restart as fallback), restarted, and the tab creation is retried once. If the restart itself fails, the error carries a camofox_stuck marker.
  • smart-extract.mjs: on camofox_stuck, skip Camofox for the remaining URLs (the existing escalation to CloakBrowser applies). On SIGTERM/SIGINT, print the results already collected as mode: "partial" instead of exiting silently.
  • SKILL.md: short note on what to do after a timeout or a partial result.

Verification

  • Dead domain followed by a normal URL: no restart, normal URL extracted via Camofox.
  • Browser process frozen with SIGSTOP: probe fails, browser restarted, both URLs extracted (~60s total).
  • timeout -s TERM 5 ...: mode: "partial" with the URLs already extracted.

Known limits

  • The stuck state was simulated by freezing the browser process; the original page crash is no longer reproducible on demand.
  • /stop closes sessions of every Camofox user, but it only runs when the probe has shown the browser is really stuck.
  • Partial output works on SIGTERM/SIGINT, not SIGKILL; POSIX signal support is limited on Windows.

Johell1NS avatar Oct 22 '26 08:10 Johell1NS