gemini-cli - 💡(How to fix) Fix The write_file tool corrupts or truncates long text sequences during file writes

Official PRs (…)
ON THIS PAGE

Recommended Tools

×6

Utilities matched from this issue’s tags and category — try them while you read without losing context.

GitHub issue graph ai analysis

Paste a GitHub issue URL. We fetch that issue, discover linked issues from bodies/comments/timeline, collect linked pull requests, and produce a structured English report.

The report is written in English Markdown for sharing and archival.

Helpful · Quick feedback

Loading…

Code Example

> /about
| CLI Version: 0.42.0                                                                                                                                                                       
Git Commit: 68e2196d5                                                                                                                                                                     
| Model: Auto (Gemini 3)                                                                                                                                                              
Sandbox: no sandbox                                                                                                                                                                   
OS: linux                                                                                                                                                                      
Auth Method: Signed in with Google (pfelipm@gmail.com)                                                                                                                                    
Tier: Gemini Code Assist in Google One AI Pro
RAW_BUFFERClick to expand / collapse

What happened?

When using the built-in write_file tool in the Gemini CLI to refactor a file containing very long text sequences, the output becomes corrupted or truncated.

The issue specifically triggered when the model was instructed to modify an Apps Script function's logic while explicitly being asked to keep a massive, pre-existing literal character-mapping object (latin_map spanning 6,671 characters) completely intact (source). The tool introduced structural anomalies. It generated malformed key-value pairs towards the tail end of the sequence (e.g., corrupting data into "": "v"), omitted vital closing characters, and subtly altered character capitalization against explicit source integrity (such as converting lowercase characters like ų, ü, ŷ, ź, ż to their uppercase equivalents).

The exact same precision breakdown and loss of data integrity occurred previously within this project when the tool attempted to process a large inline base64-encoded image (source).

What did you expect to happen?

The write_file tool should execute file writes with 100% precision and integrity. It must preserve every character, symbol, structure, and case exactly as intended by the model's logic or the original code block, regardless of the text sequence length or token volume.

Client information

<details> <summary>Client Information</summary>

Run gemini to enter the interactive CLI, then run the /about command.

> /about
| CLI Version: 0.42.0                                                                                                                                                                       
│ Git Commit: 68e2196d5                                                                                                                                                                     
| Model: Auto (Gemini 3)                                                                                                                                                              
│ Sandbox: no sandbox                                                                                                                                                                   
│ OS: linux                                                                                                                                                                      
│ Auth Method: Signed in with Google ([email protected])                                                                                                                                    
│ Tier: Gemini Code Assist in Google One AI Pro
</details>

Login information

Personal Google Account.

Anything else we need to know?

The agent explicitly acknowledged its own failure in the session logs, stating that its output fidelity becomes compromised when reproducing massive, continuous code blocks due to output token limits during a single write operation.

The terminal outputs (attached as screenshots in the report) clearly capture the exact diff comparison where the WriteFile action truncates the map and fails to close the object layout properly.

<img width="1509" height="1460" alt="Image" src="https://github.com/user-attachments/assets/e1d98329-9126-4478-87ba-63384e4e2e84" /> <img width="1509" height="1460" alt="Image" src="https://github.com/user-attachments/assets/80777ec2-b941-4e47-89b5-af09cadd8fcb" /> <img width="1509" height="1460" alt="Image" src="https://github.com/user-attachments/assets/20045d78-734f-4fea-92f4-774e0ae41098" />

Vote matrix · Quick signals

Works
Did the solution work? Tap to confirm.
Easy Fix
Was it a quick fix?
Time Saver
Did it save you time?
Blocking
Was it severely blocking?
Common Issue
Are others likely hitting this too?
Flaky / Intermittent
Is it intermittent?
Verified / Reproducible
Can you reproduce it reliably?
Loading…

Still need to ship something?

×6

Another batch ranked right after the header list — different links, same matching logic.

Back to top recommendations

TRENDING