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
agentfield.agent_server.AgentServer._graceful_shutdown does not track in-flight asyncio tasks, so when shutdown fires, long-running reasoner tasks continue executing in the background past the shutdown deadline. The agent process exits while work is still in progress — partial state, potential dropped responses, and a confusing audit trail in the control plane.
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_cancels_in_flight_tasks_within_deadline (skipped with pytest.skip("source bug: graceful shutdown does not track or cancel in-flight tasks"))
Reproduction
agent=make_shutdown_agent()
server=AgentServer(agent)
asyncdeflong_running():
awaitasyncio.sleep(60)
tasks= [asyncio.create_task(long_running()) for_inrange(5)]
awaitserver._graceful_shutdown(timeout_seconds=0)
# Expected: all tasks done (completed or cancelled) before _graceful_shutdown returns# Actual: tasks still running after _graceful_shutdown — server exits leaving them orphaned
Expected behavior
_graceful_shutdown should:
Maintain a registry of in-flight reasoner tasks (created when a request arrives, removed when it completes)
On shutdown, await all pending tasks up to the configured deadline
Summary
agentfield.agent_server.AgentServer._graceful_shutdowndoes not track in-flight asyncio tasks, so when shutdown fires, long-running reasoner tasks continue executing in the background past the shutdown deadline. The agent process exits while work is still in progress — partial state, potential dropped responses, and a confusing audit trail in the control plane.Where
sdk/python/agentfield/agent_server.pyAgentServer._graceful_shutdownsdk/python/tests/test_agent_graceful_shutdown.py::test_graceful_shutdown_cancels_in_flight_tasks_within_deadline(skipped withpytest.skip("source bug: graceful shutdown does not track or cancel in-flight tasks"))Reproduction
Expected behavior
_graceful_shutdownshould:os._exitafter the task drain is completeReference implementation: most ASGI servers (uvicorn, hypercorn) follow this pattern — track requests, drain on shutdown, cancel on deadline.
Acceptance criteria
AgentServermaintains a set of in-flight reasoner tasks_graceful_shutdownawaits all in-flight tasks before exittest_agent_graceful_shutdown.py::test_graceful_shutdown_cancels_in_flight_tasks_within_deadlineis 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.