Skip to content

fix(host-core): preserve BOM-marked UTF-16 text through Read and Edit - #1445

Merged
vastsa merged 3 commits into
vastsa:mainfrom
AR307:codex/pr-utf16-tools
Oct 7, 2026
Merged

vastsa merged 3 commits into
vastsa:mainfrom
AR307:codex/pr-utf16-tools

Conversation

@AR307

@AR307 AR307 commented Oct 7, 2026

Copy link
Copy Markdown
Contributor

Windows PowerShell 5.1 commonly writes redirected logs as UTF-16LE with a BOM.
Read rejects these ordinary text files as TOOL_BINARY_CONTENT because the
binary sniff treats the encoding's zero bytes as binary data. This reproduces
on upstream 0.17.0, including main at 72b5e826cb7a.

Decode BOM-marked UTF-16LE and UTF-16BE before binary classification, and keep
the original encoding when Edit writes the result. The existing UTF-8 behavior,
line anchors and binary-file refusal remain intact.

Reproduction:

  1. In Windows PowerShell 5.1, run "build passed" > build.log.
  2. Ask the agent to Read build.log.
  3. Before this change, Read reports binary content. Afterward it returns readable
    lines; editing a displayed line retains the BOM, endian and line endings.

Validation:

  • New native Read/Edit regressions fail on the unmodified upstream baseline
    and pass after the fix: UTF-16LE PowerShell logs and UTF-16BE Chinese text.
  • The edited output is compared to the expected encoded bytes, including CRLF.
  • cargo test -p host-core --locked -j 2 tools:: -- --test-threads=1: 92 passed
    on the combined candidate; the two new UTF-16 tests also pass on this standalone
    PR branch.
  • cargo fmt --check: passed.
  • Isolated Windows Electron with the real sidecar and Rust host successfully
    sends decoded Chinese log content to a controlled local provider. This visual
    flow was run on the combined candidate, with identical host tool code.

No model-provider, account, IPC or persistent transcript format changes.

Related work: #1296 handles image-file reads, and #1420 preserves unmatched text in legacy edits. This change handles BOM-marked UTF-16 text decoding and encoding preservation.

Validation candidate: 6f6f189c2eadfd24e360d548b2c72de9c80452a2; upstream main: 72b5e826cb7a9928467091ccf745aa9b225eeb04.

AR307 and others added 3 commits October 7, 2026 14:39
PowerShell logs contain UTF-16 zero bytes that the binary sniff rejected before decoding. Decode BOM-marked text and retain its byte order and line endings so reading and editing ordinary logs works without changing their encoding.
The summary is outside the UTF-16 fix and duplicates the shared root path added by other ready maintenance PRs. Drop it so the PR stays scoped and subsequent conflict resolution only covers the E2E plan entries.
The latest main contains the completed session index migration and its regression coverage. Revalidate the UTF-16 fix against that integration baseline.
@vastsa
vastsa merged commit a46e1a3 into vastsa:main Oct 7, 2026
5 checks passed
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.

2 participants