Skip to content

fix(wait): avoid 180s mutex stall when a dialog opens during an action - #2427

Merged
Lightning00Blade merged 6 commits into
ChromeDevTools:mainfrom
ch-bas:fix/waitfor-dialog-stall
Jul 30, 2026
Merged

Lightning00Blade merged 6 commits into
ChromeDevTools:mainfrom
ch-bas:fix/waitfor-dialog-stall

Conversation

@ch-bas

@ch-bas ch-bas commented Jul 27, 2026

Copy link
Copy Markdown
Contributor

Fixes #2426

Problem

When a tool that passes no handleDialog (click, hover, fill, type_text, drag, new_page) runs an action that opens a JS dialog, McpPage's persistent listener stores the dialog but never dismisses it, so the renderer stays paused. WaitForHelper then ran waitForStableDom, whose setup evaluateHandle (WaitForHelper.ts:43) hung until Puppeteer's default protocolTimeout (180s, none is configured). That await happens while ToolHandler holds the single, timeout-less tool mutex, so every queued call — including handle_dialog, the only remedy — was blocked ~180s, freezing the session.

Verified empirically: with a dialog left open, page.evaluateHandle() hangs until protocolTimeout then throws ProtocolError.

Fix

  • (A) Correctness: always register the dialog listener (not only when handleDialog is set) and record any observed dialog in a separate #dialogDetected flag, then skip waitForStableDom when it is set. #dialogDetected does not affect dialogHandled, so callers that clearDialog() on dialogHandled (navigate_page, the worker/page paths of evaluate_script) are unaffected and never clear a genuinely-open dialog. The action returns promptly and the next dialog-blocked tool fails fast with "A dialog is open", prompting handle_dialog.
  • (B) Defense-in-depth: bound the waitForStableDom setup evaluation with the abort signal and the stable-DOM timeout, so any renderer pause can no longer exceed the intended cap.

