Skip to content

fix: unescape \t and \r in new_string before writing to file (#33733)#33745

Closed
hoobnn wants to merge 1 commit into
NousResearch:mainfrom
hoobnn:fix/issue-33733-newstring-escape-sequences
Closed

fix: unescape \t and \r in new_string before writing to file (#33733)#33745
hoobnn wants to merge 1 commit into
NousResearch:mainfrom
hoobnn:fix/issue-33733-newstring-escape-sequences

Conversation

@hoobnn

@hoobnn hoobnn commented May 28, 2026

Copy link
Copy Markdown

Summary

Fixes #33733 — the patch tool now unescapes common escape sequences (\t and \r) in new_string before writing to disk.

Root Cause

The LLM's training data overwhelmingly represents tabs as the two-character sequence \t (e.g. in Python string literals, regex, diffs). When generating JSON tool call arguments, the model produces these literal characters instead of real tab bytes. The tool then faithfully writes those literal characters into the file.

Fix

Added unescaping of \t -> tab and \r -> carriage return in new_string at the top of fuzzy_find_and_replace(), before the matching loop. This is the symmetrical counterpart to _strategy_escape_normalized which already does the same for old_string during matching.

\n is intentionally excluded because newlines serialize correctly in JSON.

Changes

  • tools/fuzzy_match.py: Added 2-line unescape for new_string (\t and \r)
  • tests/tools/test_fuzzy_match.py: Added 5 new tests covering:
    • Tab unescaping in new_string
    • Carriage return unescaping in new_string
    • Newline intentionally NOT unescaped
    • Passthrough when no escape sequences present
    • Tab unescaping working with fuzzy (non-exact) match strategies

When the LLM produces literal backslash-t or backslash-r (two-character
sequences) in new_string instead of real tab/carriage-return bytes,
the patch tool now converts them before writing to disk.

This is the symmetrical counterpart to _strategy_escape_normalized which
already does the same for old_string during matching. \n is excluded
because newlines serialize correctly in JSON.

Fixes NousResearch#33733
@alt-glitch alt-glitch added type/bug Something isn't working P2 Medium — degraded but workaround exists comp/tools Tool registry, model_tools, toolsets labels May 28, 2026
@alt-glitch

Copy link
Copy Markdown
Collaborator

Duplicate of #33737 which addresses the same issue (#33733) with a similar fix. #33737 was filed first and scopes the unescape to the escape_normalized strategy match path.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

comp/tools Tool registry, model_tools, toolsets P2 Medium — degraded but workaround exists type/bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

patch tool: new_string escape sequences (\t) get written literally

2 participants