◉ANTIGRAVITY LABJP
Articles/Editor View
⟐ Editor View/2026-08-27Intermediate

Three Byte-Level Checks I Run Before an Agent Edits Files That Contain Japanese

When an agent edit swaps a single multi-byte character, git shows it as an ordinary one-line change. Here is how I fold invalid UTF-8, replacement characters, and normalization drift into one pass.

antigravity461utf-8japanese4code-review11

✦ Premium Article

The Antigravity CLI 1.1.21 release notes from August 26 include a fix for edits breaking on files that contain non-ASCII characters.

The fix is welcome. What caught my attention was something else entirely: if the same thing had happened on my machine, would I have noticed?

To find out, I built a stand-in for a resource file listing ukiyo-e artwork names and deliberately removed a single byte from 神奈川沖浪裏. The diff of the broken file looked disappointingly ordinary.

As an indie developer maintaining Japanese resources, I can't treat this as someone else's problem. I hand JSON files full of Japanese artwork titles and headers full of Japanese comments to agents on a regular basis, and I had nothing in place that would have told me when one of them broke.

Git shows a corrupted byte as an ordinary one-line change

I started by reproducing what corruption actually looks like. Take a valid UTF-8 file and remove a single byte from the middle of a three-byte character.

# Drop the third byte of 浪 to produce an invalid UTF-8 sequence
python3 -c "
b = bytearray(open('tracked.txt','rb').read())
i = b.find('浪'.encode())
del b[i+2]
open('tracked.txt','wb').write(bytes(b))"
 
git diff --numstat
git diff | head -8

The output:

1	1	tracked.txt

diff --git a/tracked.txt b/tracked.txt
index 4d2ec8b..50590fb 100644
--- a/tracked.txt
+++ b/tracked.txt
@@ -1,2 +1,2 @@
 // Holds the artwork title
-const title = "神奈川沖浪裏";
+const title = "神奈川沖��裏";

Git does not switch to binary mode. It emits no warning. This is a perfectly ordinary 1 insertion(+), 1 deletion(-).

That is exactly the problem. When you are reading top to bottom through a diff where an agent touched thirty files, a line where one character inside a Japanese string has turned into a replacement glyph barely registers. The line length and structure are unchanged.

If you run agents unattended, a half-written file left behind by a timeout is actually easier to catch. A truncated file breaks the build. A single swapped character does not.

There are three distinct failure modes, and the usual checks cover them unevenly

I prepared five deliberately broken files and lined up how the common inspection commands respond.

FileStatefile verdicticonv -f UTF-8 -t UTF-8Python strict decode
ok.txtValid UTF-8UTF-8 textexit 0OK
broken.txtOne byte removedNon-ISO extended-ASCII textexit 1FAIL (invalid continuation byte)
sjis.txtSaved as CP932OpenPGP Secret Keyexit 1FAIL (invalid start byte)
bom.txtUTF-8 with BOMUTF-8 (with BOM) textexit 0OK
nfd.txtDecomposed dakuten (NFD)UTF-8 textexit 0OK

Three things stand out.

First, file is not dependable here. On my machine it classified a CP932-encoded Japanese text file as an OpenPGP Secret Key. The contents were a single line of Japanese. Encoding detection is heuristic, so misses like this are inevitable. Branching your automation on its verdict is a bad bet.

Second, iconv and Python's strict decode agree. Both are only judging byte-sequence validity, so that is expected. Pick whichever is more convenient.

Third, and most importantly: BOM and NFD pass every one of these checks. They are perfectly valid UTF-8 at the byte level. What is broken is not the bytes but everything downstream of them.

✦

Thank you for reading this far.

Continue Reading

What follows includes implementation code, benchmarks, and practical content we hope you'll find useful. This site runs without ads — server and development costs are supported entirely by members like you. If it's been helpful, we'd be truly grateful for your support.

WHAT YOU'LL LEARN
✦You will be able to decide where to place encoding checks so that a corrupted edit never reaches production unnoticed
✦You will be able to recognize the failure mode that a plain UTF-8 validity check silently lets through, and recover the files it already touched
✦You will be able to choose between a pre-commit hook and CI for a whole-repository scan, based on measured runtime rather than guesswork
Secure payment via Stripe · Cancel anytime
✦

Unlock This Article

Get full access to the rest of this article. Buy once, read anytime. This site is ad-free — your support goes directly toward keeping it running.

or
Unlock all articles with Membership →
Share

Thank You for Reading

Antigravity Lab is ad-free, supported entirely by members like you. We publish practical guides daily with implementation code, benchmarks, and production-ready patterns. If you've found it useful, we'd love to have you on board.

  • ✦Copy-paste ready implementation code
  • ✦New advanced guides published daily
  • ✦$5/mo or $15 for lifetime access
View Membership →

Related Articles

⟐ Editor View2026-08-14
I Stopped Eyeballing Agent Diffs, and the 2.8.0 View Limits Are Why
Version 2.8.0 caps how much of a file and how much of a large history diff you can view. Losing the ability to scroll to the end forced a better split: let a script decide what machines can catch, and spend human attention only on what they cannot. Includes a working script and the defects it found in a real repository.
⟐ Editor View2026-07-09
Localizing Antigravity 2.0 to Japanese — The Three-Layer Setup for Menus, Commands, and AI Responses
Installing the Japanese Language Pack in Antigravity 2.0 only translates part of the UI. To get a clean Japanese experience — menus, command palette, AI responses — you need to configure three independent layers. Here is the exact setup I run as an indie developer at Dolice, plus which parts I deliberately leave in English.
⟐ Editor View2026-10-08
Undo That Rewinds Only the Conversation, and Messaging a Subagent Directly: Three Moments I Hesitated
Antigravity 2.19.1 adds undo for the conversation only, and direct messages to a subagent. Here is what the changelog says, where I draw my own lines, and how to check both safely.
📚RECOMMENDED BOOKS
Build a Large Language Model (From Scratch)
Sebastian Raschka
LLM Dev
Prompt Engineering for LLMs
Berryman & Ziegler
Prompting
AI Engineering
Chip Huyen
AI Eng
* Contains affiliate links