Testing

  • New tests/WaitForHelper.test.ts with a hanging evaluateHandle stub (fast + deterministic, no 180s wait):
    • does not hang when the DOM-stability setup never resolves — covers (B).
    • skips the DOM-stability wait when a dialog opens (no handleDialog) — covers (A); also asserts dialogHandled stays false.
    • Both fail on main (hang until the test's bound) and pass with this change.
  • Re-ran the suites that exercise waitForEventsAfterAction (input, pages, script, snapshot) — all pass.
  • ESLint + Prettier clean.

When a tool that passes no handleDialog (click, hover, fill, type_text,
drag, new_page) runs an action that opens a JS dialog, McpPage's
persistent listener stores the dialog but never dismisses it, so the
renderer stays paused. WaitForHelper then ran waitForStableDom, whose
setup evaluateHandle hung until Puppeteer's default protocolTimeout
(180s) because no protocolTimeout is configured. That await happens
while ToolHandler holds the single, timeout-less tool mutex, so every
queued call - including handle_dialog, the only remedy - was blocked for
~180s, freezing the session.

Two fixes:
- (A) Always register the dialog listener (not only when handleDialog is
  set) and record any observed dialog in a separate #dialogDetected flag,
  then skip waitForStableDom when it is set. #dialogDetected does not
  affect dialogHandled, so callers that clearDialog() on dialogHandled
  are unaffected and never clear a genuinely-open dialog.
- (B) Defense-in-depth: bound the waitForStableDom setup evaluation with
  the abort signal and the stable-DOM timeout so any renderer pause can
  no longer exceed the intended cap.

Adds fast, deterministic regression tests (a hanging evaluateHandle stub)
that fail on the previous behavior.

Fixes ChromeDevTools#2426
@OrKoN
OrKoN requested a review from Lightning00Blade July 27, 2026 11:55

@Lightning00Blade Lightning00Blade left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Code wide looks good, lets change the test to reuse a real page.

Comment thread src/WaitForHelper.ts Resolved
Comment thread src/WaitForHelper.ts Resolved
Comment thread tests/WaitForHelper.test.ts Resolved
Comment thread src/WaitForHelper.ts Resolved
- Rename #dialogOpened to #dialogHandled.
- Skip the DOM-stability wait on #dialogDetected alone, which already
  covers the handled case.
- Simplify the waitForStableDom setup race to a single trailing catch.
- Rewrite the regression test to drive a real page instead of mocks.
@ch-bas

ch-bas commented Jul 28, 2026

Copy link
Copy Markdown
Contributor Author

Thanks for the review! Addressed in the follow-up commit:

  • Renamed #dialogOpened → #dialogHandled and dropped the comment.
  • Skip the DOM-stability wait on #dialogDetected alone — it's set for every observed dialog, so it already covers the handled case.
  • Simplified the waitForStableDom setup race to a single trailing .catch(...).
  • Rewrote the regression test to drive a real page via withMcpContext (opens a dialog from the action with no handleDialog, asserts the call returns promptly instead of stalling and that the dialog is still recorded).

One small note: I used .catch(() => undefined) instead of the suggested .catch(() => {}) because the repo's @typescript-eslint/no-empty-function rule rejects the empty body — same behavior, lint-clean.

Comment thread tests/WaitForHelper.test.ts Resolved
Comment thread tests/WaitForHelper.test.ts Resolved
Comment thread tests/WaitForHelper.test.ts Resolved
Comment thread tests/WaitForHelper.test.ts Resolved
Comment thread src/WaitForHelper.ts Resolved
- Move the dialog-tracking note to a JSDoc on #dialogDetected.
- Test: correct copyright year, drop the stall timeout to 5s with a note
  tying it to WaitForHelper.#stableDomTimeout, use assert() for the
  stall check, and drop the manual dialog cleanup (page teardown handles
  an open dialog).
@ch-bas

ch-bas commented Jul 29, 2026

Copy link
Copy Markdown
Contributor Author

Thanks for the approval! Addressed the nits in the follow-up commit:

  • Moved the dialog-tracking note to a JSDoc on #dialogDetected (Track all dialogs as they pause the renderer).
  • Test: fixed the copyright year, dropped the stall timeout to 5_000 with a comment tying it to WaitForHelper.#stableDomTimeout, and switched the stall check to assert(result !== 'stalled', ...).
  • Re the cleanup question — you're right: I verified the page tears down fine with an open dialog, so I removed the manual dismiss()/clearDialog().

Verified against the freshly-merged base (puppeteer 25.4.0): the WaitForHelper test plus the input/script suites pass, and lint is clean.

@Lightning00Blade
Lightning00Blade added this pull request to the merge queue Jul 30, 2026
Merged via the queue into ChromeDevTools:main with commit b4e8f74 Jul 30, 2026
27 of 29 checks passed
OrKoN pushed a commit to LuHuangMSFT/chrome-devtools-mcp that referenced this pull request Aug 10, 2026
🤖 I have created a release *beep* *boop*
---


##
[1.7.0](ChromeDevTools/chrome-devtools-mcp@chrome-devtools-mcp-v1.6.0...chrome-devtools-mcp-v1.7.0)
(2026-08-10)


### 🎉 Features

* add a utility function to check for localhost.
([ChromeDevTools#2454](ChromeDevTools#2454))
([c5ebf9e](ChromeDevTools@c5ebf9e))
* Add get_heapsnapshot_object_details MCP tool
([ChromeDevTools#2374](ChromeDevTools#2374))
([8432cb9](ChromeDevTools@8432cb9))
* Emit native contexts in snapshot summary
([ChromeDevTools#2375](ChromeDevTools#2375))
([f78a911](ChromeDevTools@f78a911))
* Filter heap snapshot objects by native context
([ChromeDevTools#2377](ChromeDevTools#2377))
([76fd242](ChromeDevTools@76fd242))
* **telemetry:** log devtools data.
([ChromeDevTools#2460](ChromeDevTools#2460))
([df2c753](ChromeDevTools@df2c753))
* **telemetry:** log is_devtools_open with each tool call.
([ChromeDevTools#2445](ChromeDevTools#2445))
([6f60eab](ChromeDevTools@6f60eab))
* **telemetry:** report whether tool call is made on localhost.
([ChromeDevTools#2455](ChromeDevTools#2455))
([6398b7e](ChromeDevTools@6398b7e))
* update lighthouse to 13.4.1
([ChromeDevTools#2398](ChromeDevTools#2398))
([745ffe7](ChromeDevTools@745ffe7))


### 🛠️ Fixes

* bound per-navigation network request retention
([ChromeDevTools#2435](ChromeDevTools#2435))
([b08c73c](ChromeDevTools@b08c73c))
* **cli:** validate session ids
([ChromeDevTools#2475](ChromeDevTools#2475))
([5ca9121](ChromeDevTools@5ca9121))
* **cli:** warn about version mismatch between cli and daemon
([ChromeDevTools#2461](ChromeDevTools#2461))
([3afc44d](ChromeDevTools@3afc44d))
* **daemon:** preserve hyphenated browser flags in arg serialization and
lazy daemon startup
([ChromeDevTools#2405](ChromeDevTools#2405))
([d79f3ba](ChromeDevTools@d79f3ba))
* dispose heap snapshot workers on context teardown
([ChromeDevTools#2428](ChromeDevTools#2428))
([f245c76](ChromeDevTools@f245c76))
* do not throw synchronously when a CDP session is gone
([ChromeDevTools#2466](ChromeDevTools#2466))
([ba4fe3e](ChromeDevTools@ba4fe3e))
* don't throw if Dialog was handled
([ChromeDevTools#2437](ChromeDevTools#2437))
([574c320](ChromeDevTools@574c320))
* downscale viewport screenshots when no viewport is emulated
([ChromeDevTools#2380](ChromeDevTools#2380))
([39c4140](ChromeDevTools@39c4140))
* improve daemon lifecycle
([ChromeDevTools#2360](ChromeDevTools#2360))
([3ee6a27](ChromeDevTools@3ee6a27))
* improve file writing
([ChromeDevTools#2447](ChromeDevTools#2447))
([1da4bb0](ChromeDevTools@1da4bb0))
* include the tab id in `get_tab_id`'s text response
([ChromeDevTools#2381](ChromeDevTools#2381))
([dcbaf49](ChromeDevTools@dcbaf49))
* **memory:** dispose the heap-snapshot worker when loading fails
([ChromeDevTools#2449](ChromeDevTools#2449))
([744738d](ChromeDevTools@744738d))
* **performance:** reset trace-running flag when start_trace setup fails
([ChromeDevTools#2420](ChromeDevTools#2420))
([40240c0](ChromeDevTools@40240c0))
* regression after the
[ChromeDevTools#2443](ChromeDevTools#2443)
([ChromeDevTools#2462](ChromeDevTools#2462))
([4c80ce4](ChromeDevTools@4c80ce4))
* rename maxRetainedSize column
([ChromeDevTools#2402](ChromeDevTools#2402))
([75c7048](ChromeDevTools@75c7048))
* **screenshot:** dispose element handle after take_screenshot
([ChromeDevTools#2422](ChromeDevTools#2422))
([fffb40e](ChromeDevTools@fffb40e))
* toggle lazy loading for source maps.
([ChromeDevTools#2486](ChromeDevTools#2486))
([8028bfe](ChromeDevTools@8028bfe))
* **wait:** avoid 180s mutex stall when a dialog opens during an action
([ChromeDevTools#2427](ChromeDevTools#2427))
([b4e8f74](ChromeDevTools@b4e8f74))


### 📄 Documentation

* Add devin cli install instruction to README
([ChromeDevTools#2361](ChromeDevTools#2361))
([45262c0](ChromeDevTools@45262c0))
* correct the user data directory documentation
([ChromeDevTools#2473](ChromeDevTools#2473))
([5ddbffd](ChromeDevTools@5ddbffd))
* **skills:** update memory leak debugging skill to use native MCP tools
([ChromeDevTools#2436](ChromeDevTools#2436))
([99bd90a](ChromeDevTools@99bd90a))
* Update Chrome requirement for categoryExperimentalWebmcp
([ChromeDevTools#2163](ChromeDevTools#2163))
([354458e](ChromeDevTools@354458e))
* update security.md
([ChromeDevTools#2362](ChromeDevTools#2362))
([5012b07](ChromeDevTools@5012b07))


### 🏗️ Refactor

* clean up McpResponse.handle
([ChromeDevTools#2392](ChromeDevTools#2392))
([348975d](ChromeDevTools@348975d))
* introduce Explicit resouce managent (using)
([ChromeDevTools#2443](ChromeDevTools#2443))
([5b25370](ChromeDevTools@5b25370))
* move tool groups
([ChromeDevTools#2365](ChromeDevTools#2365))
([2d944f9](ChromeDevTools@2d944f9))
* re-use Puppteer Mutex
([ChromeDevTools#2444](ChromeDevTools#2444))
([775ea2d](ChromeDevTools@775ea2d))
* rename methods for clarity
([ChromeDevTools#2442](ChromeDevTools#2442))
([dc23bcd](ChromeDevTools@dc23bcd))
* use a destructor to shorten the calls
([ChromeDevTools#2376](ChromeDevTools#2376))
([77e1d3f](ChromeDevTools@77e1d3f))

---
This PR was generated with [Release
Please](https://github.com/googleapis/release-please). See
[documentation](https://github.com/googleapis/release-please#release-please).
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.

A dialog opened during a no-handleDialog action freezes the whole session for ~180s (mutex stall in waitForStableDom)

2 participants