diff --git a/amplifier_core/coordinator.py b/amplifier_core/coordinator.py index cf0f62a..ff8dc35 100644 --- a/amplifier_core/coordinator.py +++ b/amplifier_core/coordinator.py @@ -335,7 +335,7 @@ async def collect_contributions(self, channel: str) -> list[Any]: if result is not None: contributions.append(result) - except Exception as e: + except BaseException as e: logger.warning( f"Contributor '{contributor['name']}' on channel '{channel}' failed: {e}" ) @@ -353,7 +353,7 @@ async def cleanup(self): result = cleanup_fn() if inspect.iscoroutine(result): await result - except Exception as e: + except BaseException as e: logger.error(f"Error during cleanup: {e}") def reset_turn(self): diff --git a/amplifier_core/session.py b/amplifier_core/session.py index 44f7a32..a58e2de 100644 --- a/amplifier_core/session.py +++ b/amplifier_core/session.py @@ -20,7 +20,7 @@ logger = logging.getLogger(__name__) -def _safe_exception_str(e: Exception) -> str: +def _safe_exception_str(e: BaseException) -> str: """ CRITICAL: Explicitly handle exception string conversion for Windows cp1252 compatibility. Default encoding can fail on non-cp1252 characters, causing a crash during error handling. @@ -432,7 +432,7 @@ async def execute(self, prompt: str) -> str: self.status.status = "completed" return result - except Exception as e: + except BaseException as e: # Check if this was a cancellation-related exception if self.coordinator.cancellation.is_cancelled: self.status.status = "cancelled" @@ -455,8 +455,11 @@ async def execute(self, prompt: str) -> str: async def cleanup(self: "AmplifierSession") -> None: """Clean up session resources.""" - await self.coordinator.cleanup() - # Clean up sys.path modifications + try: + await self.coordinator.cleanup() + except BaseException as e: + logger.error(f"Error during coordinator cleanup: {e}") + # Clean up sys.path modifications - must always run if self.loader: self.loader.cleanup()