Agent Mode Intermittently Fails to Apply Code Changes

Agent Mode Intermittently Fails to Apply Code Changes

:lady_beetle: Bug Description

When using Agent Mode (specifically with Gemini 2.5 Pro Max with thinking), I’m experiencing an intermittent issue where code changes sometimes fail to apply properly. The agent acknowledges this failure with messages like “It seems the edit wasn’t applied again” or “Reapply failed as well,” and then attempts to retry or manually specify the edit.

This appears to be similar to an issue reported back in February 18, 2025 (~3 months ago).

Behavior Patterns

I’ve noticed several patterns:

  1. Complete failure to apply - Sometimes changes aren’t applied at all

  2. Unrecognized success - Sometimes the code change is actually made, but the agent fails to recognize this and suggests manual intervention

  3. Partial application - The agent makes smaller incorrect changes or tries to merge code inappropriately, leading to errors like “Table is not defined”

:counterclockwise_arrows_button: Reproduction Steps

Unfortunately, I haven’t identified a consistent reproduction pattern. The issue occurs randomly during coding sessions in agent mode. However, I’ve noticed:

  • It seems to happen more frequently with larger code blocks or complex replacements

  • If I proactively click the “apply” button as the agent is working (rather than letting the agent handle it automatically), changes seem more likely to be recognized

:prohibited: Impact

While this doesn’t completely prevent me from using Cursor, it does hinder productivity as I need to manually verify changes, perform manual interventions, or restart chats when the agent gets stuck in a loop of failed applications.

:laptop: System Information

  • Operating System: Windows 10

  • Cursor Version: 0.49.6 (user setup)

  • AI Model: Using Gemini 2.5 Pro Max with thinking enabled in Agent Mode

:camera: Screenshots

I’ve attached several screenshots showing the error messages and behavior patterns.

:information_source: Additional Notes

Overall, Gemini 2.5 Pro Max is doing a great job with coding - most code changes work correctly. This issue appears to be with Cursor’s ability to reliably apply and detect changes rather than with the AI model’s suggestions themselves.

I checked the developer console logs and found the following error patterns that seem relevant:

  1. Numerous instances of: InlineDiffService#addLine: line contains newline characters, which is not supported

  2. File path related errors: The "path" argument must be of type string. Received type undefined

  3. Model access issues: Could not retrieve model lines for diff calculation for URI: [file paths]

These suggest the apply model may be struggling with code blocks that contain newline characters or with certain file path handling, which could explain why large code block replacements are particularly problematic.

Cursor_nsMP3TMoHT

6 Likes

I hate to be the guy to suggest this, but I had the same thing and restarting Cursor fixed it lol.

I’ve been experiencing the same behavior for the last 36 hours, both with Sonnet 3.7 and Gemini 2.5 pro, and even with their enhanced versions.

1 Like

Same here, it just randomly stops the current task and needs to be applied manually.

I do that a bunch and sometimes it fixes it, but then there’s always a point where it doesn’t

i can not apply all the time,why they can’t fix this

Restart isn’t fixing it for me. An “agent” should be able to take actions like writing code, so this is definitely a bug.

Getting a lot of these lately as well.

image

Same for me.