Repository navigation
Conversation
`SessionBuilder::start_session` sent `session/new` from a task spawned on the connection. An error response made that task fail, which shuts down the whole connection, so the caller never received the error. Send the request as an ordered request and attach the session in its ordered result, as the restore builders do. An error response now reaches the caller, the session's dynamic handlers are dropped so its runners stop after their cleanup, and the connection keeps running. Dropping a pending start cancels the request instead of failing the connection when the late response arrives.
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.
Problem
SessionBuilder::start_session(protocol v1) sendssession/newfrom a task spawned withConnectionTo::spawn. When the agent answers with an error, for exampleauth_required, that task returnsErr, and a failed spawned task shuts down the whole connection. The caller never receives the error:start_session().awaitresolves only as the connection ends, andconnect_withends with the agent's error.The v1 restore builders (
load_session/resume_session) and the protocol v2 session builder already return setup errors to the caller and keep the connection running. Only the v1 new-session path did not.Change
start_sessionnow followsstart_restored_session. It sendssession/newwithsend_ordered_request_toand attaches the session insideblock_task_with_ordered_result.on_session_startalready guarantees this.SentRequestdrop-time cancellation plus handler cleanup. Before, a late response made the connection fail.Tests
session_ordering::start_session_returns_session_new_error_without_closing_connection: rejects onesession/new, then starts another session on the same connection. Before the fix, the connection ended with the agent's-32602.session_mcp_scope::start_session_failure_and_cancellation_keep_runner_until_cleanup: the v1 counterpart of the existing v2 setup-cleanup test, covering both rejection and cancellation with an attached MCP server. It fails before the fix.session_ordering::start_session_installs_routing_before_later_batch_entry: an update in the same transport batch as the response reaches the returned session.just test,cargo clippy --workspace --all-targets --all-features -- -D warnings,cargo fmt --check.