Skip to content

fix(tools): treat no-op edits and identical writes as terminal tool-loop failures #96983

Description

@liuhaiyang14

Summary

No-op file mutations should be treated as terminal tool-loop failures in agent execution, rather than as successful mutations or recoverable tool errors.

Two recurring cases:

  1. write is called with content identical to the existing file content.
  2. Edit/patch tools are called with identical old/new text, or return a result like No changes made.

In agent loops, these can be interpreted as progress or a recoverable failure, causing repeated identical write/edit attempts.

Expected behavior

  • If write can cheaply precheck that the target file already contains identical content, it should stop before overwriting and return/throw a terminal no-op result.
  • If an edit request has identical old/new text, it should be blocked before execution as a no-op.
  • If an edit tool returns a canonical no-op result such as No changes made, the wrapper should classify it as terminal rather than allowing the agent to retry the same edit indefinitely.
  • Real content changes and new file creation should continue to work normally.

Suggested implementation direction

There are a few possible API shapes. The important semantic boundary is:

  • no-op file mutation is not a successful mutation;
  • no-op file mutation is also not a normal transient/retryable tool failure;
  • it should be terminal for the current tool-loop, with a machine-readable reason such as no-op-write or no-op-edit.

If the current tool runtime already has a terminal tool-loop error type, this could use that. Otherwise, adding a structured denied reason would make this easier to test and easier for frontends to display.

Minimal tests

  • write to an existing file with identical content does not rewrite the file and returns a terminal no-op reason.
  • write with different content still succeeds.
  • write creating a new file still succeeds.
  • edit request with identical old/new text is blocked before execution.
  • edit result containing canonical No changes made is classified as terminal.
  • existing loop detection behavior for genuinely repeated non-noop tools remains unchanged.

Compatibility note

Some callers may currently rely on same-content write being idempotent success. If so, it may be useful to scope this behavior to agent tool-loop execution rather than lower-level file APIs, or to expose a compatibility flag. The key bug is allowing an LLM-controlled tool loop to repeatedly perform or retry no-op mutations as if progress is being made.

Metadata

Metadata

Assignees

No one assigned

    Labels

    P2Normal backlog priority with limited blast radius.clawsweeper:fix-shape-clearClawSweeper found a clear likely implementation shape for this issue.clawsweeper:queueable-fixClawSweeper marked this issue as an existing queue_fix_pr work candidate.clawsweeper:source-reproClawSweeper found a high-confidence source-level issue reproduction.impact:crash-loopCrash, hang, restart loop, or process-level availability failure.impact:session-stateSession, memory, transcript, context, or agent state can drift or corrupt.issue-rating: 🦞 diamond lobsterVery strong issue quality with high-confidence source-level or clear reproduction.no-staleExclude from stale automation

    Type

    No type

    Fields

    Priority

    None yet

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions