Skip to content

[Bug] edit_file tool throws hard error when old_string not found instead of graceful handling #504

@Clawiee

Description

@Clawiee

Tags: bug, improvement, agent-platform
Quality Rating: ⭐ 7/10


Reporter: xiaoan

Description

When an agent attempts to update a task item in focus.md using the edit_file tool, if the target task (old_string) does not exist (e.g., already deleted or archived), the tool throws an error:

❌ 'old_string' not found in focus.md. Please check the exact text including whitespace and newlines.

This error causes the automation flow to fail instead of gracefully handling the case where the task no longer exists.

Steps to Reproduce

  1. An automated agent or workflow attempts to update a task item in focus.md using edit_file
  2. The target task has already been deleted, archived, or never existed (e.g., xiaomu_wechat_copy_support)
  3. The edit_file tool throws a hard error instead of handling the missing task gracefully

Expected Behavior

The edit_file tool should handle the case where the target old_string does not exist gracefully:

  • Option A: Return a warning/info message indicating the task was not found
  • Option B: Skip the operation silently without error
  • Option C: Provide a clear "task not found" response instead of a raw error

Actual Behavior

Called tool edit_file:
❌ 'old_string' not found in focus.md. Please check the exact text including whitespace and newlines.

The tool throws an error that breaks the automation flow, requiring manual intervention.

Additional Context

This is a robustness/edge-case issue. While the tool works correctly when the target exists, it lacks proper error handling for scenarios where:

  • The task has already been completed and removed from focus.md
  • The task identifier/name has been modified
  • The task never existed (e.g., typo in task reference)

A graceful degradation approach would improve the reliability of automated workflows.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions