@@ -87,8 +87,14 @@ async def open(self) -> "MCPEnabledBase":
8787 # Register agent (best effort)
8888 try :
8989 agent_registry .register_agent (self )
90- except Exception :
91- pass
90+ except Exception as exc :
91+ # Best-effort registration; log and continue without failing open()
92+ self .logger .warning (
93+ "Failed to register agent %s in agent_registry: %s" ,
94+ type (self ).__name__ ,
95+ exc ,
96+ exc_info = True ,
97+ )
9298
9399 return self
94100
@@ -100,13 +106,25 @@ async def close(self) -> None:
100106 if self ._agent and hasattr (self ._agent , "close" ):
101107 try :
102108 await self ._agent .close () # AzureAIAgentClient has async close
103- except Exception :
104- pass
109+ except Exception as exc :
110+ # Best-effort close; log failure but continue teardown
111+ self .logger .warning (
112+ "Error while closing underlying agent %s: %s" ,
113+ type (self ._agent ).__name__ if self ._agent else "Unknown" ,
114+ exc ,
115+ exc_info = True ,
116+ )
105117 # Unregister from registry if present
106118 try :
107119 agent_registry .unregister_agent (self )
108- except Exception :
109- pass
120+ except Exception as exc :
121+ # Best-effort unregister; log and continue teardown
122+ self .logger .warning (
123+ "Failed to unregister agent %s from agent_registry: %s" ,
124+ type (self ).__name__ ,
125+ exc ,
126+ exc_info = True ,
127+ )
110128 await self ._stack .aclose ()
111129 finally :
112130 self ._stack = None
@@ -407,26 +425,26 @@ async def close(self) -> None:
407425 if self ._agent and hasattr (self ._agent , "close" ):
408426 try :
409427 await self ._agent .close ()
410- except Exception :
411- pass
428+ except Exception as exc :
429+ logging . warning ( "Failed to close underlying agent %r: %s" , self . _agent , exc , exc_info = True )
412430
413431 # Unregister from registry
414432 try :
415433 agent_registry .unregister_agent (self )
416- except Exception :
417- pass
434+ except Exception as exc :
435+ logging . warning ( "Failed to unregister agent %r from registry: %s" , self , exc , exc_info = True )
418436
419437 # Close credential and project client
420438 if self .client :
421439 try :
422440 await self .client .close ()
423- except Exception :
424- pass
441+ except Exception as exc :
442+ logging . warning ( "Failed to close Azure AgentsClient %r: %s" , self . client , exc , exc_info = True )
425443 if self .creds :
426444 try :
427445 await self .creds .close ()
428- except Exception :
429- pass
446+ except Exception as exc :
447+ logging . warning ( "Failed to close credentials %r: %s" , self . creds , exc , exc_info = True )
430448
431449 finally :
432450 await super ().close ()
0 commit comments