Skip to content

Conversation

@ammar-agent
Copy link
Collaborator

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:

  1. error field (user-facing): Concise error message shown in UI
  2. note field (agent-facing): Explicit failure signal and recovery guidance

Key Changes

  • Add note?: string field to all file edit error results
  • Introduce EDIT_FAILED_NOTE_PREFIX constant for consistent messaging
  • Remove redundant WRITE_DENIED_PREFIX from error messages
  • Simplify UI to detect failures via success field instead of string matching
  • Update tool descriptions to warn upfront that edits may fail

Agent Notes Pattern

All notes follow this structure:

EDIT FAILED - file was NOT modified. [Problem]. [Fix].

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

  1. Upfront warnings in tool descriptions tell agents not to assume success
  2. Clear failure signals with "EDIT FAILED" prefix
  3. Actionable remediation telling agents exactly what to do (read file, retry)
  4. Follows existing pattern - the bash tool already uses note field successfully

Files Modified

  • src/types/tools.ts - Added note field and EDIT_FAILED_NOTE_PREFIX
  • src/services/tools/file_edit_replace_shared.ts - Added notes to all error cases
  • src/services/tools/file_edit_operation.ts - Pass through note field
  • src/services/tools/file_edit_insert.ts - Added notes to all error cases
  • src/utils/tools/toolDefinitions.ts - Updated descriptions with failure warnings
  • src/components/tools/FileEditToolCall.tsx - Simplified error detection
  • src/services/tools/file_edit_replace_shared.test.ts - New tests for note field

Testing

✅ All 127 tool tests pass (including 3 new tests)
✅ TypeScript compilation successful
✅ ESLint checks passed

Generated with cmux

- Add 'note' field to file edit error results for agent-specific guidance
- Introduce EDIT_FAILED_NOTE_PREFIX constant for consistent messaging
- Remove redundant WRITE_DENIED_PREFIX from error messages
- Simplify UI error detection to check success field directly
- Update tool descriptions to warn that edits may fail

Agent notes provide clear failure signals and recovery steps:
- 'EDIT FAILED - file was NOT modified'
- Specific problem explanation
- Concrete remediation (read file, retry with correct params)

This addresses the issue where agents continue after file edit failures
by making failures more explicit upfront (tool descriptions) and providing
targeted recovery guidance (note field) separate from user-facing errors.

_Generated with `cmux`_
- Add NOTE_READ_FILE_RETRY, NOTE_READ_FILE_FIRST_RETRY, NOTE_READ_FILE_AGAIN_RETRY constants
- Add TOOL_EDIT_WARNING constant for tool descriptions
- Update all usages to reference constants (7 locations)
- Eliminates string duplication across tool definitions and error handling
@ammario ammario added this pull request to the merge queue Oct 29, 2025
Merged via the queue into main with commit 31a3c6a Oct 29, 2025
18 of 19 checks passed
@ammario ammario deleted the fix-edit branch October 29, 2025 18:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants