Skip to content

Cleanup and --list-sessions race each other #27273

@jpmartins98

Description

@jpmartins98

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

Client Information

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                                                                                                                                          │
│                                                                                                                                                                                                                                                                                 │
╰─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯

Login information

Signed in with Google

Anything else we need to know?

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    area/coreIssues related to User Interface, OS Support, Core Functionalityeffort/medium2-3 days: UI state, async flow, cross-component refactorskind/bugpriority/p2Important but can be addressed in a future release.status/bot-triaged

    Type

    No fields configured for Bug.

    Projects

    Status
    No status

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions