feat: Add Graceful Plugin Shutdown to Runner

This change introduces a shutdown lifecycle hook for plugins. The `PluginManager` now has an `async def shutdown()` method that will call `await plugin.shutdown()` on any registered plugins that implement the method. This is called from `Runner.close()`, allowing plugins to perform cleanup tasks like flushing logs or closing connections when the runner instance is being closed. This improves the reliability of plugins that perform background operations.

PiperOrigin-RevId: 831037737
This commit is contained in:
Google Team Member
2025-11-11 13:05:03 -08:00
committed by Copybara-Service
parent 01bac62f0c
commit 249216e890
7 changed files with 152 additions and 7 deletions
@@ -455,7 +455,7 @@ class BigQueryAgentAnalyticsPlugin(BasePlugin):
self._background_tasks.add(task)
task.add_done_callback(self._background_tasks.discard)
async def shutdown(self):
async def close(self):
"""Flushes pending logs and closes client."""
# 1. Wait for pending background logs (best effort, 2s timeout)
if self._background_tasks: