-
-
Notifications
You must be signed in to change notification settings - Fork 143
Improve backend error handling and logging for async tasks #292
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
e2d24cd
adfeb13
2ad883b
f4a8126
deee362
aaafc99
a4d57cf
5be446e
ebb6809
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -27,6 +27,7 @@ def _register_handlers(self): | |
| @traceable(name="devrel_request_coordination", run_type="chain") | ||
| async def _handle_devrel_request(self, message_data: Dict[str, Any]): | ||
| """Handle DevRel agent requests""" | ||
| session_id = None | ||
| try: | ||
| # Extract memory thread ID (user_id for Discord) | ||
| memory_thread_id = message_data.get("memory_thread_id") or message_data.get("user_id", "") | ||
|
|
@@ -58,11 +59,15 @@ async def _handle_devrel_request(self, message_data: Dict[str, Any]): | |
| await self._send_response_to_platform(message_data, result_state.final_response) | ||
|
|
||
| except Exception as e: | ||
| logger.error(f"Error handling DevRel request: {str(e)}") | ||
| logger.error( | ||
| "Error handling DevRel request for session %s", | ||
| session_id, exc_info=True, | ||
| ) | ||
| await self._send_error_response(message_data, "I'm having trouble processing your request. Please try again.") | ||
|
|
||
| async def _handle_clear_memory_request(self, message_data: Dict[str, Any]): | ||
| """Handle requests to clear thread memory""" | ||
| memory_thread_id = None | ||
| try: | ||
| memory_thread_id = message_data.get("memory_thread_id") | ||
| cleanup_reason = message_data.get("cleanup_reason", "manual") | ||
|
|
@@ -81,8 +86,11 @@ async def _handle_clear_memory_request(self, message_data: Dict[str, Any]): | |
| else: | ||
| logger.error(f"Failed to clear memory for thread {memory_thread_id}") | ||
|
|
||
| except Exception as e: | ||
| logger.error(f"Error clearing memory: {str(e)}") | ||
| except Exception: | ||
| logger.error( | ||
| "Error clearing memory for thread %s", | ||
| memory_thread_id, exc_info=True, | ||
| ) | ||
|
Comment on lines
+89
to
+93
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do not silently swallow queue-handler failures after logging. These blocks log and continue, which means queue-dispatched failures can be treated as successful handler completion (no exception propagated). In flows like response enqueue/clear-memory timeout, this can lose critical work without retry/dead-letter behavior. Suggested patch pattern- except Exception:
+ except Exception:
logger.error(
"Error sending response to platform %s",
platform, exc_info=True,
)
+ raiseApply the same pattern to the other queue-handler exception blocks where failure should participate in queue failure handling. Also applies to: 108-112, 131-135 🤖 Prompt for AI Agents |
||
|
|
||
| async def _handle_memory_timeout(self, memory_thread_id: str, state: AgentState): | ||
| """Handle memory timeout - store to database and clear from InMemorySaver""" | ||
|
|
@@ -97,11 +105,15 @@ async def _handle_memory_timeout(self, memory_thread_id: str, state: AgentState) | |
|
|
||
| logger.info(f"Memory timeout handled successfully for thread {memory_thread_id}") | ||
|
|
||
| except Exception as e: | ||
| logger.error(f"Error handling memory timeout: {str(e)}") | ||
| except Exception: | ||
| logger.error( | ||
| "Error handling memory timeout for thread %s", | ||
| memory_thread_id, exc_info=True, | ||
| ) | ||
|
|
||
| async def _send_response_to_platform(self, original_message: Dict[str, Any], response: str): | ||
| """Send agent response back to the originating platform""" | ||
| platform = None | ||
| try: | ||
| platform = original_message.get("platform", "discord") | ||
|
|
||
|
|
@@ -116,8 +128,11 @@ async def _send_response_to_platform(self, original_message: Dict[str, Any], res | |
|
|
||
| await self.queue_manager.enqueue(response_message) | ||
|
|
||
| except Exception as e: | ||
| logger.error(f"Error sending response to platform: {str(e)}") | ||
| except Exception: | ||
| logger.error( | ||
| "Error sending response to platform %s", | ||
| platform, exc_info=True, | ||
| ) | ||
|
|
||
| async def _send_error_response(self, original_message: Dict[str, Any], error_message: str): | ||
| """Send error response to platform""" | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.