fix: allow concurrent streamable http requests - #1186
Open
nickcoai wants to merge 5 commits into
Open
Conversation
nickcoai
force-pushed
the
agent/configurable-streamable-http-parallelism
branch
from
August 18, 2026 15:55
fac20e9 to
fd439b3
Compare
Keep cancellation and replies available while old session POSTs finish. Bound the wait for old POSTs and the replacement initialization handshake. Do not retry interrupted POSTs because the server may have processed them. Add regressions for recovery, queued cancellation, control timeouts, and server replies needed by active requests.
Match responses against all pending requests before removing a stream registration. Keep distinct numeric and string ids separate while preserving the existing fallback for servers that stringify numeric ids. Add a mixed-id regression and keep a separate registration owner alive in the abandoned-cancellation test.
nickcoai
marked this pull request as ready for review
August 22, 2026 16:46
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.
Summary
Allow ordinary streamable http POSTs to run concurrently. Previously, one slow
application/jsonresponse blocked unrelated requests.StreamableHttpClientTransportConfig::max_concurrent_requestsdefaults to 16. Set it to1to keep ordinary POSTs serial;0is treated as1. Open sse response streams do not count against this limit. Initialization and protocol-version changes remain ordered with ordinary POSTs.Response cleanup matches ids against all pending requests, not just open response streams. Exact ids take precedence over the existing numeric-string fallback.
Cancellation and recovery
Cancellation and replies to server requests use a separate bounded queue with one extra POST slot. Each control POST has a five-second timeout after it starts. Queued and active ordinary POSTs can be cancelled without waiting for a free slot.
For an open legacy response stream, cancellation stops reading but keeps the stream alive until the cancellation send finishes or is dropped. This lets custom http adapters handle cancellation using their existing stream state. Ordinary legacy cancellation notifications still reach the adapter; modern http cancellation remains local.
When recovery is enabled, ordinary POSTs that report
SessionExpiredin the same session share one recovery attempt. Wait up tosession_recovery_timeoutfor old POSTs, then stop any that remain. Those interrupted POSTs returnSessionRecoveryTimeoutand are not retried: the server may have processed them. The replacement handshake has a separate timeout of the same length; both default to five seconds.Retry only ordinary POSTs that returned
SessionExpired, at most once each. Control POSTs are not retried. A request that already completed on the common response stream is not retried. Old queued controls cannot change replacement-session state, and a cancelled or dropped version-change request does not block later requests.The shared worker's control queue is opt-in; server scheduling is unchanged. Callers still decide which tools may run together and which need approval. Oauth refresh coordination remains a separate follow-up.
Validation
Passed locally:
cargo +1.96 test --offline --all-featuresjustfile: 35 tests covering concurrency, subscriptions, expired sessions, disconnects, connection reuse, and shutdown.cargo +1.96 clippy --offline --all-targets --all-features -- -D warningscargo +nightly fmt --all -- --checkgit diff --checkTwo downstream custom-adapter integration tests also passed without adapter source changes.