Skip to content

fix(server): skip the drain wait when the agent is still running - #1314

Merged
kabir merged 3 commits into
a2aproject:mainfrom
VISHNU0906:issue-1302
Nov 24, 2026
Merged

kabir merged 3 commits into
a2aproject:mainfrom
VISHNU0906:issue-1302

Conversation

@VISHNU0906

@VISHNU0906 VISHNU0906 commented Nov 9, 2026 •

Copy link
Copy Markdown
Contributor

Description

Follow-up to #1315 for #1302, reworked on current main as @kabir suggested.

  • EventQueue.awaitDrained now has a concrete default that returns true, so custom EventQueue subclasses keep compiling and count as drained.
  • MainQueue.awaitDrained no longer polls. It waits on a lock that releaseSemaphore() notifies after MainEventBusProcessor has persisted and distributed an event. The failed-enqueue path also goes through releaseSemaphore() so a waiter is woken there too.
  • In onMessageSend, Step 4 (the drain wait) is skipped when the agent did not finish within agentCompletionTimeoutSeconds. The response is a snapshot in that case anyway, so the caller doesn't wait another consumptionCompletionTimeoutSeconds on top.

Tests:

  • BlockingSendMessageStaleStateTest.blockingSendReturnsATrailingArtifactEvenWhenItIsStillBeingPersisted: the agent's last event is an artifact that takes 1.5 s to persist. The artifact is in the returned task.
  • BlockingSendMessageStaleStateTest.blockingSendDoesNotWaitForTheQueueToDrainWhenTheAgentIsStillRunning: the agent times out after 1 s while an artifact takes 4 s to persist, and the call returns in under 3 s. Without the guard it takes about 4 s and fails.
  • EventQueueDrainTest.aQueueThatDoesNotTrackInFlightEventsCountsAsDrained covers the default.

I didn't copy the input-required and auth-required cases from my first version, since #1315 already covers them.

server-common passes (655 tests), and mvn -B package -fae -DskipDockerTests=true passes locally on JDK 25 (83 modules, about 4,000 tests, 0 failures). I couldn't run the Docker-based tests here.

…cking 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 a2aproject#1302

Signed-off-by: KVR Vishnu <[email protected]>
@kabir

kabir commented Nov 18, 2026

Copy link
Copy Markdown
Collaborator

Hi @VISHNU0906, I just merged #1315, which fixes #1302. I didn’t realise the two PRs overlapped when I merged it.

I’ve since read @Shay-Deng’s comparison. Your PR preserves compatibility for custom EventQueue subclasses and skips the extra drain wait when the agent is still running after the timeout. The trailing-artifact test also covers a case worth keeping. Review on #1302

Would you be up for reworking this PR as a follow-up against current main? I’d keep the awaitDrained name from #1315, give it a concrete default, and bring over your release notification and agent-timeout guard. Please bring over the trailing-artifact test too. A regression test that verifies the drain is skipped when the agent times out would round it out.

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]>
@VISHNU0906 VISHNU0906 changed the title fix(server): wait for in-flight events before reading the task in blocking sendMessage fix(server): skip the drain wait when the agent is still running Nov 22, 2026
@VISHNU0906

Copy link
Copy Markdown
Contributor Author

Thanks @kabir, happy to. I've reworked this on current main: awaitDrained keeps its name and has a concrete default, MainQueue now wakes waiters on permit release instead of polling, and the drain is skipped when the agent times out. I added the trailing-artifact test and a regression test for the timeout case, and updated the description.

@kabir
kabir merged commit e55888e into a2aproject:main Nov 24, 2026
15 checks passed
@kabir

kabir commented Nov 24, 2026

Copy link
Copy Markdown
Collaborator

Thanks @VISHNU0906 :-)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants