[Bug] string_replace writes the text "undefined" into the file when new_str is missing
Description
If the model calls string_replace without new_str, the validator accepts the call and the file gets the literal text "undefined" where the old text was.
Environment
- OS: Windows 11 Home 10.0.26300
- Node version: v22.22.3
- Nanocoder version: 1.32.0 (built from main at f92cce9c)
- Provider: Not provider-specific
- Model: Not model-specific
Steps to Reproduce
- Create
a.txtcontainingalpha\nbeta\nand read it withread_file. - Call
string_replacewith{"path": "a.txt", "old_str": "beta"}(nonew_str). - Read
a.txt.
Expected Behavior
The validator rejects the call, for example "new_str is required (use an empty string to delete text)". The file is unchanged.
Actual Behavior
The validator returns {valid: true}. The tool then throws, but the file has already been changed.
Logs/Screenshots
execute: Cannot read properties of undefined (reading 'split')
file: "alpha\nundefined\n"
With a CRLF file the validator itself fails with Cannot read properties of undefined (reading 'replace') and execute throws the same error.
Additional Context
- [x] I have searched existing issues to ensure this is not a duplicate
- [x] I can reproduce this issue consistently
- [x] This issue occurs with the latest version of nanocoder (main)
Suggested fix:
source/tools/file-ops/string-replace.tsx:243(stringReplaceValidator): return an error unlesstypeof new_str === 'string'(an empty string stays valid for deleting text). Also guard lines 101 and 124.source/tools/runtime/schema-validate.ts:76skipsundefinedvalues and leaves presence checks to each tool's validator, so this tool must check it itself.- Add a test: a missing
new_stris rejected and the file is not modified.
Hi, I'd like to work on this issue. I'll follow the suggested approach: require new_str to be a string in both the validator and execution entry point, while preserving empty-string deletion. I'll add regression tests for missing and non-string values, unchanged file bytes on rejection, and LF/CRLF behavior. Could you assign this to me (@VIOLETee0)? I'll wait for assignment before starting work.
I’d like to work on this. I’ll add a typeof new_str === 'string' check in the validator and execute, with regression tests. PR shortly.
PR is up: Nano-Collective/nanocoder#2227. Could a maintainer assign this issue to me?