fix: classify str_replace and insert tools as mutating edits#1
Merged
scoootscooob merged 1 commit intoApr 17, 2026
Merged
Conversation
classify_tool_call matched tool names against a fixed set of verb
patterns. The pattern for the "edit" family was:
r"write|edit|patch|apply|create|delete|rename"
This omitted "replace" and "insert", so tools like str_replace,
replace_in_file, insert_text, and insert_at_line all fell through
every check and were returned as ("unknown", False) – classified as
non-mutating with unknown family.
Consequences for any agent that edits via str_replace:
- distinct_mutation_targets stayed empty → min_distinct_mutation_targets
requirement always failed
- read_before_write_ratio was 1.0 for the wrong reason (no mutations
detected, so denominator collapsed to 1)
- "edit" never appeared in distinct_families → required_families check
always reported it as missing
Fix: extend the edit pattern with "replace" and "insert".
Tests added: unit test for classify_tool_call directly and an end-to-end
trajectory test using a str_replace-based edit transcript.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What's wrong
classify_tool_callidentifies the tool family from the tool name using a set of regex patterns. The pattern for the"edit"family is:"replace"and"insert"are missing. As a result, tools likestr_replace,replace_in_file,insert_text, andinsert_at_linefall through every check and return("unknown", False)— classified as non-mutating, unknown family.Impact
For any agent that edits files via
str_replace:distinct_mutation_targetsis always empty →min_distinct_mutation_targetsrequirement always failsread_before_write_ratiois1.0for the wrong reason — no mutations are detected, so the denominator collapses to1"edit"never appears indistinct_families→required_familiesalways reports it as missingFix
Extend the edit pattern:
Tests
Added two new tests in
test_trajectory.py:test_replace_and_insert_tools_are_classified_as_edit— unit test forclassify_tool_calldirectlytest_str_replace_mutation_is_detected_in_trajectory— end-to-end trajectory test verifying that mutations viastr_replaceare properly detectedAll 7 tests pass.