agentscope-java icon indicating copy to clipboard operation
agentscope-java copied to clipboard

[Bug]: FuzzyTextMatcher does not handle CRLF, so SkillManageTool#patch cannot match a Windows-authored skill file

Open wahllllll opened this issue 1 month ago • 1 comments

Describe the bug

SkillManageTool#patch reads the target skill file verbatim and hands it to FuzzyTextMatcher, whose whole reason to exist is absorbing whitespace differences the LLM cannot reproduce exactly. Its two normalisers, however, only split lines on '\n' and treat only ' ' / '\t' as whitespace — a '\r' from a CRLF terminator therefore survives normalisation as ordinary content.

Two consequences, both reachable with a skill file authored on Windows (or staged from a marketplace archive):

  1. patch can never match. A CRLF existing normalises to "foo\r\n" while an LF needle normalises to "foo\n", so no rung of the ladder matches — including WHITESPACE_COLLAPSED, whose entire purpose is to absorb exactly this kind of difference. The call fails with:

    old_string not found in <path> at any fuzziness level (tried exact, trailing-whitespace, and collapsed-whitespace)
    

    and the model has to fall back to action=edit, which rewrites the whole file instead of the requested span.

  2. A match, had it been found, would have rewritten the line ending. The emitted newline was mapped back to the '\n' offset rather than to the start of the terminator, so a match ending at a line boundary would have swallowed the '\r' and silently converted that line to LF.

This is not something the parser already covers: patch reads raw bytes through WorkspaceSkillRepository#readSkillFile → filesystem.read(...), with no newline normalisation anywhere upstream. (MarkdownSkillParser does handle CRLF, but the patch path never goes through it.)

To Reproduce

Patch a skill file whose line endings are CRLF using an LF old_string / new_string pair — for example existing "PREFIX\r\nalpha\r\nbeta\r\nSUFFIX\r\n" with needle "alpha\nbeta". Every fuzziness level reports no match.

Expected behavior

The whitespace-collapsed level should absorb a CRLF/LF difference the same way it absorbs tab/space drift, and a match should stop before the whole CRLF sequence instead of swallowing the '\r'.

Error messages

old_string not found in <path> at any fuzziness level (tried exact, trailing-whitespace, and collapsed-whitespace)

Environment (please complete the following information):

  • AgentScope-Java Version: 2.1.0-SNAPSHOT (main)
  • Java Version: 17
  • OS: Windows 11

Additional context

File: agentscope-harness/src/main/java/io/agentscope/harness/agent/tool/FuzzyTextMatcher.java, both normalisers (stripTrailingWhitespace and collapseWhitespace).

The replacement text is still spliced in verbatim, so patching a CRLF file with LF replacement text produces mixed line endings. That is deliberately out of scope here: normalising the replacement would contradict the class contract of never touching whitespace the LLM did not ask to change.

Fixed in #3416.

wahllllll avatar Oct 11 '26 08:10 wahllllll

Note: this is already fixed on main by #3416 (merged 2026-10-09) — the issue is filed only so the fix has an issue to trace back to. Please close it if you would rather not track it.

wahllllll avatar Oct 11 '26 08:10 wahllllll