Repository navigation
fix: do not block tool calls on a roots/list the client is slow to answer - #2477
Merged
Merged
Conversation
FirdavsIdriszoda
approved these changes
Aug 6, 2026
Contributor
|
Looks good to me |
thomasbachem
force-pushed
the
fix/roots-cache
branch
from
August 11, 2026 16:29
a7bfaa3 to
af85b25
Compare
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
approved these changes
Aug 12, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
getContext()awaitsupdateRoots()whileToolHandler.handle()holds the tool mutex, so a client that negotiatedrootsand 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 newMcpContext. Roots are client state rather than browser state, so a reconnect does not invalidate them, and real changes still arrive throughroots/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
contextis still undefined andcontext?.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
rootswithoutlistChangedcan 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/listfails onmainand passes here. It raises the client-side timeout above the SDK default so the stall surfaces as the assertion rather than as a test timeoutstill applies roots from a client slower than the boundpasses onmainand here, and fails if the bound covers every listing rather than the awaited onenpm run testshows four failures here, but the same four fail on unmodifiedmain.#2285 changes the
catchinsideupdateRoots()that this rewrites, so whichever lands second needs a rebase. Happy to do it if this goes last.Fixes #2476