What happened?
AgentEmitter.updateStatus() and AgentEmitter.fail(A2AError) mark the emitter terminal before calling EventQueue.enqueueEvent().
If enqueueing throws, no terminal event is delivered, but the emitter remains marked terminal. DefaultRequestHandler catches the exception and attempts to report an InternalError through emitter.fail(A2AError). That fallback call then throws: IllegalStateException: Cannot update task status - terminal state already reached
The original enqueue failure is logged, but the secondary terminal state exception escapes the error handling path and prevents the fallback error event from being emitted.
Reproduction steps
This behavior is reproducible using the SDK’s built-in EventQueue, including when a terminal enqueue is interrupted while waiting for queue capacity.
- Create an
AgentEmitter backed by an EventQueue that throws from enqueueEvent().
- Call a terminal operation such as
emitter.complete().
- Catch the resulting exception, as
DefaultRequestHandler does.
- Call
emitter.fail(new InternalError()).
The fallback operation throws because the first attempt left terminalStateReached set.
Both final status updates through updateStatus() and protocol errors through fail(A2AError) set the terminal flag before enqueueing and are affected.
Reproduced with the SDK’s built-in EventQueue using a size-one queue at capacity and interrupting the terminal enqueue. This was a focused reproduction, not production log output.
Expected behavior
The SDK should handle a failed terminal enqueue without replacing the original failure with a secondary “terminal state already reached” exception. Its terminal state should remain consistent with whether a terminal event was successfully accepted for processing.
Relevant log output
Initial terminal enqueue failure:
java.lang.RuntimeException: Unable to acquire the semaphore to enqueue the event
Fallback failure:
java.lang.IllegalStateException:
Cannot update task status - terminal state already reached
Code of Conduct
What happened?
AgentEmitter.updateStatus()andAgentEmitter.fail(A2AError)mark the emitter terminal before callingEventQueue.enqueueEvent().If enqueueing throws, no terminal event is delivered, but the emitter remains marked terminal.
DefaultRequestHandlercatches the exception and attempts to report an InternalError throughemitter.fail(A2AError). That fallback call then throws:IllegalStateException: Cannot update task status - terminal state already reachedThe original enqueue failure is logged, but the secondary terminal state exception escapes the error handling path and prevents the fallback error event from being emitted.
Reproduction steps
This behavior is reproducible using the SDK’s built-in
EventQueue, including when a terminal enqueue is interrupted while waiting for queue capacity.AgentEmitterbacked by anEventQueuethat throws fromenqueueEvent().emitter.complete().DefaultRequestHandlerdoes.emitter.fail(new InternalError()).The fallback operation throws because the first attempt left
terminalStateReachedset.Both final status updates through
updateStatus()and protocol errors throughfail(A2AError)set the terminal flag before enqueueing and are affected.Reproduced with the SDK’s built-in
EventQueueusing a size-one queue at capacity and interrupting the terminal enqueue. This was a focused reproduction, not production log output.Expected behavior
The SDK should handle a failed terminal enqueue without replacing the original failure with a secondary “terminal state already reached” exception. Its terminal state should remain consistent with whether a terminal event was successfully accepted for processing.
Relevant log output
Code of Conduct