fix: pre-seed ~/.gemini/projects.json to prevent ENOENT from concurrent ProjectRegistry saves#483
Closed
michalszelagsonos wants to merge 2 commits intogoogle-github-actions:mainfrom
Closed
Conversation
Gemini CLI 0.33.0 writes a user-level project registry at ~/.gemini/projects.json during cleanup. The atomic write fails with ENOENT if ~/.gemini/ doesn't exist. Add mkdir -p before the first gemini command to ensure the directory is present.
… CLI The previous mkdir-only fix was insufficient. Gemini CLI 0.33.0 runs cleanupCheckpoints() and cleanupToolOutputFiles() concurrently via Promise.all. Both initialize a ProjectRegistry that writes to the same projects.json.tmp file. When the registry file doesn't exist, both call save() without locking, causing a race where one rename succeeds and the other gets ENOENT because the tmp file was already renamed away. Pre-seeding projects.json with valid empty data causes both concurrent callers to skip the unguarded initial save and go straight to proper-lockfile's lock(), which properly serializes access.
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
cleanupCheckpoints()andcleanupToolOutputFiles()concurrently viaPromise.allduring startup (includinggemini --version). Both create separateProjectRegistryinstances that target the same~/.gemini/projects.jsonfile.save()without locking (theproper-lockfilelock ingetShortId()only engages after the initial save). Both write to the sameprojects.json.tmppath. Onerename()succeeds, the other getsENOENTbecause the tmp file was already renamed away by the first.~/.gemini/and pre-seedprojects.jsonwith valid empty data ({"projects":{}}) before the firstgeminicommand. This causes both concurrent callers to skip the unguarded initialsave()and go straight toproper-lockfile'slock(), which properly serializes access. This workaround can be removed once the upstream fix lands.Test plan
Failed to save project registryENOENT error no longer appears