#7556·crewAI

[BUG] Trace batch marked as failed after a successful finalize when stdout cannot render the emoji panel (Windows, redirected output)

Author: SharoonSharifCreated Sep 17, 2026Updated Sep 17, 2026

Description

TraceBatchManager._finalize_backend_batch (lib/crewai/src/crewai/events/listeners/tracing/trace_batch_manager.py) sends the finalize request, and on 200 sets _batch_finalized = True, records the trace URL, and then prints a rich Panel containing emoji ("✅ Trace batch finalized…", " View here", " Access Code") through a fresh Console(). That print happens inside the same try whose except Exception logs "Error finalizing trace batch" and calls _mark_batch_as_failed(batch_id, str(e)), returning False.

On Windows, when stdout is not a UTF-8 console (redirected to a file, a pipe, a Windows service or Task Scheduler job, a windows-latest CI runner, or any orchestrator capturing output), sys.stdout.encoding is cp1252 and console.print(panel) raises UnicodeEncodeError on the emoji. The result: every successful run ends with an "Error finalizing trace batch" log line, the backend is told the batch failed, and the method returns False, even though the finalize call already succeeded.

Steps to Reproduce

On Windows, run a crew with tracing enabled and stdout redirected:

python main.py > run.log

Or, without the backend, in a child process whose stdout is a pipe and with PYTHONIOENCODING/PYTHONUTF8 unset: build a TraceBatchManager, give it a fake plus_api whose finalize_trace_batch returns status 200, set trace_batch_id, and call _finalize_backend_batch(). It returns False and mark_trace_batch_as_failed is called with 'charmap' codec can't encode character '\u2705'.

Expected behavior

A successful finalize stays successful. If the console cannot render the panel, fall back to a plain log line; never report the batch as failed because of output formatting.

Screenshots/Code snippets

UnicodeEncodeError: 'charmap' codec can't encode character '\u2705' in position 0: character maps to <undefined>
❌ Error finalizing trace batch: 'charmap' codec can't encode character '\u2705' ...

Operating System

Windows 11

Python Version

3.13

crewAI Version

main @ b9629cfb8 (1.15.22+)

crewai-tools Version

same workspace commit

Proposed fix

Guard the panel print: catch UnicodeEncodeError around console.print(panel) and log a plain "Trace batch … finalized. View here: …" line instead. The finalize result is unchanged. PR with a regression test follows.

Disclosure per CONTRIBUTING: this report and the fix were prepared with the help of an AI coding assistant; please apply the llm-generated label.