A retry can deliver a message twice
Level 3 makes the network unreliable. The write-up's follow-up asks what happens when a machine crashes or a message fails, and suggests retries with a request id and cached answers, so nothing is counted twice (1 report).
Here is why retries bring repeats. A machine asks a child and waits. Nothing comes back for a while. Was the ask lost, or the answer, or is the child just slow? The machine can't tell. The only safe move is to ask again. If the child was only slow, it now gets the ask twice, and the parent may get two answers. Networks that retry deliver at least once, never exactly once.
So a repeat must change nothing. That property has a name, idempotent: doing it twice has the same effect as doing it once.
A dict of answers keyed by child is nearly idempotent. A second answer from 3 writes the same value under the same key, but it also runs finish_if_done again, and that sends a second answer up the tree. So ignore an answer from a child that's already in the dict: then a repeat changes nothing. A counter can't even tell the copies apart:
| After these answers | replies dict | counter waiting, total |
|---|---|---|
| 3: 1 | {3: 1}, waiting for 4 | 1 left, 2 |
| 3: 1 again | {3: 1}, waiting for 4 | 0 left, 3, so it answers |
| 4: 1 | {3: 1, 4: 1}, answers 3 | ignored |
The counter answers 3, which happens to be right here, but too early and for the wrong reason: it counted 3 twice and never heard from 4. On a deeper tree the numbers come out wrong.
The editor holds a level 1 Machine that keeps self.waiting and self.total instead of a dict. Run it to see machine 1 answer before 4 has said anything, then change how Machine keeps its answers so a repeat changes nothing.