You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Even when an in-flight task survives past the configured timeout_seconds, agentfield.agent_server.AgentServer._graceful_shutdown does not force-cancel it. The process exits while the task is still running, leaving an orphaned coroutine in the event loop. This is the second half of the graceful-shutdown gap (the first being task tracking — see #356).
Where
File:sdk/python/agentfield/agent_server.py
Function:AgentServer._graceful_shutdown
Discovered by:sdk/python/tests/test_agent_graceful_shutdown.py::test_graceful_shutdown_force_cancels_tasks_after_timeout (skipped with pytest.skip("source bug: graceful shutdown does not enforce timeout-based task cancellation"))
Reproduction
agent=make_shutdown_agent()
server=AgentServer(agent)
task=asyncio.create_task(asyncio.sleep(60)) # task that will outlive the deadlineawaitserver._graceful_shutdown(timeout_seconds=0)
# Expected: task.cancelled() is True (the deadline forced a cancel)# Actual: task is still running — no cancel issued
Summary
Even when an in-flight task survives past the configured
timeout_seconds,agentfield.agent_server.AgentServer._graceful_shutdowndoes not force-cancel it. The process exits while the task is still running, leaving an orphaned coroutine in the event loop. This is the second half of the graceful-shutdown gap (the first being task tracking — see #356).Where
sdk/python/agentfield/agent_server.pyAgentServer._graceful_shutdownsdk/python/tests/test_agent_graceful_shutdown.py::test_graceful_shutdown_force_cancels_tasks_after_timeout(skipped withpytest.skip("source bug: graceful shutdown does not enforce timeout-based task cancellation"))Reproduction
Expected behavior
_graceful_shutdown(timeout_seconds=N)should:Nseconds for in-flight tasks to drain (depends on [Python SDK] graceful shutdown does not track or cancel in-flight tasks #356)task.cancel()on every still-running tracked taskawait asyncio.gather(*tasks, return_exceptions=True)to let cancellation propagateA
timeout_seconds=0value should mean "cancel immediately", not "wait forever".Acceptance criteria
timeout_secondselapses, all still-running tracked tasks receivecancel()timeout_seconds=0cancels immediatelytest_agent_graceful_shutdown.py::test_graceful_shutdown_force_cancels_tasks_after_timeoutis unskipped and passesRelated
Agent.stop()not implemented)Discovered via
PR #352 (test coverage improvements). One of 5 source bugs surfaced while writing failure-mode tests for the Python SDK.