Skip to content

fix(cli): enforce utf-8 encoding for screenshot text outputs - #13084

Merged
kodjima33 merged 1 commit into
BasedHardware:mainfrom
Aj2280:fix/cli-screenshot-utf8-encoding
Sep 8, 2026
Merged

fix(cli): enforce utf-8 encoding for screenshot text outputs#13084
kodjima33 merged 1 commit into
BasedHardware:mainfrom
Aj2280:fix/cli-screenshot-utf8-encoding

Conversation

@Aj2280

@Aj2280 Aj2280 commented Sep 8, 2026

Copy link
Copy Markdown
Contributor

Summary

In sdks/python-cli/omi_cli/commands/local.py, _write_screenshot_result() invoked Path.write_text() without specifying encoding="utf-8". On Windows locales using legacy non-UTF-8 default encodings (e.g. cp1252), saving plain-text OCR or metadata containing multilingual characters (e.g. Screenshot OCR: café 東京) fails with UnicodeEncodeError.

This PR explicitly sets encoding="utf-8" on all output.write_text() calls in _write_screenshot_result(), ensuring reliable UTF-8 screenshot text exports across all platforms and locale settings.

Fixes #13072

Changes

  • sdks/python-cli/omi_cli/commands/local.py:
    • Specified encoding="utf-8" for string outputs, dictionary content outputs, and JSON fallback outputs in _write_screenshot_result().
  • sdks/python-cli/tests/test_local_screenshot_encoding.py:
    • Added unit and CLI command tests verifying UTF-8 encoding behavior for plain strings, content mappings, and JSON fallback payloads when non-UTF-8 preferred encodings (e.g. cp1252) are simulated.

Verification

  • Automated Tests:
    • sdks/python-cli/venv/bin/pytest sdks/python-cli/tests/test_local_screenshot_encoding.py -v: 4/4 passed.
    • sdks/python-cli/venv/bin/pytest sdks/python-cli/tests/: 132 passed, 1 skipped.
  • Manifest Preflight:
    • Validated with scripts/pr-preflight.

Failure-Class: none

Review in cubic

In `sdks/python-cli/omi_cli/commands/local.py`, `_write_screenshot_result()`
invoked `output.write_text()` using the system default encoding. On Windows
locales with legacy non-UTF-8 code pages, saving OCR text or metadata
containing multilingual characters raises `UnicodeEncodeError`.

Explicitly specify `encoding="utf-8"` on all `write_text()` calls in
`_write_screenshot_result()`.

Fixes BasedHardware#13072

@cubic-dev-ai cubic-dev-ai Bot 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.

No issues found across 2 files

Confidence score: 5/5

  • Automated review surfaced no issues in the provided summaries.
  • No files require special attention.

Re-trigger cubic

@Git-on-my-level Git-on-my-level added positive-signal Automation verified a genuine fix/quality contribution python labels Sep 8, 2026
@Git-on-my-level

Copy link
Copy Markdown
Collaborator

Thanks @Aj2280 — clean, well-scoped fix for #13072, and the tests are the right shape for it.

What I verified:

  • sdks/python-cli/omi_cli/commands/local.py: _write_screenshot_result() had exactly three text-writing calls relying on the locale-dependent default encoding — the plain-string path, the mapping content path, and the final JSON fallback. All three now pin encoding="utf-8". The binary paths are correctly left alone: shutil.copyfile(...) for file-backed results and output.write_bytes(...) for base64 payloads never go through text encoding.
  • sdks/python-cli/tests/test_local_screenshot_encoding.py: covers all three text paths at the unit level plus one end-to-end omi --json local screenshot 9 --output ... run against a mocked local API, reusing the existing test_local.py helpers and conftest.py fixtures (all of which resolve at this head). I also confirmed the locale.getpreferredencoding patch is a genuine seam: with UTF-8 mode off, Path.write_text() without encoding= resolves its codec through exactly that function, so the pre-fix code reproduces the reported UnicodeEncodeError under a simulated legacy code page and the pinned version does not. The fix and its regression tests are real, not vacuous.

One non-blocking note: on interpreters running with UTF-8 mode enabled (PYTHONUTF8=1, or newer interpreters where it is the default), open() ignores the preferred locale encoding, so these particular tests would pass even without the fix on such machines. They still discriminate correctly on the Windows locales from the issue, which is what matters — just worth knowing the red/green signal depends on UTF-8 mode being off.

Good first contribution. This feedback is AI-generated on behalf of the Omi maintainers; leaving the merge decision to a human maintainer.


by AI on behalf of David — if you need David’s attention urgently, please @Git-on-my-level and escalate with need human response.

@kodjima33 kodjima33 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

fix(cli): enforce utf-8 encoding for screenshot text outputs. Confidence 5/5 (root cause stated, fixes #13072, tiny scoped diff, regression tests added). Confirmed bug still present on main (write_text calls in local.py lack encoding param).

@kodjima33
kodjima33 merged commit b5cff63 into BasedHardware:main Sep 8, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

positive-signal Automation verified a genuine fix/quality contribution python

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Python CLI screenshot text export fails on non-UTF-8 Windows locales

3 participants