[Bug]:Blocking SendMessage returns stale task state when the agent ends in an interrupted state (INPUT_REQUIRED / AUTH_REQUIRED)
Maintainer antworten meist innerhalb von 1 Tag
@VISHNU0906 arbeitet bereits daran.
Seit 09.11.2026.
Bewertung
- Schwierigkeit
- 4/5
- Geschätzter Aufwand
- 3-5 Tage
- Anfängerfreundlichkeit
- 45/100
- Issue-Typ
- Bug
- Klarheit
- Klar beschrieben
- Aktivitätsstatus
- Aktiv
- Tech-Stack
- java
- Bereich
- backend-api-design
Rechercherichtung
Start with DefaultRequestHandler.onMessageSend, EventQueue.MainQueue.enqueueItemInternal, and MainEventBusProcessor; the report also gives a self-contained reproducer, InputRequiredStaleRepro.java. Trace when queued events are persisted and when the blocking response reads TaskStore, then reproduce with a delayed save and an INPUT_REQUIRED final event. Done means the blocking response returns the persisted interrupted state even when persistence lags.
Vom Indexierungsmodell aus dem Issue-Text verfasst.
Beschreibung
What happened?
[Bug]: Blocking SendMessage returns stale task state when the agent ends in an interrupted state (INPUT_REQUIRED / AUTH_REQUIRED)
Version: org.a2aproject.sdk:*:1.5.0.Final (also present in main as of 2026-11-09)
Environment: macOS / OpenJDK 17.0.20.1, plain Java (no CDI), InMemoryTaskStore wrapped with a
fixed per-save delay, InMemoryQueueManager, MainEventBusProcessor, handler built via
DefaultRequestHandler.builder()
Affects: non-streaming SendMessage with returnImmediately omitted or false, when the last
event is INPUT_REQUIRED or AUTH_REQUIRED
Summary
For a blocking SendMessage, the returned Task is read from TaskStore
(DefaultRequestHandler.onMessageSend, Step 5, taskStore.get(taskId)), but the blocking path only
waits for the consumer future. If the agent's last event has not been persisted by
MainEventBusProcessor when Step 5 runs, the caller receives a stale state (SUBMITTED / WORKING)
even though the task is already INPUT_REQUIRED in the store a moment later.
Terminal states are protected by the awaitingFinalEvent machinery; interrupted states are not,
because TaskState.INPUT_REQUIRED.isFinal() == false and isInterrupted() == true.
This is the interrupted-state analogue of #1247 (fixed for terminal events by #1227).
Why it happens
EventQueue.MainQueue.enqueueItemInternalonly callsChildQueue.expectFinalEvent()when
isFinalEvent(event)is true.isFinalEventacceptsTaskState.isFinal()andA2AError—
INPUT_REQUIRED/AUTH_REQUIREDare excluded.- The blocking path (
DefaultRequestHandler.onMessageSend) closes the caller'sChildQueue
(Step 2) and waits for consumption (Step 3). WithisAwaitingFinalEvent() == false, the
consumer exits as soon as the queue is closed and empty
(ChildQueue.dequeueEventItem). - Step 5 then reads
TaskStore. Events still inMainQueue— acquired on the semaphore in
enqueueItemInternal, released only after persist + distribute — are invisible at this point. MainEventBusProcessoris asynchronous and persists before distributing, so the event is
durable shortly afterwards; the caller already returned.
The consumer's dequeueEventItem(QUEUE_WAIT_MILLISECONDS = 500) gives an accidental grace window:
with a fast store the event lands before the poll times out, which is why this is invisible in
simple examples and only shows up when persistence lags (slow DB, many events, write backlog)
beyond ~500 ms after the agent returns.
Reproduction
Self-contained single file, attached as InputRequiredStaleRepro.java. Only
a2a-java-sdk-server-common + a2a-java-sdk-spec 1.5.0.Final are required.
# pom: the two artifacts above at 1.5.0.Final
mvn -q dependency:build-classpath -Dmdep.outputFile=cp.txt
# interrupted last event, 600ms per persist -> stale
java -DsaveDelay=600 -Dcalls=3 -cp "$(cat cp.txt)" InputRequiredStaleRepro.java blocking
# same store, terminal last event -> correct
java -DsaveDelay=600 -Dcalls=3 -cp "$(cat cp.txt)" InputRequiredStaleRepro.java terminal
Observed:
mode=blocking expected=TASK_STATE_INPUT_REQUIRED saveDelay=600ms artifacts=0 calls=3
call#1 returned=TASK_STATE_SUBMITTED eventual=TASK_STATE_INPUT_REQUIRED STALE
call#2 returned=TASK_STATE_SUBMITTED eventual=TASK_STATE_INPUT_REQUIRED STALE
call#3 returned=TASK_STATE_SUBMITTED eventual=TASK_STATE_INPUT_REQUIRED STALE
=> 0/3 returned the expected state
mode=terminal expected=TASK_STATE_COMPLETED saveDelay=600ms artifacts=0 calls=3
call#1 returned=TASK_STATE_COMPLETED eventual=TASK_STATE_COMPLETED OK
call#2 returned=TASK_STATE_COMPLETED eventual=TASK_STATE_COMPLETED OK
call#3 returned=TASK_STATE_COMPLETED eventual=TASK_STATE_COMPLETED OK
=> 3/3 returned the expected state
A less artificial shape reproduces too — 50 ms per save with 12 artifact events before
requiresInput() (≈650 ms of persistence lag for the tail):
java -DsaveDelay=50 -Dartifacts=12 -Dcalls=3 -cp "$(cat cp.txt)" InputRequiredStaleRepro.java blocking
# => 0/3, e.g. returned=TASK_STATE_WORKING / SUBMITTED, eventual=INPUT_REQUIRED
GetTask immediately afterwards returns INPUT_REQUIRED — the state is not lost, only the blocking
response is wrong.
Suggested fix
The blocking path should guarantee the same invariant the terminal path gets from
awaitingFinalEvent: no event enqueued by the agent may still be in flight in MainQueue when
Step 5 reads TaskStore.
Option A (general): expose the existing in-flight count and wait for it to reach zero before Step 2,
e.g. QueueManager.awaitDrained(taskId, timeout) implemented on MainQueue
(size() == getQueueSize() - semaphore.availablePermits()), signalled from
releaseSemaphore() — which runs in MainEventBusProcessor's finally block, after persist and
distribute. A callback-based wake-up would miss the last event, so the signal has to be on the
release path.
Option B (narrower): extend the awaitingFinalEvent accounting to
state.isFinal() || state.isInterrupted(). This fixes the status-event case, but an artifact tail
(the last event being an artifact) would still race, so Option A is preferable.
Workaround for applications
Wrap the AgentExecutor so that execute() does not return until the task's queue is drained
(poll QueueManager.get(taskId).size() with a bounded timeout), or use
returnImmediately=true plus client-side GetTask polling.
Related
- #1247 — blocking
SendMessagedrops in-flight final events (fixed in 1.5.0 by #1227) - #1249 — builder blocking timeouts aligned with documented defaults
- #990 — API/hook to close streams after INPUT_REQUIRED / AUTH_REQUIRED
Relevant log output
Code of Conduct
- I agree to follow this project's Code of Conduct
- Vorherrschende Sprache
- Java
- Sterne
- 514
- Forks
- 200
- Ø Merge
- 1 T. 2 Std.
- Gemergte PRs (30 T.)
- 53
Entwicklungsumgebung
- Kein Dockerfile und keine Docker-Compose-Datei
- Hat eine Pull-Request-Vorlage
- Beitragsleitfaden lesen
Erste Schritte
- Lesen Sie das ganze Issue und danach den Beitragsleitfaden des Projekts.
- Schreiben Sie ins Issue, dass Sie es übernehmen — das erspart doppelte Arbeit.
- Forken Sie das Repository und arbeiten Sie in einem Branch.
- Öffnen Sie einen Pull Request, der die Issue-Nummer nennt.
Mehr aus a2aproject/a2a-java
-
Document 1.x is the actively supported stream, and not 0.3.xEvtl. vergeben @Linux2010 hat das vor 2 Tagen übernommen. Offen
Schwierigkeit 1/5 1-3 Stunden Anfängerfreundlichkeit 62/100
a2aproject/a2a-java#1321 ·
Maintainer antworten meist innerhalb von 1 Tag
-
HTTP+JSON CancelTask returns 409 Conflict instead of 400 Bad Request for TaskNotCancelableErrorEvtl. wieder frei @ravismash hat das vor 9 Tagen übernommen, und es ist kein Pull Request offen. Offen
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 76/100
a2aproject/a2a-java#1298 · 5 Kommentare ·
Maintainer antworten meist innerhalb von 1 Tag
-
fix: handle blank push notification config id consistently across transportsEvtl. vergeben @prachisinghal-1 hat das vor 24 Tagen übernommen. Offen
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 75/100
a2aproject/a2a-java#1012 · 2 Kommentare · 1 zugewiesene Person ·
Maintainer antworten meist innerhalb von 1 Tag
-
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 65/100
a2aproject/a2a-java#464 · 1 Kommentar ·
Maintainer antworten meist innerhalb von 1 Tag
-
Create a sample that demonstrates how to use a shared contextId across multiple tasksEvtl. wieder frei @tanish111 hat das vor 390 Tagen übernommen, und es ist kein Pull Request offen. Offensample
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 70/100
a2aproject/a2a-java#375 · 5 Kommentare · 1 zugewiesene Person ·
Maintainer antworten meist innerhalb von 1 Tag
Alle Issues in a2aproject/a2a-java
Ähnliche Issues
-
bug
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 78/100
apache/skywalking#14239 ·
Maintainer antworten meist innerhalb von 1 Tag
-
account bug exercise lecture modeling programming
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 64/100
Maintainer antworten meist innerhalb von 1 Tag
-
Re-executed query with IN condition on an index column returns deleted rows (stale IndexCursor)Evtl. vergeben @dbusche hat das heute übernommen. Offen
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 82/100
h2database/h2database#4580 ·
Maintainer antworten meist innerhalb von 1 Tag
-
vips-drift
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 74/100
Stirling-Tools/JPDFium#300 ·
Maintainer antworten meist innerhalb von 1 Tag
-
hermes-queue
Schwierigkeit 1/5 1-3 Stunden Anfängerfreundlichkeit 85/100
chrisalunlloyd2-sudo/mindpalace#403 ·
Maintainer antworten meist innerhalb von 1 Tag