Skip to content

Add explicit UTF-8 encoding to file operations in autogen-ext#7400

Open
alpnix wants to merge 1 commit intomicrosoft:mainfrom
alpnix:fix/add-utf8-encoding-to-file-operations
Open

Add explicit UTF-8 encoding to file operations in autogen-ext#7400
alpnix wants to merge 1 commit intomicrosoft:mainfrom
alpnix:fix/add-utf8-encoding-to-file-operations

Conversation

@alpnix
Copy link

@alpnix alpnix commented Mar 14, 2026

Summary

Fixes #5566 by adding encoding='utf-8' parameter to text-mode file operations that were missing it in the autogen-ext package. This prevents UnicodeDecodeError on Windows systems with non-English system locales.

Problem

The codebase had multiple open() calls without explicit UTF-8 encoding, causing crashes on Windows with non-English locales (Chinese, Japanese, etc.). While one instance was previously fixed in playwright_controller.py, several others remained throughout the codebase.

Changes

Added encoding="utf-8" to 6 file operations across 3 files:

1. code_executors/docker_jupyter/_docker_jupyter.py

  • Line 278: HTML file writing in _save_html method

2. experimental/task_centric_memory/utils/page_logger.py

  • Line 120: Hash file writing
  • Line 389: Call tree HTML writing
  • Line 501: Page HTML writing

3. experimental/task_centric_memory/utils/chat_completion_client_recorder.py

  • Line 76: JSON session file reading
  • Line 214: JSON session file writing

Testing

  • ✅ All changes are mechanical additions of the encoding parameter
  • ✅ No functional changes to code logic
  • ✅ Follows Python 3 best practices (PEP 597)
  • ✅ Syntax validated

Impact

High - Prevents crashes for international users on Windows systems with non-English locales, improving cross-platform compatibility.

Diff Summary

 3 files changed, 6 insertions(+), 6 deletions(-)

All changes follow the same pattern:

# Before
with open(path, "w") as f:

# After  
with open(path, "w", encoding="utf-8") as f:

Closes #5566

Fixes microsoft#5566 by adding encoding='utf-8' parameter to all text-mode
file operations that were missing it. This prevents UnicodeDecodeError
on Windows systems with non-English system locales.

Changes made:
- docker_jupyter/_docker_jupyter.py: HTML file writing
- page_logger.py: Hash file, call tree HTML, and page HTML writing
- chat_completion_client_recorder.py: JSON session file read/write

This follows Python 3 best practices (PEP 597) and ensures
cross-platform compatibility for international users.

All changes are mechanical additions of encoding parameter with
no functional changes to the code logic.
@alpnix
Copy link
Author

alpnix commented Mar 14, 2026

@microsoft-github-policy-service agree

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.

open needs encoding='utf-8' for non-english environment, error in playwright_controller.py

1 participant