Repository navigation
fix(memory): replace Unicode box-drawing chars with ASCII tree markers - #322
Open
farizanjum wants to merge 1 commit into
Open
farizanjum wants to merge 1 commit into
farizanjum wants to merge 1 commit into
Conversation
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
Contributor
|
Important Review skippedAuto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the ⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Plus Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
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. Comment |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Replaces Unicode box-drawing characters (
└──U+2514,──U+2500,├──U+251C) inMemoryEntry.__str__()with ASCII tree markers (+--,|--). These characters causedUnicodeEncodeErrorcrashes on Windows cp125x consoles.Fixes #321
Changes
mesa_llm/memory/memory.py: Replaced 7 occurrences of└──/├──with+--/|--inMemoryEntry.__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 outputProblem
MemoryEntry.__str__()used literal Unicode box-drawing characters as decorative tree markers in its output. Whendisplay=True(the default),Console().print(panel)writes these tosys.stdout. On Windows wheresys.stdout.encodingis a cp125x variant (Western/Central/Eastern European, Cyrillic, Greek, Turkish, Hebrew, Arabic, Thai), these codepoints have no encoding mapping and raiseUnicodeEncodeError, crashing the simulation.This affects all memory backends (
STMemory,STLTMemory,LTMemory) since they all callMemoryEntry.display().Rich's
safe_boxcorrectly 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 tosys.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
└──(current)•(U+2022)+--(ASCII)Before / After
Before:
After:
Testing
pre-commit run --all-filespasses (ruff, ruff-format, pyupgrade, codespell)python -m pytest tests/test_memory/ -v --timeout=30 # 137 passed