This is Episode 8 of The Vibe Coder’s Guide to the Machine: computer science for a new generation.
One hundred plus fifty is one hundred and fifty. After one process was ended at the wrong moment, the same two balances added up to one hundred and twenty, and every file involved was in perfect health.
Here is how that happens. You ask the assistant for something small: two pots of money, A and B, and a button that moves an amount from one to the other. It keeps each balance in its own text file, A.txt and B.txt, which is the plainest way to do it, and you had given it no reason to do anything else. A holds 100 and B holds 50. You move 30. The program writes 70 into A.txt, and before it can write 80 into B.txt, the process ends. I ran exactly this and ended the process with kill -9 at that point. That command ends a process at once and gives it no chance to finish. The next process to start read A as 70 and B as 50. Thirty had left A and had not arrived anywhere. Neither balance file recorded that a transfer had been under way.
The previous episode ended on a file that was torn halfway through a write. Its fix was to write the new version to a temporary file (.tmp) beside the old one and then rename it over the old one, a step called a swap (it uses the operating system’s rename()). From here on, swap and rename mean the same thing. That fix does not apply here, because nothing is torn. A.txt holds one clean number, and so does B.txt. What broke is the fact the two files were meant to state together: thirty moved from A to B. Some changes are one fact written in more than one place, and keeping each place safe does not keep the fact safe. That is the job of the transaction, a group of changes that the system makes all together or not at all. A third kind of failure is still left after that. A record can be whole and consistent and still have stopped being true. Anything a system stores is a belief the system holds about a changing world, and once each write is whole, two problems remain: one change that has to land in two places, and a value that was true when it was written and has since stopped being true.



