From 2ab4986b255896f6f0d457ca006f987349e103cf 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 5e998885b..f76c2de35 100644 --- a/src/crewai/utilities/events/utils/console_formatter.py +++ b/src/crewai/utilities/events/utils/console_formatter.py @@ -191,6 +191,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: @@ -241,6 +245,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 @@ -610,6 +616,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() @@ -711,6 +718,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() @@ -1270,6 +1278,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 @@ -1296,6 +1308,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) @@ -1405,6 +1418,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():