[Bug]: windowed edit tool parses replace_all with type=bool, so "false"/"0" enable replace-all
Describe the bug
The edit tool in the windowed_edit_replace bundle parses its optional third argument with argparse type=bool:
# tools/windowed_edit_replace/bin/edit, get_parser()
parser.add_argument("replace_all", type=bool, nargs="?", default=False)bool("false"), bool("False") and bool("0") are all True, so any non-empty string enables replace-all. This makes it impossible for the model to request a single (first-occurrence-only) replacement by passing an explicit false-y value, which contradicts the tool docstring ("If replace-all is True, replace all occurrences...").
This affects both invocation paths:
- Function calling:
replace-allis declared astype: booleaninconfig.yaml. A JSONfalsereachesget_quoted_arg()insweagent/tools/parsing.py, is returned as-is (non-str), rendered through the{{value}}template into the literal stringFalse, and the command line becomesedit <search> <replace> False— which the parser turns intoTrue. - Backtick/template path: the model writes
edit <search> <replace> falsedirectly, same result.
Steps/commands/code to Reproduce
import argparse
parser = argparse.ArgumentParser()
parser.add_argument("search", type=str)
parser.add_argument("replace", type=str)
parser.add_argument("replace_all", type=bool, nargs="?", default=False)
for argv in (["a", "b", "false"], ["a", "b", "False"], ["a", "b", "0"], ["a", "b"]):
print(argv, "->", parser.parse_args(argv).replace_all)End-to-end (function-calling path, verified against main @ 3ea751c using the real Command model and the parsing.py rendering logic):
JSON {"replace-all": false}
-> command line: 'edit hello world False'
-> parser sees replace_all = True # wrongError message/results
| argv (third argument) | current replace_all |
expected |
|---|---|---|
"false" |
True |
False |
"False" (function-calling rendering of JSON false) |
True |
False |
"0" |
True |
False |
"true" |
True |
True |
| omitted | False |
False |
System Information
Windows 11 x64, Python 3.13.9, verified against main @ 3ea751c. The bug is version-independent (argparse type=bool behavior).
Source: SWE-agent/SWE-agent