@@ -521,13 +521,13 @@ async def aafter_agent(self, state: ShellToolState, runtime: Runtime) -> None:
521521 """Async counterpart to `after_agent`."""
522522 return self .after_agent (state , runtime )
523523
524- def _ensure_resources (self , state : ShellToolState ) -> _SessionResources :
525- resources = state . get ( "shell_session_resources" )
526- if resources is not None and not isinstance ( resources , _SessionResources ):
527- resources = None
528- if resources is None :
529- return self ._get_or_create_resources ()
530- return resources
524+ def _ensure_resources (self , state : ShellToolState ) -> _SessionResources : # noqa: ARG002
525+ """Always return live resources from middleware cache.
526+
527+ State is ignored — session is managed internally to support restart and HIL resume.
528+ """
529+ return self ._get_or_create_resources ()
530+
531531 def _get_or_create_resources (self ) -> _SessionResources :
532532 if self ._session is None :
533533 self ._ensure_session ()
@@ -677,8 +677,10 @@ def _run_shell_tool(
677677 if payload .get ("restart" ):
678678 LOGGER .info ("Restarting shell session on request." )
679679 try :
680- session .restart ()
680+ session .stop (self ._execution_policy .termination_timeout )
681+ session .start ()
681682 self ._run_startup_commands (session )
683+ self ._session = session
682684 except BaseException as err :
683685 LOGGER .exception ("Restarting shell session failed; session remains unavailable." )
684686 msg = "Failed to restart shell session."
0 commit comments