Skip to content

fix: bound page CDP calls with a timeout; recover handler panics#56

Merged
felixgeelhaar merged 1 commit into
mainfrom
fix/page-timeouts
Jul 5, 2026
Merged

fix: bound page CDP calls with a timeout; recover handler panics#56
felixgeelhaar merged 1 commit into
mainfrom
fix/page-timeouts

Conversation

@felixgeelhaar

Copy link
Copy Markdown
Collaborator

Page CDP calls had no timeout (HIGH)

p.call used p.ctx — a context.Background()-derived context with no deadline — so a call blocked until the connection closed. A hung Chrome, or a handler the watchdog abandoned on timeout, wedged every subsequent operation and held the session lock indefinitely.

Each call now carries a per-call deadline (the session timeout, falling back to cdp.DefaultCallTimeout when unset), so a stuck call fails and releases the lock instead of hanging. This also bounds the watchdog's abandoned-goroutine problem (finding #7) to the session timeout — a full cancellation-propagation fix would need threading ctx through every Session method; the timeout gets the practical protection without that churn.

Watchdog didn't recover handler panics (MEDIUM)

The watchdog ran handlers in a goroutine but never recovered panics — so the session helper's panic(...) when Chrome can't launch (or any handler panic) crashed the whole MCP server. It now recovers into a structured SCOUT_PANIC error envelope, covering all 87 tool handlers at one point. The buffered result channel keeps recovery non-blocking even if the watchdog already timed out and abandoned the goroutine.

Tests

  • New watchdog unit test: a panicking handler yields an error response instead of aborting the process.
  • Full integration suite passes against Chrome under -race with the per-call timeout — no spurious timeouts in real operations.

Scout deep-review batch: page-call timeout (HIGH) + handler-panic (MEDIUM); bounds the watchdog-cancellation finding.

https://claude.ai/code/session_01QKTcmXFTKoTQr7mB3HCuHZ

Page CDP calls used p.ctx — a context.Background()-derived context with no
deadline — so a call blocked until the connection closed. A hung Chrome (or a
handler the watchdog abandoned on timeout) wedged every subsequent operation and
held the session lock indefinitely. Each call now carries a per-call deadline
(the session timeout, falling back to the CDP default), so a stuck call fails
and releases the lock instead of hanging. This also bounds the watchdog's
abandoned-goroutine problem to the session timeout.

The MCP watchdog ran handlers in a goroutine but never recovered panics, so the
session helper's panic when Chrome can't launch (or any handler panic) crashed
the whole server. The watchdog now recovers into a structured SCOUT_PANIC error
envelope, covering all tool handlers at one point.

Tests: a new watchdog test asserts a panicking handler yields an error response
instead of aborting; the full integration suite passes against Chrome under
-race with the per-call timeout (no spurious timeouts). Scout review batch:
findings #6 (page-call timeout, HIGH) and the handler-panic MEDIUM; also bounds
#7 (watchdog cancellation).

Claude-Session: https://claude.ai/code/session_01QKTcmXFTKoTQr7mB3HCuHZ
@felixgeelhaar
felixgeelhaar merged commit 8a14857 into main Jul 5, 2026
7 checks passed
@felixgeelhaar
felixgeelhaar deleted the fix/page-timeouts branch July 5, 2026 07:34
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