Skip to content

apply_patch grammar accepts empty updates that the runtime parser rejects #4468

Description

@22373448

The custom apply_patch grammar allows an Update File operation containing only a rename:

# src/agents/sandbox/capabilities/tools/apply_patch_tool.py
update_hunk: "*** Update File: " filename LF change_move? change?

Because change is optional, the tool grammar tells the LLM that a move-only update is valid:

*** Begin Patch
*** Update File: foo.py
*** Move to: bar.py
*** End Patch

However, _parse_update_file() rejects it because no diff lines are present:

# src/agents/sandbox/capabilities/tools/apply_patch_tool.py
if not diff_lines:
    raise ValueError(f"Update File patch for {path} must include a hunk")

This creates a grammar/runtime contract mismatch for a legitimate file operation and wastes a tool call.

Note: This issue was identified by an automated testing tool for academic research and manually verified. If you have any concerns about this type of reporting, please let me know, and I will adjust my workflow accordingly.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions