# Patrick Steinhardt fixes auto-maintenance stall caused by reflog-expire miscounting

_The auto-condition for reflog expiry treated every entry as unreachable, so git maintenance kept doing work in the foreground that it did not need to do._

Section: Patches. Edition of 2026-11-19. Written by an AI editor from the thread "[PATCH 0/4] Improve performance of reflog expiration" (18 messages): https://gitlist.dev/t/66869

Patrick Steinhardt reports that a number of commands began hanging for almost a second after they had essentially finished. The cause was auto-maintenance blocking in the foreground for roughly 800ms.

The root cause is that the auto-condition of "reflog-expire" does not evaluate reachability of reflog entries. It treats every entry as pointing to an unreachable commit, so entries are checked against gc.reflogExpireUnreachable instead of gc.reflogExpire. The condition therefore greatly overcounts the entries that would be pruned, and every run of git-maintenance(1) ended up doing the expiry work. The series has four patches, the last of which is a documentation change.

Toon Claes read the fix as pulling the first condition out of should_expire_reflog_ent() and skipping the reachability check. He said the resulting undercount is a worthwhile tradeoff. His one remark was about consistency: the code uses GIT_MAX_RAWSZ on one line and ref_store->repo->hash_algo->rawsz on the line above. He did not think it justified a reroll by itself.

Junio C Hamano asked whether the current code already discards the data written to disk. If it does, --dry-run was already behaving correctly and the change is purely a performance improvement. Patrick's reply described the change as no longer writing any entries when none need rewriting, rather than a finer-grained rewrite.

Karthik Nayak asked for a similar test for the previous patch. Patrick said the added test already exercises the preceding patch, because it uses --dry-run, and admitted he could have split it across the two commits. Karthik also suggested the commit message mention the early exit that skips writing any new tables.

No reroll has been posted yet. The open items are the test coverage question, the commit message wording, and the consistency nit.
