GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — fix(core): refuse to rewrite files that are not valid UTF-8 by neriousy · Pull Request #64868 · anomalyco/opencode

Conversation

@neriousy

@neriousy neriousy commented Nov 19, 2026

Copy link
Copy Markdown
Member

Issue for this PR

Closes #45924

Type of change

  • Bug fix
  • New feature
  • Refactor / code improvement
  • Documentation

What does this PR do?

edit and patch read files through FileMutation.readText, which decodes leniently, so every non-UTF-8 byte (Latin-1, cp1252, GBK...) became U+FFFD and the whole file got written back like that. The tool still reported success.

  • new FileMutation.readEditableText checks the bytes with isUtf8 and fails with FileMutation.InvalidUtf8Error instead
  • edit and patch updates read through it, so the file is left untouched and the model gets told to use a byte-preserving tool or convert the file
  • patch verification fails before any write, so a multi-file patch applies nothing
  • patch deletes, post-write readbacks and write stay lenient since they don't rewrite bytes they decoded

read is still lenient, didn't touch that here.

How did you verify your code works?

  • reproduced on dev with real models on a 406-line Latin-1 Invoice.java (edit on line 405, accents on line 1): claude-sonnet-5-5 via edit and gpt-6.2-sol via patch both replaced the header bytes with ef bf bd
  • with the fix both tools refuse, the models fall back to byte-level sed / python and git diff shows only the edited line
  • new tests in tool-edit.test.ts and tool-patch.test.ts fail on dev and pass here (--rerun-each 10)
  • edit, patch, write and file-mutation suites pass, bun typecheck in packages/core is clean

Screenshots / recordings

n/a

Checklist

  • I have tested my changes locally
  • I have not included unrelated changes in this PR

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@neriousy
fix(core): refuse to rewrite files that are not valid UTF-8
989887a
opencodejr[bot]
opencodejr Bot reviewed Nov 19, 2026
View reviewed changes

@opencodejr opencodejr Bot left a comment

Copy link
Copy Markdown
Contributor

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

The change looks good to me. I ran the #45924 reproduction from source with a simulated model on a file containing GBK bytes. On the base, both edit and patch (the latter called through execute) reported success and replaced d6 d0 ce c4 with ef bf bd ×4. With this PR, both tools fail with the new "not valid UTF-8" message and od shows the file byte-for-byte unchanged. The new edit and patch tests fail on the base and pass here. The edit, patch, write and file-mutation suites pass, and tsc -b in packages/core is clean.

Public API is unchanged: readEditableText and InvalidUtf8Error are internal to core.

No blocking concerns.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@opencodejr opencodejr Bot mentioned this pull request Nov 19, 2026
fix(core): refuse to rewrite files that are not valid UTF-8 #64961
Closed
6 tasks
@neriousy
neriousy merged commit b4d81f0 into dev Nov 19, 2026
11 checks passed

Uh oh!

There was an error while loading. Please reload this page.

@neriousy
neriousy deleted the non-utf8-files branch November 19, 2026 19:51
@opencodejr opencodejr Bot mentioned this pull request Nov 20, 2026
fix(core): ask permission before taking edit lock to avoid blocking other sessions #65169
Closed
@BrewTestBot BrewTestBot mentioned this pull request Nov 23, 2026
opencode 2.4.0 Homebrew/homebrew-core#327368
Merged
@amrkmn amrkmn mentioned this pull request Nov 23, 2026
opencode 2.4.0 amrkmn/homebrew-tap#1251
Closed
1 task
@github-actions github-actions Bot mentioned this pull request Nov 23, 2026
feat: opencode release v2.4.0 sprisa/opencode-server#95
Merged
@scottames-github-bot scottames-github-bot Bot mentioned this pull request Nov 27, 2026
chore(deps): update ⬆️ mise-packages scottames/dots#1181
Merged
1 task
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@opencodejr opencodejr[bot] opencodejr[bot] left review comments

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

edit and apply_patch silently corrupt non-UTF-8 files (U+FFFD replacement)

Uh oh!

There was an error while loading. Please reload this page.

1 participant

@neriousy
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.
You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.