Repository navigation
fix(service): keep peer messaging active during response drain - #1524
Conversation
Signed-off-by: Perfloop Agent <agent@perfloop.ai>
Codex Review Summary: ✅ CompletedThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
|
@connor4312 is on triage rotation this week and is the reviewer for this one. Labels come from the PR labeler. Please review the change. Automated triage. Labels are a first pass and the assigned maintainer has the final say. |
jokemanfire
left a comment
There was a problem hiding this comment.
Verified at head 51ded29, base c78f2764.
Reproduced the claimed red/green with the PR's own test file, unmodified:
- base
c78f2764+test_peer_message_drain.rs->0 passed; 2 failed(peer message blocked the response drainat line 149,blocked send outlived the EOF drain deadlineat 213) - head
51ded29->2 passed - existing regression file
test_inflight_response_drain.rsat head ->2 passed(test_inflight_response_drain_on_eof,test_eof_cancels_pending_requests_after_drain) cargo fmt --all -- --checkclean (only the nightly-only rustfmt option warnings)
The new gate reads consistently: drain ends only when the sink channel is closed and empty and both JoinSets are empty, transport.receive() is disabled, PeerSinkMessage::Request is answered with TransportClosed before it can be inserted into local_responder_pool, and clearing the pool on entry drops the responders of requests already on the wire. The sink_proxy_tx.as_ref().expect("not draining") in the request branch is unreachable while draining, because Quit can only come from the select!, which is only reached with batch_messages empty.
Two small things, neither blocking:
blocked_sends_respect_drain_deadlinepins the 5 s EOF deadline only; the 2 s cancellation budget has no new test. Parametrising the helper overQuitReasonwould keep the two deadlines from drifting apart.- On timeout,
send_task_set.shutdown()/response_send_tasks.shutdown()abort atransport.sendfuture mid-write. With a buffered writer the last frame can be truncated on the wire (the peer sees a partial JSON line, then EOF). That is probably the right trade-off versus holding the writer lock through close, but the body only covers the backpressure case; one sentence would keep the next reader from treating it as accidental.
Public API unchanged, the shortened drain block reads correctly, and the EofReader in the test is a good touch for determinism.
|
I’m extending the blocked-send helper to exercise both |
Signed-off-by: Perfloop Agent <agent@perfloop.ai>
Signed-off-by: Perfloop Agent <agent@perfloop.ai>
|
The blocked-send helper now covers both EOF and cancellation, with response and notification sends checked against the five-second and two-second drain budgets. The focused Cargo tests pass 28 checks with no failures or skips; the production drain logic is unchanged. The description now explicitly notes that aborting an unfinished send at either deadline can leave a partial JSON line before EOF, rather than waiting indefinitely for a writable output. |
DaleSeo
left a comment
There was a problem hiding this comment.
Thanks for the fix, @perfloop-agent! Approved with a couple of minor suggestions.
Signed-off-by: Perfloop Agent <agent@perfloop.ai>
An in-flight handler that reports progress after input EOF can block the response drain and lose its reply. The drain added in #759 waits for handler responses but stops polling peer messages and notification-send completions. This change keeps those paths running while output is still writable, without changing the public API.
For an incoming ping with ID
1, a handler can now send progress token7and then return its empty result after EOF. Both messages reach the peer. Outbound peer requests instead receiveTransportClosedpromptly, since shutdown no longer reads their replies.serve_innerreuses its normal dispatch during the existing five-second EOF or two-second cancellation drain. At the deadline, it aborts and joins unfinished sends before closing the writer, so a backpressured send cannot hold the writer lock through close. Aborting a send at either deadline can leave a partial JSON line before EOF rather than waiting indefinitely for output to become writable.Notifications still require a writable output; this does not make peer replies available after input processing stops.
Fixes #1523
cc @DaleSeo
Validation and related work
Default-feature-only tests remain unvalidated because the stdio helper targets call feature-gated
transport::stdio. Validation uses default features plustransport-io.The new public-API regressions in
crates/rmcp/tests/test_peer_message_drain.rscover messages queued during drain, already-dispatched sends, and blocked writers under both the five-second EOF and two-second cancellation budgets. The peer-messaging and blocked-send tests fail on the unmodified base. A third test checks that both replies arrive when two handlers finish together after EOF.cargo testpassed 28 focused client/server shutdown, timeout, cancellation, response-concurrency and subscription checks, with no failures or skips.Related work: #1489 drops the outbound receiver before drain; it leaves pending peer responders and notification-send completions unserviced.
Case and evidence
Made by Perfloop. Human sponsor: Tomás Senart.