fix(a2a): drain output_rx until Flush to prevent response shift (#2326, #2313)#2328
Merged
fix(a2a): drain output_rx until Flush to prevent response shift (#2326, #2313)#2328
Conversation
Replace the non-blocking try_recv drain with a blocking recv-until-Flush loop after process() exits on FullMessage. The previous try_recv was a TOCTOU race: the agent loop continued emitting Usage/Flush tail events after the drain completed, leaving them buffered for the next request and causing each message/send to return the previous request's response. Flush is the universal end-of-turn sentinel across all agent paths. The drain loop handles channel close (None) as a fallback exit. Also fix a silent tx.send() error discard in EmbeddingAnomalyGuard check_async(): log a tracing::warn when the result channel is closed instead of silently swallowing the error (#2313). Fixes #2326, #2313
This was
linked to
issues
Mar 28, 2026
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
try_recvdrain inAgentTaskProcessor::process()with a blockingrecv().await-until-Flushloop. The previous drain was a TOCTOU race: the agent loop continued emittingUsage/Flushtail events aftertry_recvhad already returned empty, leaving them buffered inoutput_rxfor the nextmessage/sendcall. Each subsequent request then consumed the previous response, producing the observed one-position shift.Flushis the universal end-of-turn sentinel across all agent code paths.let _ = tx.send(result)with anis_err()check andtracing::warn!()inEmbeddingAnomalyGuard::check_async()— both the cold-start and warm async paths.Test plan
cargo +nightly fmt --checkpassescargo clippy --features full --workspace -- -D warningspasses (0 warnings)cargo nextest run --workspace --features full --lib --bins— 6927 passed (+1 new test)a2a_response_shift_drain_until_flush_prevents_leakverifies the drain loop consumesFullMessage+ delayedUsage + Flushand leaves the channel empty before the next requestrecv().awaitfalls back toNoneon channel close)