@@ -647,20 +647,20 @@ def close(self) -> None:
647647 # MCP server connections + event-loop thread (no-op when no MCP
648648 # servers are configured or none connected)
649649 self .mcp_manager .close_all ()
650- if hasattr ( self . client , "close" ):
650+ with contextlib . suppress ( Exception ): # best effort
651651 self .client .close ()
652- if self .subagent_client is not self .client and hasattr (self .subagent_client , "close" ):
653- self .subagent_client .close ()
652+ if self .subagent_client is not self .client :
653+ with contextlib .suppress (Exception ): # best effort
654+ self .subagent_client .close ()
654655 # defensive: sub-agent workers close their own clones in
655656 # run_subagent's finally; close any stragglers (e.g. a worker
656657 # still winding down after cancel) so no pool leaks
657658 with self ._subagent_clients_lock :
658659 strays = list (self ._active_subagent_clients )
659660 self ._active_subagent_clients .clear ()
660661 for c in strays :
661- if hasattr (c , "close" ):
662- with contextlib .suppress (Exception ): # best effort
663- c .close ()
662+ with contextlib .suppress (Exception ): # best effort
663+ c .close ()
664664
665665 def cancel (self ) -> None :
666666 """Cancel the in-flight agent run (Ctrl-C).
@@ -688,9 +688,8 @@ def cancel(self) -> None:
688688 with self ._subagent_clients_lock :
689689 clients .extend (self ._active_subagent_clients )
690690 for c in clients :
691- if hasattr (c , "abort" ):
692- with contextlib .suppress (Exception ): # best effort
693- c .abort ()
691+ with contextlib .suppress (Exception ): # best effort
692+ c .abort ()
694693
695694 # ------------------------------------------------------------------
696695 # model switching
@@ -759,10 +758,7 @@ def switch_model(self, name: str) -> tuple[bool, str]:
759758 self .calibrator .reset ()
760759 self .temperature = merged ["temperature" ]
761760 self .max_tokens = merged ["max_tokens" ]
762- if hasattr (self .client , "set_timeout" ):
763- self .client .set_timeout (merged ["timeout" ])
764- else :
765- self .client .timeout = merged ["timeout" ]
761+ self .client .set_timeout (merged ["timeout" ])
766762 self .reasoning_effort = merged ["reasoning_effort" ]
767763 self .stream = merged ["stream" ]
768764 return True , f"switched to { name } ({ self .model } )"
0 commit comments