Add progress-aware request timeout reset#858
Open
ContextVM-org wants to merge 1 commit into
Open
Conversation
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.
I added opt-in support for resetting a request timeout when a matching
notifications/progressnotification is received.This is useful for long-running MCP operations where the peer is still alive and making progress, but the final response may legitimately take longer than the idle request timeout.
The change keeps existing behavior unchanged by default.
What changed
PeerRequestOptions:reset_timeout_on_progress: boolmax_total_timeout: Option<Duration>PeerRequestOptions::with_timeout(...)PeerRequestOptions::reset_timeout_on_progress()PeerRequestOptions::with_max_total_timeout(...)RequestHandle::await_response()so that:reset_timeout_on_progressis enabledmax_total_timeoutacts as a hard cap and is not reset by progressnotifications/cancelled, matching the existing behavioron_progresshandlers still receive the same notifications.Motivation
The current timeout implementation uses a single fixed
tokio::time::timeout(...)around the response receiver. That works for ordinary requests, but it cannot distinguish between a peer that is offline and a peer that is actively sending progress for a long-running operation.With this patch, callers can opt into idle-timeout semantics:
This means:
Backwards compatibility
This should be backwards compatible:
reset_timeout_on_progressdefaults tofalsemax_total_timeoutdefaults toNoneTests
I added a dedicated test target for request timeout/progress behavior.
Covered cases:
max_total_timeoutwins over progress resetI also verified that the existing progress subscriber behavior still works.
Commands run:
All focused checks passed.
resolves: #834