Patching Zsh to Crash: How I Found the History Truncation Bug
Tracking down a Zsh history data loss bug
For years, Michael Stapelberg occasionally found his Zsh history file truncated to only very old entries. After ruling out inotify and fatrace, he used bpftrace to trace Zsh's file operations, revealing that Zsh was rewriting the history file with fewer lines than expected. To pinpoint the bug, he patched Zsh to crash when writing a truncated history file, then analyzed the core dump. The investigation led to a fix in Zsh 5.9.2. The article details the debugging process and includes appendices on an exported HISTFILE footgun and whether AI can find the bug.
Spoiler: ultimately, patching Zsh to make it crash loudly and analyzing the crash’s core dump was the winning strategy!