Skip to content

fix(memory): replace Unicode box-drawing chars with ASCII tree markers - #322

Open
farizanjum wants to merge 1 commit into
mesa:mainfrom
farizanjum:fix/memory-display-unicode-crash
Open

farizanjum wants to merge 1 commit into
mesa:mainfrom
farizanjum:fix/memory-display-unicode-crash

Conversation

@farizanjum

@farizanjum farizanjum commented Aug 7, 2026 •

Copy link
Copy Markdown

Summary

Replaces Unicode box-drawing characters (└── U+2514, ── U+2500, ├── U+251C) in MemoryEntry.__str__() with ASCII tree markers (+--, |--). These characters caused UnicodeEncodeError crashes on Windows cp125x consoles.

Fixes #321

Changes

  • mesa_llm/memory/memory.py: Replaced 7 occurrences of └──/├── with +--/|-- in MemoryEntry.__str__()
  • tests/test_memory/test_memory_encoding.py: New regression test verifying output is encodable across 14 Windows code pages + UTF-8, and that no box-drawing characters (U+2500-U+257F) remain in output

Problem

MemoryEntry.__str__() used literal Unicode box-drawing characters as decorative tree markers in its output. When display=True (the default), Console().print(panel) writes these to sys.stdout. On Windows where sys.stdout.encoding is a cp125x variant (Western/Central/Eastern European, Cyrillic, Greek, Turkish, Hebrew, Arabic, Thai), these codepoints have no encoding mapping and raise UnicodeEncodeError, crashing the simulation.

This affects all memory backends (STMemory, STLTMemory, LTMemory) since they all call MemoryEntry.display().

Rich's safe_box correctly degrades its own panel borders to ASCII on legacy consoles, but the box-drawing characters in __str__() are literal content text -- Rich cannot degrade them, so they pass through to sys.stdout.write() and fail.

Solution

ASCII tree markers (+--, |--) are pure ASCII (bytes 0x2B, 0x2D, 0x7C). Safe in every encoding ever created. Preserves the tree hierarchy that └──/├── provided.

Options considered

Option cp125x cp437/850 cp932/936/949 Verdict
└── (current) CRASH safe safe broken
• (U+2022) safe CRASH CRASH trades one crash for another
+-- (ASCII) safe safe safe universally safe

Before / After

Before:

[Observation]
   └── price : $20
   └── seller : Bob
[Action]
   ├── (1)
   │  └── offer : $25
   ├── (2)

After:

[Observation]
   +-- price : $20
   +-- seller : Bob
[Action]
   |-- (1)
   |   +-- offer : $25
   |-- (2)
Screenshot 2026-08-08 023822

Testing

  • All 121 existing memory tests pass
  • 16 new encoding tests pass (14 parametrized code page tests + box-drawing absence + tree structure preservation)
  • pre-commit run --all-files passes (ruff, ruff-format, pyupgrade, codespell)
python -m pytest tests/test_memory/ -v --timeout=30
# 137 passed

MemoryEntry.__str__() used literal Unicode box-drawing characters
(U+2514, U+2500, U+251C) as decorative tree markers. These crash with
UnicodeEncodeError on Windows cp125x consoles (Western/Central/Eastern
European, Cyrillic, Greek, Turkish, Hebrew, Arabic, Thai), which is the
default sys.stdout.encoding for the majority of Windows users.

Replaced with ASCII tree markers (+-- and |--), which are safe in every
encoding and preserve the tree hierarchy. The bullet character (U+2022)
was considered but rejected because it crashes on cp437/cp850/cp932/
cp936/cp949 (DOS-legacy and Asian Windows).

Fixes mesa#321
Copilot AI lite review requested due to automatic review settings August 7, 2026 21:21

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@coderabbitai

coderabbitai Bot commented Aug 7, 2026

Copy link
Copy Markdown
Contributor

Important

Review skipped

Auto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: c68d0135-d7e4-454c-a95f-8beffa7d27e5

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

bug: MemoryEntry display crashes with UnicodeEncodeError on Windows cp125x consoles

2 participants