crewAIInc / crewAIInc/crewAI

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

Open Beginner friendly
#7,556 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Python
Stars
58.8k
Forks
8.5k
Avg merge
1d 15h
Merged PRs (30d)
109

Description

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.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start in lib/crewai/src/crewai/events/listeners/tracing/trace_batch_manager.py at TraceBatchManager._finalize_backend_batch, and reproduce the behavior with stdout redirected on Windows or a non-UTF-8 child process. Verify that a successful finalize remains successful when the Rich panel cannot encode its emoji, with a plain fallback log line and no failed-batch notification. Add or run the regression test described in the issue.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
observability
Issue type
Bug
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Active
Clarity
Clearly specified
Newbie friendliness
88/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.