fix(checkpoints): race-safe stale index lock cleanup via atomic rename - #45883
Closed
Veritas-7 wants to merge 1 commit into
Closed
fix(checkpoints): race-safe stale index lock cleanup via atomic rename#45883Veritas-7 wants to merge 1 commit into
Veritas-7 wants to merge 1 commit into
Conversation
Contributor
|
Verified clean — no issues found. Reviewed the full diff (2 files, +156/−0):
LGTM. |
AIalliAI
added a commit
to AIalliAI/Hermes
that referenced
this pull request
Jun 14, 2026
Use os.rename to take exclusive ownership of a stale checkpoint index lock before removing it, eliminating the TOCTOU race in stat-then-unlink. Adds 5 focused tests covering no-lock, stale removal, recent-lock skip, temp-file cleanup, and atomicity verification.
Veritas-7
force-pushed
the
veritas/checkpoint-stale-lock-racesafe-v2
branch
from
June 14, 2026 11:26
af6624f to
c2adfc4
Compare
AIalliAI
added a commit
to AIalliAI/Hermes
that referenced
this pull request
Jun 14, 2026
4 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
_cleanup_stale_index_lock()which usesos.rename(POSIX-atomic on a single filesystem) to take exclusive ownership of a stale checkpoint index lock before removing it.git add -Ain the checkpoint creation path, preventing a single crashed worker from permanently blocking checkpoints for a project.Problem
When a Hermes worker is killed mid-checkpoint, git's zero-byte
<GIT_INDEX_FILE>.lockcan linger forever. Every subsequent checkpoint for that project fails withUnable to create ...index.lock: File exists.A previous attempt (#45871) used stat-then-unlink with a second stat-compare to narrow the race window. This PR eliminates the race entirely by using
rename-- an atomic operation -- to take ownership of the stale lock before unlinking.Race-safety design
Tests