fix(server): support asynchronous agent execution via keepAlive - #1027
fix(server): support asynchronous agent execution via keepAlive#1027malladinagarjuna2 wants to merge 2 commits into
Conversation
|
@kabir could you please verify |
|
Hi thanks for the PR :-) There are quite many in the queue right now, so I'm getting some help from Claude in reviewing them in bulk. Apologies if something isn't clear, and feel free to discuss further.
|
Overview
This PR introduces native support for completely asynchronous agent execution pipelines (e.g., RxJava
Single, Kotlin Coroutines, or generic background thread-hopping) to solve premature event queue closures.Fixes #872
The Problem
Previously, the
DefaultRequestHandlerassumed an agent was completely finished as soon as theAgentExecutor.execute()method returned. If the agent didn't emit a terminal event, the server enforced a strict 1.5-second timeout and forcefully closed the event queue to prevent leaks.When users built ADK tools that utilized reactive thread-hopping (like an RxJava
Singleon an I/O dispatcher), theexecute()block would return immediately, triggering the teardown before the background thread had a chance to emit its final event.The Solution
keepAlive()flag. Agents can invoke this to explicitly inform the server that the execution lifecycle has been handed off to an asynchronous thread.AgentEmitterso it can be dynamically inspected by the orchestration loop.keepAlive()was invoked, the handler skips the early queue closure timeout, allowing theEventConsumerto wait naturally for the background thread to emit the terminal event.Testing
testAsyncAgentWithKeepAlive_Blocking_WaitsForCompletiontoDefaultRequestHandlerTestto simulate a background thread executing and verifying that the client request blocks securely without timing out or closing the queue prematurely.mvn clean installverifying complete backward compatibility with existing synchronous agents.