gemini-cli - ✅(Solved) Fix Metadata-only sessions can be deleted immediately, regardless of age [1 pull requests, 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#27270Fetched 2026-05-20 03:59:43
View on GitHub
Comments
0
Participants
1
Timeline
3
Reactions
0
Participants
Timeline (top)
labeled ×2cross-referenced ×1

Root Cause

The cleanup code treats every sessionInfo === null file as a corrupted file. That includes metadata-only sessions, because listing already converted them to sessionInfo: null. These files are pushed into sessionsToDelete before age-based retention is checked. A session created seconds ago can therefore be selected for deletion if it is from a previous run and has no user/gemini messages. minRetention does not protect this path. This is especially bad because /clear followed by /quit creates exactly this kind of file.

Fix Action

Fixed

PR fix notes

PR #27287: fix(cli): harmonize empty session lifecycle

Description (problem / solution / changelog)

Summary

This PR harmonizes how the Gemini CLI handles "empty" (metadata-only) sessions, fixing several interrelated lifecycle and persistence bugs. Empty sessions are now treated as valid but explicitly flagged, preventing them from being falsely advertised for resumption or prematurely deleted.

Details

Previously, when a user started the CLI and immediately quit (e.g., after /clear), a metadata-only session file was created. The CLI's listing parser treated these as corrupted (sessionInfo: null), which caused a cascade of issues:

  1. Immediate Deletion: The startup cleanup task aggressively deleted them because they were considered corrupt, ignoring retention policies.
  2. Invisible to Resume: They were filtered out of --list-sessions and --resume.
  3. Contradictory Errors: --session-id checked raw file existence, while --resume used the filtered list, causing the CLI to tell users to resume a session that couldn't be resumed.
  4. False Promises: The exit summary blindly printed gemini --resume <id> even if no conversation occurred.

This PR fixes this by:

  • Adding an isEmpty: boolean flag to SessionInfo.
  • Allowing empty sessions to parse successfully so they fall under normal age-based retention policies.
  • Hiding the resume command in the exit summary if the session is empty.
  • Updating --session-id conflict detection to report that the ID exists but is empty, rather than blindly redirecting to --resume.

Related Issues

Fixes #27269 Fixes #27270 Fixes #27271 Fixes #27282

How to Validate

  1. Run the CLI and immediately exit using /quit.
  2. Observe the exit screen: It should say "No conversation recorded." instead of providing a --resume command.
  3. Run gemini --list-sessions.
  4. Observe the session list: The session should appear in the list with an (Empty) tag.
  5. Attempt to start a new session with that same ID: gemini --session-id <the-id>.
  6. The CLI should output a specific error: Session ID "<the-id>" already exists but is empty. Please provide a different ID or delete the old session.

Pre-Merge Checklist

  • Updated relevant documentation and README (if needed)
  • Added/updated tests (if needed)
  • Noted breaking changes (if any)
  • Validated on required platforms/methods:
    • MacOS
      • npm run
      • npx
      • Docker
      • Podman
      • Seatbelt
    • Windows
      • npm run
      • npx
      • Docker
    • Linux
      • npm run
      • npx
      • Docker

Changed files

  • docs/cli/session-management.md (modified, +6/-1)
  • packages/cli/src/gemini.test.tsx (modified, +3/-1)
  • packages/cli/src/gemini.tsx (modified, +13/-5)
  • packages/cli/src/ui/components/SessionBrowser.test.tsx (modified, +4/-0)
  • packages/cli/src/ui/components/SessionBrowser/utils.test.ts (modified, +1/-0)
  • packages/cli/src/ui/components/SessionSummaryDisplay.tsx (modified, +10/-5)
  • packages/cli/src/utils/sessionUtils.test.ts (modified, +14/-7)
  • packages/cli/src/utils/sessionUtils.ts (modified, +13/-8)
  • packages/cli/src/utils/sessions.test.ts (modified, +22/-0)
  • packages/cli/src/utils/sessions.ts (modified, +2/-1)
  • packages/core/src/services/chatRecordingService.test.ts (modified, +121/-0)

Code Example

// All corrupted files should be deleted
  sessionsToDelete.push(
    ...allFiles.filter((entry) => entry.sessionInfo === null),
  );

---

╭─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╮
│                                                                                                                                                                                                                                                                                 │
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?

The cleanup code treats every sessionInfo === null file as a corrupted file. That includes metadata-only sessions, because listing already converted them to sessionInfo: null. These files are pushed into sessionsToDelete before age-based retention is checked. A session created seconds ago can therefore be selected for deletion if it is from a previous run and has no user/gemini messages. minRetention does not protect this path. This is especially bad because /clear followed by /quit creates exactly this kind of file.

packages/cli/src/utils/sessionCleanup.ts:308

  // All corrupted files should be deleted
  sessionsToDelete.push(
    ...allFiles.filter((entry) => entry.sessionInfo === null),
  );

What did you expect to happen?

A recent file with a valid sessionId should not be deleted just because no prompt was sent. The cleanup should distinguish truly corrupted files from empty-but-valid sessions. If the file is younger than a safety window, it should be skipped or quarantined. If it is deleted, the user should get visible feedback. minRetention should apply here too, not only to age-based deletion.

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

No response

Anything else we need to know?

Signed in with Google

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 - ✅(Solved) Fix Metadata-only sessions can be deleted immediately, regardless of age [1 pull requests, 1 participants]