Skip to content

Conversation

@dylan-hurd-oai
Copy link
Collaborator

Summary

Right now, if a patch contains 2 @@ context lines in a row, we throw an error. This PR updates apply-patch to support this as a valid patch where subsequent @@ lines increase specificity of the search.

Testing

  • Added unit tests
  • Added an e2e scenario test

@dylan-hurd-oai dylan-hurd-oai changed the title fix(apply-patch) Support repeated @@ lines fix(apply-patch) Support nested @@ context lines Dec 5, 2025
@dylan-hurd-oai dylan-hurd-oai force-pushed the dh--apply-patch-context-fix branch from 45fdf1f to 7e90c32 Compare December 8, 2025 22:45
Copy link
Collaborator

@bolinfest bolinfest left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe some small tweaks, but otherwise LGTM!

@@ -0,0 +1,7 @@
*** Begin Patch
*** Update File: example.py
@@ class BaseClass:
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we use class OtherClass as the target thing since the primary bug that this fixes is the one where the agent wants to update the "second" instance of something in the file (def method() in this case), but inadvertently updates the first due to insufficient context.

// multiple @@ context headers such as:
// @@ class BaseClass:
// @@ def method():
for ctx_line in &chunk.change_context {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we need a test where there are overlapping instances of the context?

For example, if the context were:

@@ A
@@ A
- old

and the file were:

A
A
A
old

I would want to be sure that the failed match for the first two A's doesn't interfere with the match for the second and third A?

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.

3 participants