A small tagging tool sat beside a static image site: a single-file server on its own port, a grid, a detail view, free-form tags. It had been fine in testing. On its first day of real use the person tagging reported that saves were not sticking. The data file on disk turned out to be corrupt.

Atomic on paper

The save path looked correct. Write to a temporary file, then rename it over the real one, so a crash mid-write never leaves a half-written file. The temporary file had a fixed name. The HTTP server was the threaded variety, which handles each request on its own thread. Two saves arriving close together both opened the same temporary file, both wrote into it, and whichever rename landed second published a mix of the two. The atomic rename protected against crashes and did nothing against concurrency, because the two writers shared the thing the rename was supposed to protect.

The fix had several layers rather than one. Each save gets a unique temporary name. The file is synced to disk before the rename. A re-entrant lock serialises saves inside the process. On startup, a corrupt data file is detected and rebuilt from the last good state instead of crashing the server. The browser side got a serial queue, a retry, a visible saved-or-not indicator, and handling for in-progress input method composition, which had been producing truncated tags like a single syllable where a word was meant.

What was recovered

The corrupt file held the day's real work: 66 entries with their tags. They were recovered from the damaged file. The record does not say whether 66 was everything that had been entered, so whether anything was lost outright is not established. After the fix the tool went on to promote 19 images into seven category axes without incident, which is the only evidence that the new path holds.

No deliberate reproduction was recorded. Nobody fired two concurrent saves at the server to confirm the interleaving before or after the change. The diagnosis rests on reading the code and the shape of the corruption, and the fix rests on the rest of the day going quietly.