fix(cli): skip background session cleanup when listing sessions#27906
Open
i-anubhav-anand wants to merge 1 commit into
Open
fix(cli): skip background session cleanup when listing sessions#27906i-anubhav-anand wants to merge 1 commit into
i-anubhav-anand wants to merge 1 commit into
Conversation
On startup, cleanupExpiredSessions() is launched as an unawaited background task. A few lines later --list-sessions reads the same session directory. Cleanup can delete files while listSessions is scanning them, so a file can exist during readdir and then disappear before readFile — making the listed result depend on timing rather than a stable snapshot. Skip the background cleanup when the run only reads or mutates the session list (--list-sessions / --delete-session). The list command then sees a stable directory, and cleanup still runs on normal startups. Fixes google-gemini#27273
|
📊 PR Size: size/M
|
Contributor
|
Warning Gemini encountered an error creating the summary. You can try again by commenting |
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
Fixes #27273.
On startup,
cleanupExpiredSessions()is launched as an unawaited background task. A few lines later,--list-sessionsreads the same session directory vialistSessions(). Because cleanup runs concurrently, it can delete files while listing is scanning them: a file can exist duringreaddirand then disappear beforereadFile, so the list shown to the user depends on timing rather than a stable snapshot.Fix
Skip the background cleanup when the run only reads or mutates the session list (
--list-sessions/--delete-session). The list/delete commands then operate on a stable directory, and cleanup still runs as before on normal interactive/non-interactive startups.This is the minimal version of the issue author's suggested options (skip cleanup for
--list-sessions), with no added startup latency.Testing
gemini_cleanup.test.tsxasserting that the cleanup task is not invoked when--list-sessionsis set (andlistSessionsstill runs). Verified it fails before this change and passes after.npx vitest run src/gemini_cleanup.test.tsx→ 4 passed (1 pre-existing skip).eslint(touched files) andnpm run typecheck(packages/cli) clean.