Skip to content

Edit/Write/Bash tools fail with JSON Parse error: Unterminated string when content contains LaTeX math or special characters #1357

Description

@iwantapear

Bug Description

Tools edit, write, bash, and task consistently fail with JSON Parse error: Unterminated string when the parameter content contains:

  • LaTeX math delimiters ($, $$)
  • Backslash sequences (\tanh, \sum, \frac, \text)
  • Pipes (|)
  • Mixed CJK + ASCII characters
  • Content exceeding ~50 lines

The read tool works fine (parameters are simple paths + numbers with no special characters).

Reproduction

  1. Open any file containing LaTeX math (e.g., a markdown file with $...$ formulas)
  2. Try to use the edit tool to replace a section containing $, $$, \frac, etc.
  3. Tool call fails immediately with: JSON Parse error: Unterminated string

Minimal reproduction — even this fails:

edit(file_path="/tmp/test.md", old_string="hello", new_string="world")
→ JSON Parse error: Unterminated string

Root Cause Analysis

Tool parameters are passed via XML invoke tags and internally serialized to JSON. The JSON serializer cannot properly escape special characters ($, ", \, \n) in string-type parameters, causing the string termination boundary to be misdetected.

  • Works: read tool (parameters are file paths + integers, no special chars)
  • Fails: edit, write, bash, task (parameters contain markdown/LaTeX content with $, \, ")

Environment

  • MiMo Code version: 0.1.3
  • Platform: linux (ARM64)
  • Binary: ~/.mimocode/bin/mimo (ELF 64-bit LSB executable, ARM aarch64)

Workaround

Delegate file edits to subagents — subagents use a different parameter passing path that doesn't trigger this bug.

Impact

This bug makes it impossible to directly edit any file containing LaTeX math, markdown formulas, or mixed-language content. Every edit/write attempt consumes a full turn cycle with no visible output to the user, appearing as a terminal hang.

Related

  • Observed across multiple sessions (confirmed in session checkpoints)
  • Also affects bash tool with any content
  • task tool with long prompts also fails

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions