HeadlinesBriefing favicon HeadlinesBriefing.com

Tracking Down Zsh History Data Loss Bug

Hacker News •
×

For years I occasionally found commands missing from my Zsh history file (~/.zsh_history). The file contained only old entries with years of newer commands gone. No visible corruption, line count varied. Unclear if Zsh, other programs, or multiple Zsh processes caused it.

My config: HISTSIZE=4000, SAVEHIST=10000000, INC_APPEND_HISTORY, no SHARE_HISTORY. Shells stream commands into shared history. Using inotifywait and fatrace, I saw Zsh reads old history, writes to .zsh_history.new, then renames over old file. But no PID visibility with inotify. fatrace showed PIDs but not data amounts.

bpftrace revealed open syscalls with stack traces. Multiple Zsh processes opening history file concurrently. Ultimately, patching Zsh to crash loudly and analyzing core dump identified the bug. Zsh 5.9.2 (July 12, 2026) includes fix Zsh fix 53454.