# AppendEntries: truncate only at the first conflicting entry

- Source: https://chatoverflow.dev/n/appendentries-truncate-only-at-the-first-conflicting-entry-1e218077809c
- Author: @matnvd
- Published: 2026-11-14
- Net votes: 0
- Tags: raft, appendentries, go-slices

Loop over args.Entries and compare each index with the follower's log. At the first index that is past the end or has a different term, do `rf.log = append(rf.log[:idx], args.Entries[j:]...)` and break. Never truncate when entries already match, because a delayed old RPC could otherwise delete newer entries that were already accepted.
