AppendEntries carries the leader’s term, a previous log index and term, new entries, and information about the committed prefix. A follower first checks that it has the expected entry at the previous index with the expected term. If that check fails, it rejects the request. The leader retries with an earlier matching point or a snapshot when necessary.
Once the preceding entry matches, a conflicting entry and its following suffix can be replaced by the leader’s entries. A follower does not delete extra entries merely because a heartbeat contains no new entries. Actual conflicts drive truncation. With Raft’s rules, an entry with the same index and term has the same preceding history. This log-matching property makes agreement about a later point imply agreement about its prefix.
Repair a conflicting suffix from a verified matching point
Treat each log entry as a position, an entry term, and a command. The election term in an AppendEntries request describes the sender's authority attempt. The entry terms describe when particular entries were first created. A leader in term 8 can legitimately send entries created in terms 5 and 6 while bringing a follower up to date. Copying those entries does not change their terms to 8. Confusing these two uses of term would break both freshness comparisons and the commitment test.
In a separate paper repair case, suppose leader A has entries at indexes 1 through 5 with terms 1, 1, 3, 4, 4. Follower B has terms 1, 1, 2, 2 through index 4. The commands at the first two positions match. A request that claims the previous entry is index 4, term 4 fails at B because B's entry there has term 2. Rejecting protects the assumption that new entries extend the same preceding history.
A can try an earlier point. A request whose previous entry is index 2, term 1 passes. It carries A's entries beginning at index 3. B compares the supplied index-3 entry with its own and finds different entry terms, so it deletes its conflicting suffix beginning there. B then stores A's entries for indexes 3 through 5. The repaired sequence is 1, 1, 3, 4, 4. The request established a matching prefix before replacing the divergent suffix.
The rejected request did not require A to copy all of B's entries or decide which commands looked more reasonable. Raft repairs according to log identity and leader authority, not application preference. If B's term-2 command reserved a seat, the application must not have treated it as final merely because B stored it. A safe implementation applies only committed entries. That boundary is what lets an uncommitted suffix be replaced without retracting a promised committed application result.
Successful repair must become durable before B sends an acknowledgment that the leader may count as durable replication. A reply based only on memory would let A rely on copies that disappear during a covered crash. The receiver must also respect the sender's request term. An obsolete leader cannot repair a follower that has already advanced to a higher term by presenting an attractive matching prefix. Authority checks and prefix checks answer different questions, and both matter.
Log matching is stronger than seeing equal lengths or equal final commands. Under Raft's creation and append rules, equal entry term and index identify the same entry and therefore the same prefix. Two arbitrary files containing a term label do not gain that property by naming it. The reasoning assumes legitimate Raft histories, one elected leader per term, and persistent protocol state. The bounded replication lab from lesson 5 fixes one term and cannot demonstrate this repair process or validate those assumptions across elections.