Repository navigation
Conversation
withTimeout rejected the tool call but left retryWithBackoff running, so a slow transient failure (for example a 504 that lands after the timeout) still triggered new requests that nobody was waiting for. withTimeout now passes an AbortSignal that aborts when it fires, and retryWithBackoff stops scheduling attempts once that signal is aborted.
This branch has not been deployed
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.
withTimeoutrejects the tool call when the timeout fires, but theretryWithBackoffloop inside it keeps going. If an attempt fails with a transient status after the timeout (for example a 504 that comes back at ~60s), the loop waits out the backoff and sends another/searchor/contentsrequest, even though the MCP client already got the "timed out" error. With the default of 2 retries, one timed-out call can send up to two extra requests that nobody reads.This change:
withTimeoutnow passes anAbortSignalto the wrapped function and aborts it when the timeout fires.retryOnTransient/retryWithBackofftake an optional signal. Once it is aborted they stop scheduling attempts (the backoff wait also ends early) and rethrow the last error.web_search_exa,web_fetch_exaandweb_search_advanced_exapass the signal through.Existing callers that don't pass a signal behave exactly as before. The in-flight request itself is not cancelled; doing that would need the exa-js bump to a version with per-call
signalsupport (2.26+), which I left out to keep this small.Testing: added two cases to
tests/unit/utils/errorHandler.test.ts. The first wraps a function that fails with a 504 after 40s in a 60swithTimeout; on main it is called a third time after the timeout, with this change it stops at two. Both new tests fail on main and pass here.npm run ci(prettier check, typecheck, vitest: 255 tests) passes.AI-assisted; tested locally with
npm run ci.