🤖 refactor: split file edit tool errors into user/agent messages #484
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.
Problem
Agents often continue after file edit failures ("WRITE DENIED, FILE UNMODIFIED: old_string not found") as if nothing happened, leading to commits with incomplete changes. The core issue is that agents send parallel tool calls optimistically (edit + commit) before seeing results.
Solution
Split error communication into two channels:
errorfield (user-facing): Concise error message shown in UInotefield (agent-facing): Explicit failure signal and recovery guidanceKey Changes
note?: stringfield to all file edit error resultsEDIT_FAILED_NOTE_PREFIXconstant for consistent messagingWRITE_DENIED_PREFIXfrom error messagessuccessfield instead of string matchingAgent Notes Pattern
All notes follow this structure:
Examples:
"EDIT FAILED - file was NOT modified. The old_string does not exist in the file. Read the file first to get the exact current content, then retry.""EDIT FAILED - file was NOT modified. The file has 50 lines. Read the file to get current content, then retry."Why This Approach
bashtool already usesnotefield successfullyFiles Modified
src/types/tools.ts- Addednotefield andEDIT_FAILED_NOTE_PREFIXsrc/services/tools/file_edit_replace_shared.ts- Added notes to all error casessrc/services/tools/file_edit_operation.ts- Pass throughnotefieldsrc/services/tools/file_edit_insert.ts- Added notes to all error casessrc/utils/tools/toolDefinitions.ts- Updated descriptions with failure warningssrc/components/tools/FileEditToolCall.tsx- Simplified error detectionsrc/services/tools/file_edit_replace_shared.test.ts- New tests fornotefieldTesting
✅ All 127 tool tests pass (including 3 new tests)
✅ TypeScript compilation successful
✅ ESLint checks passed
Generated with
cmux