gemini-cli - 💡(How to fix) Fix Cleanup and --list-sessions race each other [1 participants]

Official PRs (…)
ON THIS PAGE

Recommended Tools

×6

Utilities matched from this issue’s tags and category — try them while you read without losing context.

GitHub issue graph ai analysis

Paste a GitHub issue URL. We fetch that issue, discover linked issues from bodies/comments/timeline, collect linked pull requests, and produce a structured English report.

The report is written in English Markdown for sharing and archival.

Helpful · Quick feedback

Loading…
GitHub stats
google-gemini/gemini-cli#27273Fetched 2026-05-20 03:59:38
View on GitHub
Comments
0
Participants
1
Timeline
2
Reactions
0
Participants
Timeline (top)
labeled ×2

Error Message

debugLogger.error('Failed to cleanup expired sessions:', e);

Root Cause

Listing sessions should produce a stable result. If cleanup must run on startup, finish it before listing starts. If startup delay is a concern, skip cleanup for --list-sessions or make listing use a stable snapshot. The user should not see sessions randomly vanish because two internal tasks touched the same files at once.

Code Example

cleanupExpiredSessions(config, settings.merged).catch((e) => {
    debugLogger.error('Failed to cleanup expired sessions:', e);
  });

---

if (config.getListSessions()) {
    // ...
    await listSessions(config);
  }

---

╭─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╮
│                                                                                                                                                                                                                                                                                 │
About Gemini CLI│                                                                                                                                                                                                                                                                                 │
CLI Version                                                                                    0.42.0Git Commit                                                                                     68e2196d5                                                                                                                                                                        │
Model                                                                                          Auto (Gemini 3)Sandbox                                                                                        no sandbox                                                                                                                                                                       │
OS                                                                                             linux                                                                                                                                                                            │
Auth Method                                                                                    Signed in with GoogleTier                                                                                           Gemini Code Assist in Google One AI Pro│                                                                                                                                                                                                                                                                                 │
╰─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯
RAW_BUFFERClick to expand / collapse

What happened?

Startup launches cleanupExpiredSessions() as a background task. It is not awaited. A few lines later, the CLI handles --list-sessions and starts reading the same session directory. Cleanup can delete files while listing is scanning them. A file can exist during readdir, then disappear before readFile. The list shown to the user can therefore depend on timing rather than a stable snapshot.

packages/cli/src/gemini.tsx:667

  cleanupExpiredSessions(config, settings.merged).catch((e) => {
    debugLogger.error('Failed to cleanup expired sessions:', e);
  });

packages/cli/src/gemini.tsx:681

  if (config.getListSessions()) {
    // ...
    await listSessions(config);
  }

What did you expect to happen?

Listing sessions should produce a stable result. If cleanup must run on startup, finish it before listing starts. If startup delay is a concern, skip cleanup for --list-sessions or make listing use a stable snapshot. The user should not see sessions randomly vanish because two internal tasks touched the same files at once.

Client information

<details> <summary>Client Information</summary>

Run gemini to enter the interactive CLI, then run the /about command.

╭─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╮
│                                                                                                                                                                                                                                                                                 │
│ About Gemini CLI                                                                                                                                                                                                                                                                │
│                                                                                                                                                                                                                                                                                 │
│ CLI Version                                                                                    0.42.0                                                                                                                                                                           │
│ Git Commit                                                                                     68e2196d5                                                                                                                                                                        │
│ Model                                                                                          Auto (Gemini 3)                                                                                                                                                                  │
│ Sandbox                                                                                        no sandbox                                                                                                                                                                       │
│ OS                                                                                             linux                                                                                                                                                                            │
│ Auth Method                                                                                    Signed in with Google                                                                                                                              │
│ Tier                                                                                           Gemini Code Assist in Google One AI Pro                                                                                                                                          │
│                                                                                                                                                                                                                                                                                 │
╰─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯
</details>

Login information

Signed in with Google

Anything else we need to know?

No response

Vote matrix · Quick signals

Works
Did the solution work? Tap to confirm.
Easy Fix
Was it a quick fix?
Time Saver
Did it save you time?
Blocking
Was it severely blocking?
Common Issue
Are others likely hitting this too?
Flaky / Intermittent
Is it intermittent?
Verified / Reproducible
Can you reproduce it reliably?
Loading…

Still need to ship something?

×6

Another batch ranked right after the header list — different links, same matching logic.

Back to top recommendations

TRENDING

gemini-cli - 💡(How to fix) Fix Cleanup and --list-sessions race each other [1 participants]