From e3cd7209add70e8146d34c02a512a6aec54a6872 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Moura?= Date: Sat, 31 May 2025 21:37:36 -0700 Subject: [PATCH] fixing console formatter --- .../events/utils/console_formatter.py | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/src/crewai/utilities/events/utils/console_formatter.py b/src/crewai/utilities/events/utils/console_formatter.py index 271030cf7..8d427a495 100644 --- a/src/crewai/utilities/events/utils/console_formatter.py +++ b/src/crewai/utilities/events/utils/console_formatter.py @@ -190,6 +190,10 @@ class ConsoleFormatter: self.print_panel(content, title, style) + # Clear all spinners when crew completes or fails + if status in {"completed", "failed"}: + self._clear_all_spinners() + def create_crew_tree(self, crew_name: str, source_id: str) -> Optional[Tree]: """Create and initialize a new crew tree with initial status.""" if not self.verbose: @@ -240,6 +244,8 @@ class ConsoleFormatter: # When a new task starts, clear pointers to previous agent, reasoning, # and tool branches so that any upcoming Reasoning / Tool logs attach # to the correct task. + if self.current_tool_branch: + self._unregister_spinner_branch(self.current_tool_branch) self.current_agent_branch = None # Keep current_reasoning_branch; reasoning may still be in progress self.current_tool_branch = None @@ -564,6 +570,7 @@ class ConsoleFormatter: f"{tool_name} ({self.tool_usage_counts[tool_name]})", "red", ) + self._unregister_spinner_branch(tool_branch) if tree_to_use: self.print(tree_to_use) self.print() @@ -665,6 +672,7 @@ class ConsoleFormatter: # Update tool branch if it exists if tool_branch: tool_branch.label = Text("❌ LLM Failed", style="red bold") + self._unregister_spinner_branch(tool_branch) if tree_to_use: self.print(tree_to_use) self.print() @@ -1224,6 +1232,10 @@ class ConsoleFormatter: self.print() + # Unregister spinner before clearing + if reasoning_branch is not None: + self._unregister_spinner_branch(reasoning_branch) + # Clear stored branch after completion self.current_reasoning_branch = None @@ -1250,6 +1262,7 @@ class ConsoleFormatter: if reasoning_branch is not None: self.update_tree_label(reasoning_branch, "❌", "Reasoning Failed", "red") + self._unregister_spinner_branch(reasoning_branch) if tree_to_use is not None: self.print(tree_to_use) @@ -1359,6 +1372,11 @@ class ConsoleFormatter: self._stop_spinner_event.set() self._spinner_running = False + def _clear_all_spinners(self): + """Clear all active spinners. Used as a safety mechanism.""" + self._spinner_branches.clear() + self._stop_spinner_thread() + def _spinner_loop(self): import time while self._stop_spinner_event and not self._stop_spinner_event.is_set():