Skip to content

Suppress diff exceptions#167

Open
AlexandrSuhinin wants to merge 3 commits into
mainfrom
suhinin/suppres-diff-exceptions
Open

Suppress diff exceptions#167
AlexandrSuhinin wants to merge 3 commits into
mainfrom
suhinin/suppres-diff-exceptions

Conversation

@AlexandrSuhinin
Copy link
Copy Markdown
Collaborator

No description provided.

@AlexandrSuhinin AlexandrSuhinin requested a review from ishulgin June 1, 2026 11:41
@AlexandrSuhinin AlexandrSuhinin changed the title Suppres diff exceptions Suppress diff exceptions Jun 1, 2026
_meta: {
kind: "delete",
}
try {
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Looks like unified diff handling for add/delete are redundant - see fn format_file_change_diff(change: &FileChange) -> String { https://github.com/openai/codex/blob/67b805fc111706aca5b32d465c94d95659bab6aa/codex-rs/app-server-protocol/src/protocol/item_builders.rs#L302

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

I'm still not sure that it never leaks via content. We have explicit commits and test for add/delete recovery. I tried to avoid any semantic change here and suggest putting this cleanup out of the scope of this PR.

* Removes synthetic "Moved to" from the end.
*/
function recoverCorruptedDiff(diff: string): string {
return diff.replace(/\nMoved to: .*$/, "");
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

It actually adds 2 \n

type: "diff",
oldText: oldContent,
newText: newContent,
path: change.path,
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

What if file was actually moved? Don't we want to use PatchChangeKind#moved_path?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Actually I think that it's impossible to express move in a single diff event. We probably need to split it into delete + add pair.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

image

Confirmed
image

}

async function createUpdateFileContent(change: FileUpdateChange): Promise<ToolCallContent | null> {
const oldContent = await readFile(change.path, { encoding: "utf8" }).catch(() => null);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I think I'm seeing an error here where, when running the agent on bypass permissions, the edit is already applied to the file when reading the file here, so the applyPatch fails and the "Editing files" ACP tool call is sent with empty content.

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