Skip to content

I-037 — Gemini cleanup mangles CJK characters

✅ Attestation: read AGENTS.md · board checked by scope (T-187 closed; no ticket covers text fidelity — no dup) · ticket-only fix. Source: EOP Telegram Bot · https://claude.ai/code/session_019z4CYS2vGnufAXZNDmnBJW

Symptom

Owner (2026-07-28): receipt content — Chinese characters especially — gets transformed into unreadable words on the processed (Gemini-cleaned) receipt image. Repro: any CJK-heavy receipt through the bot; the displayed "scanned" copy shows invented glyph-like strokes where the printed Chinese was.

Why it happens

The cleanup pass regenerates the receipt as an AI-drawn image; CJK glyph fidelity is a known weak point of generative redrawing. The drift guard (verifyCleanedImagediffParsedReceipts) compares only five numeric fields (total, lineItemsSum, subtotal, serviceCharge, tax) — text is never compared, so a numerically-faithful but textually-mangled redraw passes and is displayed. Data integrity is unaffected by design: parsed fields are always extracted from the ORIGINAL photo, which is also retained in Drive (and viewable via the card's show-original toggle).

Decision + fix (owner, 2026-07-28)

Owner chose prompt-level text-fidelity clauses over a text-drift verification gate — verbatim: "I'd rather that we make sure in our initial prompt to Gemini includes a request to explicitly tell Gemini not to mangle characters in any language anywhere on the receipt… I can accept a few mangled character on the receipt after they're processed… and I also feel that we could always use the original, so it's okay." Rationale: a gate would reject more redraws into plain-crop displays; residual mangling is acceptable because the original is always available and the books never read the redrawn image.

Fix: GEMINI_IMAGE_CLEANUP_PROMPT gains an appended fidelity clause (copy characters stroke-for-stroke, never invent/substitute glyphs, blurry stays blurry) — the proven first sentence is untouched per the historical over-specification lesson documented at the prompt. Honest expectation: this reduces, not eliminates, mangling — glyph fidelity is partly a model-capability limit, not only instruction- following. The bot agent flagged this and the owner accepted the residual. A text-drift gate (compare merchant + line-item descriptions original-parse vs cleaned-parse; zero extra model calls) remains the documented fallback plan if prompt-level fidelity proves insufficient.

Watch after deploy: cropper fallback rate (a prompt regression on the green background would show there) and whether CJK receipts read acceptably; Re-run AI resamples from the original and may improve any given receipt, but nothing verifies text — that is the accepted trade.

  • SHAs: the commit carrying this ticket + the prompt change (same commit); merged via PR.