fix(rmcp): route peer cancellation by lifecycle - #1262
Open
aurokin wants to merge 4 commits into
Open
Conversation
Cancel inbound legacy requests by their exact request ID. Preserve modern subscription waiter cleanup using the peer lifecycle and outbound request kind. Suppress cancelled handler results and errors during EOF draining without dropping uncancelled responses during graceful shutdown. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
DaleSeo
reviewed
Sep 12, 2026
Use rstest to report each startup and request ID combination independently. Keep the existing per-case timeout and cancellation assertions. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Merge upstream main fbfc5cc without rewriting history. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Replace the stale ServerInfo reference after merging the upstream alias migration. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
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.
Fixes #1251.
Implements the approach agreed to in #1251 (comment).
Problem
In legacy sessions, incoming server
notifications/cancelledmessages remove an outbound client waiter instead of cancelling the server-originated request'sRequestContext.ct. This leaves the handler running and can affect an unrelated request with the same ID.Removing outbound cleanup entirely would break modern subscription termination.
Fix
Route cancellation by the established lifecycle:
subscriptions/listenwaiter for modern server cancellation, independently of notification-channel registration.No dependency, wire-schema, or macro changes. Outgoing server teardown and same-direction ID reuse are outside this fix.
Regression coverage
The tests cover string-ID reverse cancellation on a live connection, handler-token observation, response suppression, subsequent traffic, legacy initialization, direct peers, unknown IDs, and equal IDs in opposite directions.
The subscription regression inspects the actual waiter after an ordered ping. It covers modern discovery selecting either application version, ordinary outbound request immunity, and listen requests without a registered notification channel.
Drain regressions cover successful and failed cancelled handlers and graceful completion of uncancelled handlers. Existing RoleServer stdio coverage remains in place.
Validation
The clean candidate passed:
Full all-feature and non-local suites passed on the same production source before the final test-only error-response variant. That variant passed targeted validation, including against the published release with its original lockfile.
The same cancellation files also passed targeted validation after merging upstream
3023198in a separate development branch. That merge is not included in this single-commit PR head. The regressions fail against unpatched upstream; an independent reproduction on46db531is recorded in #1251.Full Clippy previously failed at an unchanged
clippy::question_markwarning inauth.rs. The unchanged base reproduced the same warning with the same compiler and lockfile. No unrelated lint fix or suppression is included.