# action_log: Fix race condition when committing changes \(\#53884\) · gitcafe/zed

[View on GitCafe](https://git.cafe/gitcafe/zed/commit/dae1b20289bd578ef48145ed3aca4d4bbd65f5c4)

Repository: [gitcafe/zed](https://git.cafe/gitcafe/zed)

Visibility: public

Requested revision: dae1b20289bd578ef48145ed3aca4d4bbd65f5c4

Requested commit: dae1b20289bd578ef48145ed3aca4d4bbd65f5c4

Commit: dae1b20289bd578ef48145ed3aca4d4bbd65f5c4

Tree: f79c938528134b5e54df470e6eacaddc6727f0af

Author: Bennet Bo Fenner

Committer: GitHub

## Message

```
action_log: Fix race condition when committing changes (#53884)

Sometimes the action log would not auto-accept agent edits when
commiting.

Gpt-5.4 identified this race condition:

This fixes a race where `keep_committed_edits` could run after
`head_commit` changed but before the new git base text had been applied,
leaving committed agent edits marked as unreviewed; `ActionLog` now
waits for an explicit `BufferDiffEvent::BaseTextChanged` instead of
inferring readiness from generic `DiffChanged` activity, so it only
accepts edits after the diff base itself is actually updated.

- `ReloadGitState` updates `head_commit` before `ReloadBufferDiffBases`
finishes loading and applying the new HEAD text.
- In that gap, an unrelated `DiffChanged` can fire from a normal diff
recalculation.
- The old logic treated that event as the commit signal and ran
`keep_committed_edits` too early.
- `keep_committed_edits` then read stale diff base text, so it failed to
match the committed agent edits.
- When the real base-text update arrived later, the HEAD had already
been overwritten (`old_head`), and the edits stayed unreviewed.

Self-Review Checklist:

- [x] I've reviewed my own diff for quality, security, and reliability
- [x] Unsafe blocks (if any) have justifying comments
- [x] The content is consistent with the [UI/UX
checklist](https://github.com/zed-industries/zed/blob/main/CONTRIBUTING.md#uiux-checklist)
- [x] Tests cover the new/changed behavior
- [x] Performance impact has been considered and is acceptable

Closes #ISSUE

Release Notes:

- Fixed an issue where committing agent written code would sometimes not
mark edits as accepted
```

## Parents

- [bbf087756c51aa1d22cbc08148b6506b06ca7b30](https://git.cafe/gitcafe/zed/commit/bbf087756c51aa1d22cbc08148b6506b06ca7b30?format=markdown)

[Source at this commit](https://git.cafe/gitcafe/zed/tree/dae1b20289bd578ef48145ed3aca4d4bbd65f5c4?format=markdown)
