Repository navigation
fix(server): return the interrupted state from a blocking SendMessage - #1315
Merged
kabir merged 1 commit intoNov 18, 2026
Merged
Conversation
A blocking SendMessage reads the task back from the TaskStore once consumption completes, but completion only proves the consumer saw the events that had already been distributed to it. The last event of an agent turn can still be inside MainEventBusProcessor at that point, which persists it *after* the consumer is done, so the read returns the state from before that event: SUBMITTED or WORKING instead of INPUT_REQUIRED, with nothing logged and no error raised. Terminal states never hit this - the awaitingFinalEvent machinery keeps the consumer waiting for the final event. Interrupted states (INPUT_REQUIRED, AUTH_REQUIRED) are not final, and neither is an artifact-only tail. EventQueue#awaitDrained waits until no event accepted by the queue is left in flight, i.e. until every semaphore permit taken at enqueue time has been released by MainEventBusProcessor - which happens in its finally block, after the event has been persisted and distributed. ChildQueue delegates to its parent, since in-flight events are tracked there. The blocking path now waits there between waiting for consumption and reading the TaskStore. A timeout is logged and the previous behaviour is kept, so a stuck processor degrades to what callers had before instead of failing the request. Fixes a2aproject#1302
1 task done
Collaborator
|
Thank you @WMK666666 :-) |
3 of 4 tasks
VISHNU0906
added a commit
to VISHNU0906/a2a-java
that referenced
this pull request
Nov 22, 2026
Follow-up to a2aproject#1315 on top of current main. - EventQueue#awaitDrained is no longer abstract. The default returns true, so custom EventQueue subclasses written before a2aproject#1315 keep compiling and do not make the blocking path wait. - MainQueue wakes awaitDrained when a permit is released instead of polling every millisecond. The permit released on a failed enqueue goes through releaseSemaphore() too, so it also wakes waiters. - The blocking SendMessage path only waits for the drain when the agent finished within agentCompletionTimeoutSeconds. A still-running agent can keep enqueueing, and its later events are not part of the returned task anyway. Tests cover a trailing artifact whose persistence is slow, the skipped drain when the agent times out, and the default implementation. This fixes a2aproject#1302 Signed-off-by: KVR Vishnu <[email protected]>
kabir
pushed a commit
that referenced
this pull request
Nov 24, 2026
* fix(server): wait for in-flight events before reading the task in blocking sendMessage A blocking SendMessage reads the task from the TaskStore once the consumer stops, but only a final event keeps the consumer polling after the handler closes its queue. When persisting the agent's last event takes longer than the consumer's poll, an interrupted state (INPUT_REQUIRED, AUTH_REQUIRED) or a trailing artifact was still in flight and the call returned the previous state. After consumption completes and the agent has returned, wait (bounded by the consumption timeout) until the MainQueue has no events left in the event bus. MainQueue now wakes waiters when MainEventBusProcessor releases a permit. Fixes #1302 Signed-off-by: KVR Vishnu <[email protected]> * fix(server): skip the drain wait when the agent is still running Follow-up to #1315 on top of current main. - EventQueue#awaitDrained is no longer abstract. The default returns true, so custom EventQueue subclasses written before #1315 keep compiling and do not make the blocking path wait. - MainQueue wakes awaitDrained when a permit is released instead of polling every millisecond. The permit released on a failed enqueue goes through releaseSemaphore() too, so it also wakes waiters. - The blocking SendMessage path only waits for the drain when the agent finished within agentCompletionTimeoutSeconds. A still-running agent can keep enqueueing, and its later events are not part of the returned task anyway. Tests cover a trailing artifact whose persistence is slow, the skipped drain when the agent times out, and the default implementation. This fixes #1302 Signed-off-by: KVR Vishnu <[email protected]> --------- Signed-off-by: KVR Vishnu <[email protected]>
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.
Problem
Fixes #1302.
A blocking
SendMessagereads the task back from theTaskStoreonce consumption completes (DefaultRequestHandler.onMessageSend, Step 5). Completion of consumption only proves that the consumer saw the events that had already been distributed to it. The last event of an agent turn can still be insideMainEventBusProcessorat that point — it persists the event, then distributes it, and only then releases the queue permit — so Step 5 reads the state from before that event:Nothing is logged and nothing is thrown; the caller just gets a task that is one event behind, and the next
GetTaskshows the real state.Terminal states are not affected: the
awaitingFinalEventmachinery keeps the consumer waiting for a final event.TaskState.INPUT_REQUIRED.isFinal() == false(andisInterrupted() == true), so interrupted turns have no such protection. An artifact-only tail has the same problem.Change
EventQueue#awaitDrained(timeout, unit)— waits until no event accepted by the queue is still in flight.MainQueuederives that from the semaphore it already uses for backpressure (getQueueSize() - availablePermits());ChildQueuedelegates to its parent, which is where in-flight events are tracked. The permit is released inMainEventBusProcessor.processEvent'sfinallyblock, i.e. after persist and distribute, so a drained queue means persisted.DefaultRequestHandler#onMessageSend— new Step 4 between "wait for consumption" and "read the TaskStore". It reusesconsumptionCompletionTimeoutSeconds(default 5s) rather than adding another knob. On timeout it logs a warning and keeps the previous behaviour instead of failing the request, so a wedged processor degrades to what callers had before.MainQueuetakes the drain permit view rather than a callback on release, because a wake-up signalled from the release path would still race with the lastreleaseSemaphore(); polling the permit count cannot miss it. The interval is 1 ms, and the wait only happens on the blocking path, which is already blocking onagentFuture.get(...)andconsumptionFuture.get(...).Verification
server-common: 620 tests pass, 7 of them newEventQueueDrainTest(4): idle queue drains immediately; an accepted-but-unprocessed event is not drained;awaitDrainedactually blocks until the permit is released; a child queue reports its parent's in-flight events.BlockingSendMessageStaleStateTest(3): the task store is wrapped so that persisting a chosen state is delayed, making the ordering deterministic instead of timing-dependent.INPUT_REQUIRED→ blocking send returnsINPUT_REQUIREDAUTH_REQUIRED→ returnsAUTH_REQUIREDCOMPLETED→ returnsCOMPLETED(unchanged)which is exactly the symptom reported in #1302 (
returned=TASK_STATE_SUBMITTED eventual=TASK_STATE_INPUT_REQUIRED), and confirms the terminal path is untouched.