Skip to content

fix: do not block tool calls on a roots/list the client is slow to answer - #2477

Merged
nattallius merged 3 commits into
ChromeDevTools:mainfrom
thomasbachem:fix/roots-cache
Aug 12, 2026
Merged

nattallius merged 3 commits into
ChromeDevTools:mainfrom
thomasbachem:fix/roots-cache

Conversation

@thomasbachem

Copy link
Copy Markdown
Contributor

getContext() awaits updateRoots() while ToolHandler.handle() holds the tool mutex, so a client that negotiated roots and never answers blocks every tool for the SDK's 60s default.

This bounds the one awaited listing rather than updateRoots() as a whole, since the other two call sites are already fire-and-forget and bounding them would only throw away roots a slow client was about to send. The last listing is then kept and handed to each new McpContext. Roots are client state rather than browser state, so a reconnect does not invalidate them, and real changes still arrive through roots/list_changed.

Both halves turn out to be needed, which took me a couple of tries to see. Bound every listing and a client answering in 8s never gets roots at all, because each of its listings times out. Leave the background ones unbounded but keep no cache and they are lost anyway, since that listing can land while context is still undefined and context?.setRoots() drops it. Either way, file writes stay confined to the temp directory for the rest of the session, where today that client works and merely waits.

It does mean a client declaring roots without listChanged can see the previous list on its first call against a new context, until the background refresh lands.

Tests for each half:

  • does not block tools if the client never answers roots/list fails on main and passes here. It raises the client-side timeout above the SDK default so the stall surfaces as the assertion rather than as a test timeout
✖ does not block tools if the client never answers roots/list (60902.121334ms)
  AssertionError [ERR_ASSERTION]: list_pages took 60438ms, expected the bounded roots request to settle well before the 60s SDK default
  • still applies roots from a client slower than the bound passes on main and here, and fails if the bound covers every listing rather than the awaited one

npm run test shows four failures here, but the same four fail on unmodified main.

#2285 changes the catch inside updateRoots() that this rewrites, so whichever lands second needs a rebase. Happy to do it if this goes last.

Fixes #2476

@nattallius

Copy link
Copy Markdown
Contributor

Looks good to me

@thomasbachem

Copy link
Copy Markdown
Contributor Author

Rebased onto main – no change to this PR's code.

That picks up #2482, which should cover the two waits failing on the Windows cell at 12.06s. The Lighthouse timeouts in the same run look like separate runner slowness rather than anything this touches.

@nattallius
nattallius enabled auto-merge August 12, 2026 11:04
@nattallius
nattallius added this pull request to the merge queue Aug 12, 2026
Merged via the queue into ChromeDevTools:main with commit d93e667 Aug 12, 2026
20 checks passed
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 client that never answers roots/list blocks every tool for 60s

3 participants