Skip to content

fix: preserve exact turn diffs after partial apply_patch failures#21518

Merged
jif-oai merged 3 commits intomainfrom
jif/follow-up-diff
May 7, 2026
Merged

fix: preserve exact turn diffs after partial apply_patch failures#21518
jif-oai merged 3 commits intomainfrom
jif/follow-up-diff

Conversation

@jif-oai
Copy link
Copy Markdown
Collaborator

@jif-oai jif-oai commented May 7, 2026

Why

Follow-up to #21180: turn diffs are operation-backed now, but a failed apply_patch can still leave exact filesystem mutations behind. For example, a move can write the destination file before failing to remove the source. Treating the whole call as unknowable then drops a change that Codex actually knows happened, so the emitted turn diff can drift from the workspace.

What changed

  • apply-patch now returns ApplyPatchFailure with the exact committed prefix accumulated before an error. If a write failure may already have mutated the target, the delta is marked inexact instead of being reused blindly.
  • Move handling now records the destination write before attempting source removal, so a partially failed move can still report the destination file that definitely landed (code).
  • ApplyPatchRuntime now accumulates committed deltas across attempts and forwards them even when the visible tool result is failed or sandbox-denied (runtime path, event path).
  • TurnDiffTracker now consumes committed exact deltas rather than only fully successful patches; exact-empty failures leave the aggregate unchanged, while inexact deltas still invalidate it.

Verification

@jif-oai jif-oai requested a review from a team as a code owner May 7, 2026 09:35
@jif-oai
Copy link
Copy Markdown
Collaborator Author

jif-oai commented May 7, 2026

@codex review

@jif-oai jif-oai changed the title feat: apply patch diff follow-up fix: preserve exact turn diffs after partial apply_patch failures May 7, 2026
Copy link
Copy Markdown
Contributor

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: f55724e027

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread codex-rs/core/src/tools/events.rs
jif-oai and others added 2 commits May 7, 2026 11:13
Co-authored-by: Codex <noreply@openai.com>
Co-authored-by: Codex <noreply@openai.com>
@jif-oai
Copy link
Copy Markdown
Collaborator Author

jif-oai commented May 7, 2026

@codex review

@chatgpt-codex-connector
Copy link
Copy Markdown
Contributor

Codex Review: Didn't find any major issues. Can't wait for the next one!

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Copy link
Copy Markdown
Contributor

@fcoury-oai fcoury-oai left a comment

Choose a reason for hiding this comment

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

I manually tested the happy path by creating a workspace where apply_patch could write the move destination but fail removing the locked source.

The file-change item failed, the locked file remained unchanged, but the destination file wwas updated with the proper contents.

It also still streamed a turn diff containing the committed destination change as expected.

Code looks good, approved! 👍

@jif-oai jif-oai merged commit 9b6c6f7 into main May 7, 2026
37 of 38 checks passed
@jif-oai jif-oai deleted the jif/follow-up-diff branch May 7, 2026 16:05
@github-actions github-actions Bot locked and limited conversation to collaborators May 7, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants