fix(a2a): demand-driven backpressure and explicit stall failure for streaming (issue #212) #389
All Vouch review confidence checks passed
Residual risk 0.25 = Change Risk (0.49) × (1 − Review Confidence (0.48)).
Review depth and reviewer attention state are adequate.
Model 1 · Change Risk (XGBoost)
Score: 0.49 · 1075 lines diff across 5 files
Model 2 · Review Depth (DistilBERT)
Depth Score: 0.00 · 1 substantive comment(s)
Model 3 · Review Timing & Attention
Session adequacy: 100% · Reviewer familiarity: 35%
Bedrock Claude 3 · Risk Narration
(disconnected)
Groq Risk Narration
AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
Model 1 · Change Risk Attribution
SHAP Weights
Diff Size
diff_size
0.400
Shallow Review Depth
shallow_review_depth
0.350
Real PR Conversation Timeline
2 items
Approved
LGTM
yuluo-yx
konlue
Contributing to ARGI: make the A2A streaming producer demand-driven and fail an indefinitely stalled consumer explicitly (issue #212).
Describe what this PR does / why we need it
Issue #212 asks for explicit backpressure and a reliable terminal state when the A2A streaming queue is full. The 1000-slot
LinkedBlockingQueuethe issue quotes was already removed by #277 (cancel aborts the blocking read) and #213/#371 (structured terminal errors), but the replacement has the same unbounded-memory failure mode in a different shape:Flux.createuses the defaultBUFFERstrategy, so a subscriber that stops requesting without cancelling makes the producer keep reading the socket and buffer without bound — the stream neither completes nor fails, and there is no capacity/wait configuration. This PR makes downstream demand the only buffer and turns an indefinitely stalled consumer into an explicitA2aBackpressureException, with a configurable wait.Does this pull request fix one issue?
Fixes #212
Describe how you did it
The producer now emits through
StreamEmission, a per-subscription demand gate. Permits are counted exactly fromFluxSink.onRequestand one permit is consumed per emitted event;requestedFromDownstream()is deliberately not used as the permit source because it races with the sink's own decrement — the race let one extra event sit in the sink queue, which then held the terminal signal behind undeliverable data. The wait re-checks every 50 ms and is woken by requests, cancellation and disposal. While waiting, the producer is not reading the socket, so TCP backpressure reaches the remote peer.The blocking exchange runs on its own bounded-elastic task instead of inside the
Flux.createemitter. Running it in the emitter tied the blocking work to thesubscribeOnworker, which also has to forward downstream requests; the producer then waited for demand that its own worker could never deliver (reproduced with probes before and after this change).When the consumer stays at zero demand for
streamDemandTimeout, the gate first callspost.cancel(), then deliverssink.error(A2aBackpressureException)directly and lets the producer unwind normally. Delivering the terminal before unwinding is essential: letting the exception escape the HTTP client's response handler delayed the error by roughly five seconds of connection teardown in the reproduction. Because no event is ever emitted without a permit, the sink queue is empty when the terminal is sent, andcomplete/errorare delivered even at zero demand. The done response stays an ordinary event and therefore needs one permit — a consumer that stops requesting before it gets the explicit failure instead of an accumulated result stranded in a buffer — and a cancelled subscription still receives neither an error nor a done response, preserving the #213/#277 contracts.There is no intermediate queue, so the effective capacity is the subscriber's outstanding demand.
A2aNodeActionWithConfig.streamDemandTimeout(Duration)configures the bound (default 60 s,Duration.ZEROwaits indefinitely to restore the legacy behaviour, negative values rejected) andA2aRemoteAgent.Builder.streamDemandTimeoutpasses it through both node construction sites, which now share onenewNodeActionfactory so the agent-level userId and timeout options cannot drift apart. Of the options the issue asks to compare, an unbounded queue is rejected by the acceptance criteria, and a boundedSinks.many().unicast().onBackpressureBuffer(ArrayBlockingQueue)variant is rejected because its terminal can queue behind data that no demand can drain and its overflow wait would need polling; cancellable blocking backpressure plus an explicit error plus a terminal channel independent of demand is the chosen shape.Describe how to verify it
Red on
origin/main:A2aStreamBackpressureTest#stalledConsumerFailsWithExplicitBackpressureErrorsubscribes with an initial request of one, stops requesting, and only times out — the old producer buffers the rest of the stream forever. The new code fails that test green withA2aBackpressureExceptionafter the configured 250 ms, having delivered exactly one chunk and released the worker.New coverage in
A2aStreamBackpressureTest(7 tests): a stalled consumer gets the explicit error in bounded time with the worker released; a slow consumer requesting one event at a time receives every chunk plus the done response in order; disposing while the producer waits for demand emits no terminal signal and releases the worker; a consumer that pauses for 500 ms and resumes within the timeout receives every chunk; a consumer that stops requesting right before the done response fails explicitly instead of hanging;Duration.ZEROkeeps waiting instead of failing; and the timeout configuration rejects null/negative values while acceptingDuration.ZERO.Two further tests in
A2aRemoteAgentTestscover the builder wiring: a configured timeout reaches the node action produced by the shared factory, and null/negative values are rejected whileDuration.ZEROis accepted.Existing coverage is unchanged: the A2A suite is 82 tests green, including
A2aStreamCancellationTest(transport abort on cancel, #277) andA2aStructuredFailurePropagationTest(structured terminal errors, #213). The fullargi-agent-frameworkmodule shows the same 2 failures and 10 errors as the known Windows baseline (filesystem symlink permissions, ripgrep executable permissions and aCreateProcesscommand-line limit — none A2A related), and checkstyle plus spotless are clean for the module.Special notes for reviews
The only new failure mode is a consumer that stays at zero demand for the whole timeout;
Duration.ZEROdisables the timeout entirely (it does not mean "fail immediately"), restoring the previous wait-forever behaviour, and the done response follows the same demand rule as any other event. The exchange now runs on its own bounded-elastic task while thesubscribeOnworker returns to the pool right after subscription, so the per-stream thread footprint is unchanged. Change size: 5 files, +961/−114 (including 9 new tests: 7 inA2aStreamBackpressureTestand 2 inA2aRemoteAgentTests). Boundary: this does not revisit the terminal classification from #213, does not touch Extensions #25 or the persistence cancellation work in #14, and does not change the graph engine.Fixes #212