The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
test(desktop): attach to a restart-wait owner; keep run_shutdown under its size cap
Tekniumef9a8691aa71
diff --git a/gateway/drain_control.py b/gateway/drain_control.pyindex 602d0ae9bfa..a5d28878176 100644--- a/gateway/drain_control.py+++ b/gateway/drain_control.py@@ -32,6 +32,13 @@ _log = logging.getLogger(__name__)RESTART_WAIT_REASON = "restart_wait"+def open_restart_wait(runner) -> None:+ """Publish the restart's after-turn wait (``drain_reason``) unless a drain already named its own."""+ descriptor = getattr(runner, "session_runtime_descriptor", None)+ if descriptor is not None and not descriptor.get("drain_reason"):+ descriptor["drain_reason"] = RESTART_WAIT_REASON++def restart_wait_open(runner) -> bool:"""True while *runner* is in a restart's after-turn wait (draining, not yet stopping)."""descriptor = getattr(runner, "session_runtime_descriptor", None) or {}diff --git a/gateway/run_shutdown.py b/gateway/run_shutdown.pyindex 76402f6acf3..11b213bca14 100644--- a/gateway/run_shutdown.py+++ b/gateway/run_shutdown.py@@ -1683,11 +1683,8 @@ class GatewayShutdownMixin(GatewaySessionEndMixin):self._restart_task_started = True# Refuse new turns; keep ``_running`` True so the active turn can still deliver its final response.self._draining = True- # Clients may still reach this owner to answer a turn parked on approval/clarify (#139041).- descriptor = getattr(self, "session_runtime_descriptor", None)- if descriptor is not None and not descriptor.get("drain_reason"):- from gateway.drain_control import RESTART_WAIT_REASON- descriptor["drain_reason"] = RESTART_WAIT_REASON+ from gateway.drain_control import open_restart_wait+ open_restart_wait(self) # clients may still answer a turn parked on approval/clarify (#139041)# The restart's after-turn wait is a drain window too: pollers of GET /v1/runs/{id} must see# the boundary from the moment new turns are refused, not only once stop() begins (#115133).self._mark_api_runs_shutdown_requested()@@ -1701,11 +1698,8 @@ class GatewayShutdownMixin(GatewaySessionEndMixin):await asyncio.sleep(0.05)await self.stop(restart=True, detached_restart=detached, service_restart=via_service)- # NOT in _background_tasks: _stop_impl cancels those, which would skip _shutdown_event.set() / exit 75.- # _run_restart is a short-lived self-terminating task (calls stop() then returns). Don't add it to- # _background_tasks — _stop_impl cancels all entries in that set, which would cancel _run_restart- # while it's awaiting _stop_task, propagating CancelledError into _stop_impl and preventing- # _shutdown_event.set() / _exit_code = 75. See #12875. We still hold a strong reference in+ # NOT in _background_tasks: _stop_impl cancels those, which would cancel _run_restart while it+ # awaits _stop_task and skip _shutdown_event.set() / _exit_code = 75 (#12875). We still hold a strong reference in# self._restart_task: a bare asyncio.create_task() keeps only a weak reference, so the event loop# may garbage-collect a still-pending task mid-flight. The cancel loop in _stop_impl explicitly# skips _restart_task for the same reason it skips _stop_task.