crewAI icon indicating copy to clipboard operation
crewAI copied to clipboard

One failed memory save permanently suppresses later console/spinner output (listener in-progress flags never reset on failure paths)

Open Wilson0511 opened this issue 1 month ago • 2 comments

Description

The event listeners that render console output guard their started/completed pairings behind boolean in-progress flags, and both TraceCollectionListener and EventListener are process-wide singletons. Several failure paths never clear the flag, so the first failure suppresses output for the rest of the process:

  1. TraceCollectionListener.on_memory_save_failed renders the failure but never clears memory_save_in_progress (the completed handler at the same level does clear it). Every later MemorySaveStartedEvent hits the if self.memory_save_in_progress: return guard — no spinner, no started line — and the completed handler mis-pairs.
  2. There is no handler for MemoryRetrievalFailedEvent at all, although emitters fire it (agent/core.py, lite_agent.py). memory_retrieval_in_progress sticks after any retrieval failure.
  3. EventListener.on_knowledge_search_query_failed renders the error but never clears knowledge_retrieval_in_progress.
  4. Both knowledge retrieval twins (handle_knowledge_retrieval / ahandle_knowledge_retrieval in agent/utils.py) only emit KnowledgeRetrievalCompletedEvent when the query rewrite produced a query. When the rewrite returns None (e.g. the agent LLM is not a BaseLLM), the KnowledgeRetrievalStartedEvent is orphaned — nothing ever ends the retrieval, so the flag sticks through path 3's territory as well.

Reproduction (current main)

Register a mock formatter on the singleton, emit MemorySaveStartedEvent + MemorySaveFailedEvent, then a second started/completed pair:

flag after failed save: True                      # expected False
handle_memory_save_started calls: 1                # expected 2

Same shape for retrieval (started + MemoryRetrievalFailedEvent → second started is swallowed) and knowledge (started, query rewrite returns None → second started is swallowed).

Expected behavior

Every started event must have a matching terminal event, and every terminal handler (completed or failed) releases the in-progress flag. The empty-query knowledge path should still emit a (empty) KnowledgeRetrievalCompletedEvent so listeners can pair.

Suggested fix

  • clear memory_save_in_progress in on_memory_save_failed;
  • add a MemoryRetrievalFailedEvent handler that clears memory_retrieval_in_progress (and optionally renders it — the console formatter already has failed panels for save/query);
  • clear knowledge_retrieval_in_progress in on_knowledge_search_query_failed;
  • emit an empty KnowledgeRetrievalCompletedEvent on the empty-query path in both twins.

All display-layer state; no persistence/telemetry changes. Happy to submit a PR with regression tests.

Wilson0511 avatar Oct 22 '26 08:10 Wilson0511

This issue is stale because it has been open for 30 days with no activity. Remove stale label or comment or this will be closed in 5 days.

github-actions[bot] avatar Nov 21 '26 12:11 github-actions[bot]

This issue was closed because it has been stalled for 5 days with no activity.

github-actions[bot] avatar Nov 26 '26 12:11 github-actions[bot]