Repository navigation
Description
What happened?
Blocking SendMessage drops in-flight final events: InternalError: Timeout waiting for task <id> consumption
Version: org.a2aproject.sdk:*:1.4.0.Final
Environment: macOS 15 / OpenJDK 17.0.20.1, plain Java (no CDI), all in-memory implementations
(InMemoryTaskStore, InMemoryQueueManager, InMemoryPushNotificationConfigStore),
handler built via DefaultRequestHandler.builder()
Affects: non-streaming SendMessage with returnImmediately omitted or false
Summary
For a blocking SendMessage, DefaultRequestHandler closes the consumer's ChildQueue as soon as
the agent's execute() returns. If the agent's final event is still in flight inside
MainEventBusProcessor at that moment, MainQueue drops it (Skipping closed child queue), the
consumption future never completes, and the call fails with
InternalError: Timeout waiting for task <id> consumption.
The task itself is persisted correctly — MainEventBusProcessor persists before distributing — so
this is purely a lost response: GetTask afterwards returns a COMPLETED task with all artifacts.
Two separate problems combine here; the second is what turns the first from a latency spike into a
hard error, and is also why this is likely invisible under Quarkus/CDI. Happy to split this into
two issues if you prefer — they are independent fixes.
Problem 1: the blocking path closes the queue without honouring isAwaitingFinalEvent()
ResultAggregator (ResultAggregator.java:155-165) interrupts on the first event of any
blocking call, without looking at isFinalEvent:
else if (blocking) {
// For blocking calls: Interrupt to free Vert.x thread, but continue in background
// Python's async consumption doesn't block threads, but Java's does
// So we interrupt to return quickly, then rely on background consumption
shouldInterrupt = true;
LOGGER.debug("ResultAggregator: Setting shouldInterrupt=true (blocking, isFinal={})", isFinalEvent);So interruptedOrNonBlocking (DefaultRequestHandler.java:812) is always true for blocking
calls, and the branch at DefaultRequestHandler.java:845 is always taken — even though its body is
written for the fire-and-forget case, i.e. tasks that never emit a final event:
// Step 2: Close the queue to signal consumption can complete
// For fire-and-forget tasks, there's no final event, so we need to close the queue
// This allows EventConsumer.consumeAll() to exit
queue.close(false, false); // graceful close, don't notify parent yetclose(boolean, boolean) does not consult isAwaitingFinalEvent(). The guarded variant is
ChildQueue.closeIfNotAwaitingFinalEvent(), which refuses to close while
pendingFinalEvents > 0 || submittedFinalEvents > 0. EventConsumer uses that variant
(EventConsumer.java:182); the blocking path does not.
This breaks an invariant that EventQueue itself documents at the drop site
(EventQueue.java:771-780):
// Skip children that have already been closed. CopyOnWriteArrayList gives
// snapshot semantics, so a child removed by closeIfNotAwaitingFinalEvent()
// may still appear in this iteration. ...
// a narrow residual race remains for graceful close but is harmless for
// non-final events (they'd land in the draining queue) and impossible for
// final events (submittedFinalEvents prevents close while one is in flight).
if (child.isClosed()) {
LOGGER.debug("MainQueue[{}]: Skipping closed child queue for event {}", ...);
return;
}"impossible for final events" holds only while every closer goes through
closeIfNotAwaitingFinalEvent(). The direct close(false, false) in the blocking path makes it
possible.
After the final event is dropped, the consumer keeps polling because isAwaitingFinalEvent() is
still true (the counter was incremented when the final event was enqueued into MainQueue). It
recovers on its own after MAX_AWAITING_FINAL_TIMEOUT_MS = 3000
(EventConsumer.java:40) by calling clearAwaitingFinalEvent().
Problem 2: Builder.build() hardcodes the blocking timeouts and ignores the documented config
DefaultRequestHandler.Builder.build() (DefaultRequestHandler.java:491-493):
handler.agentCompletionTimeoutSeconds = 5;
handler.consumptionCompletionTimeoutSeconds = 2;
handler.reconciliationTimeoutSeconds = 1;The CDI path (initConfig(), DefaultRequestHandler.java:365-371) instead reads
a2a.blocking.agent.timeout.seconds / a2a.blocking.consumption.timeout.seconds /
a2a.blocking.reconciliation.timeout.seconds, whose values in META-INF/a2a-defaults.properties
are 30 / 5 / 1.
So a builder-wired handler silently gets a 2 s consumption timeout where a CDI-wired handler gets
5 s, and the a2a.blocking.* properties documented in the class javadoc have no effect at all.
This interacts badly with Problem 1:
| wiring | consumption timeout | vs consumer's 3 s self-recovery | expected behaviour |
|---|---|---|---|
| CDI / Quarkus | 5 s (from config) | 5 s > 3 s | recovers: correct task returned, but the call takes ~3 s |
Builder |
2 s (hardcoded) | 2 s < 3 s | hard failure: InternalError |
The Builder row is what we observe directly. The CDI row is inferred — we have not run this
on Quarkus. What we did verify is the timeout's effect in isolation: reflectively raising
consumptionCompletionTimeoutSeconds from 2 to 5 on a builder-wired handler
(Repro.java -DconsumptionTimeout=5) turns 4–9/20 into 20/20 across three runs, with the
affected calls taking ~3030 ms instead of ~150 ms — i.e. the consumer's 3 s self-recovery then fits
inside the budget.
If that inference is right, it would explain why this has gone unnoticed: under Quarkus the bug
manifests as an occasional 3-second latency spike on blocking calls rather than an error. Someone
with a Quarkus setup could confirm this quickly.
Reproduction
Single self-contained file, attached as A2aBlockingRepro.java — no Spring, no HTTP, no CDI,
and no reflection on the default path. Only a2a-java-sdk-spec + a2a-java-sdk-server-common
are required.
# 1. resolve a classpath (throwaway pom, contents below)
mvn -q dependency:build-classpath -Dmdep.outputFile=cp.txt
# 2. run — Java 11+ single-file source launcher, no javac step
java -cp "$(cat cp.txt)" A2aBlockingRepro.java # all three sections
java -cp "$(cat cp.txt)" A2aBlockingRepro.java repro # just the failing blocking path
java -cp "$(cat cp.txt)" A2aBlockingRepro.java matrix # exposure vs event count
java -cp "$(cat cp.txt)" A2aBlockingRepro.java workaround # async + poll, for comparison
# sensitivity switches (apply to the "repro" section)
java -Dlinger=1 -cp "$(cat cp.txt)" A2aBlockingRepro.java repro # 1ms after complete() -> 20/20
java -Dwork=300 -cp "$(cat cp.txt)" A2aBlockingRepro.java repro # slow agent -> no effect
java -Dgap=1000 -cp "$(cat cp.txt)" A2aBlockingRepro.java repro # spacing calls -> no effect
java -DconsumptionTimeout=5 -cp "$(cat cp.txt)" A2aBlockingRepro.java repro # CDI's valuepom.xml used for step 1:
<project><modelVersion>4.0.0</modelVersion>
<groupId>x</groupId><artifactId>x</artifactId><version>1</version>
<dependencies>
<dependency><groupId>org.a2aproject.sdk</groupId>
<artifactId>a2a-java-sdk-server-common</artifactId><version>1.4.0.Final</version></dependency>
<dependency><groupId>org.a2aproject.sdk</groupId>
<artifactId>a2a-java-sdk-spec</artifactId><version>1.4.0.Final</version></dependency>
</dependencies>
</project>The executor and the handler wiring, abridged:
AgentExecutor echo = new AgentExecutor() {
public void execute(RequestContext c, AgentEmitter e) {
if (c.getTask() == null) e.submit();
e.startWork();
e.addArtifact(List.of(new TextPart("hi")), "a1", "answer", null);
e.complete();
}
public void cancel(RequestContext c, AgentEmitter e) { e.cancel(); }
};
DefaultRequestHandler h = DefaultRequestHandler.builder()
.agentExecutor(echo).taskStore(taskStore).queueManager(queueManager)
.mainEventBusProcessor(processor)
.executor(agentPool).eventConsumerExecutor(consumerPool)
.authorizationRequired(false).build();
// configuration omitted => returnImmediately == false => blocking
for (int i = 0; i < 20; i++) {
h.onMessageSend(MessageSendParams.builder().message(msg("m" + i)).build(), ctx());
}Result across runs: 4/20 to 9/20 succeed; the rest throw
InternalError: Timeout waiting for task <id> consumption, each after ~2000 ms.
Observed log interleaving
[MainEventBusProcessor] Distributing TaskStatusUpdateEvent to 1 children for task 4e12f445
[main] DefaultRequestHandler: Step 1 - Agent completed for task 4e12f445
[main] DefaultRequestHandler: Step 2 - Closed queue for task 4e12f445 to allow consumption completion
[MainEventBusProcessor] MainQueue[4e12f445]: Skipping closed child queue for event TaskStatusUpdateEvent
[MainEventBusProcessor] MainQueue[4e12f445]: Skipping closed child queue for event TaskArtifactUpdateEvent
[MainEventBusProcessor] MainQueue[4e12f445]: Skipping closed child queue for event TaskStatusUpdateEvent
[main] WARN Timeout waiting for task 4e12f445 consumption
Sensitivity (3 runs × 20 calls each)
The race window is sub-millisecond, and it is bounded by "final event enqueued → execute()
returns", not by how long the agent works:
| variation | result |
|---|---|
baseline (complete() then immediate return) |
7/20, 9/20, 4/20 |
sleep 1 ms after complete() |
20/20, 20/20, 20/20 |
sleep 300 ms before complete() |
2/20, 1/20, 1/20 — no effect (slightly worse) |
| 1 s gap between calls | 3/20, 8/20, 4/20 — no effect |
Event count is what decides exposure
Same blocking path, different executor bodies, 20 calls each:
| executor body | events | passed (across runs) |
|---|---|---|
sendMessage("Hello World") — the examples-server hello-world executor |
1 | 20/20 |
complete() |
1 | 20/20 |
submit() + complete() |
2 | 19–20/20 |
submit() + startWork() + complete() |
3 | 14–18/20 |
submit() + addArtifact() + complete() |
3 | 5–9/20 |
submit() + startWork() + addArtifact() + complete() |
4 | 4/20 |
as above with lastChunk = true |
4 | 3–5/20 |
Numbers vary run to run (it is a timing race); the ordering by event count is stable.
The shipped hello-world example emits a single Message and never creates a task, so it is not
affected. Any executor that returns a task with artifacts emits 3–4 events and is.
SendStreamingMessage with the same 4-event executor is stable
(SUBMITTED → WORKING → artifactUpdate → COMPLETED), since it does not close the queue early.
Suggested fixes
For Problem 1 — smallest change: make Step 2 respect the existing guard, e.g.
if (!queue.closeIfNotAwaitingFinalEvent()) {
// a final event is in flight; leave the queue open and let Step 3's
// consumptionFuture complete when the consumer sees it
}Both the counters (expectFinalEvent(), incremented by MainQueue when a final event is enqueued,
EventQueue.java:617/640) and the atomic check-and-close already exist.
Alternative, addressing the root condition: have ResultAggregator expose whether a final event
was already observed (e.g. an extra component on EventTypeAndInterrupt) and skip the
fire-and-forget close entirely when it was. That keeps the Vert.x-thread-freeing interrupt while
restoring the branch's stated precondition.
For Problem 2: have Builder.build() read the same a2a.blocking.* properties as
initConfig() (or at least use the same defaults, 30/5/1), and/or expose them as builder methods.
Right now a non-CDI deployment cannot configure these timeouts at all.
Workaround we are using
Avoid the blocking path: call SendMessage with returnImmediately=true and poll GetTask until
the task reaches a terminal (or INPUT_REQUIRED) state. 20/20 with both a 0 ms and a 300 ms agent.
A2aBlockingRepro.java
ISSUE.md
Relevant log output
Code of Conduct
- I agree to follow this project's Code of Conduct
Activity
fix(server): align builder blocking timeouts with documented defaults (…
ordercard commentedon Oct 30, 2026
Why not just change it the way I did? Is the root cause that the default time hasn't been kept consistent?
kabir commentedon Oct 30, 2026
It looks like it was already fixed in #1227, so this was just some additional adjustments.
If this is all wrong, please let me know!