Skip to content

Bug: --list-sessions never marks the current session, so --delete-session can delete it #29133

Description

@CodewMilan

What happened?

--list-sessions never tags the active session as current, so the delete guard never fires and --delete-session can remove the live session.
The interactive Session Browser does this correctly. The CLI path does not.
SessionBrowser passes the active session ID:

// packages/cli/src/ui/components/SessionBrowser.tsx
const sessionData = await getSessionFiles(
  chatsDir,
  config.getSessionId(),
);

However, SessionSelector.listSessions() does not:

// packages/cli/src/utils/sessionUtils.ts
async listSessions(): Promise<SessionInfo[]> {
  const chatsDir = path.join(this.storage.getProjectTempDir(), 'chats');
  return getSessionFiles(chatsDir);
}

getAllSessionFiles() only sets isCurrentSession when currentSessionId is passed. Without it, every session has isCurrentSession: false.

--list-sessions (packages/cli/src/utils/sessions.ts) therefore never prints , current.

--delete-session uses the same listing, so this guard never fires:
ts if (sessionToDelete.isCurrentSession) { writeToStderr('Cannot delete the current active session.'); return; }
The existing sessions.test.ts mocks isCurrentSession: true, so it does not exercise the real listSessions() path.

There is also a related matching issue in the same area: current-session detection uses:
ts file.includes(currentSessionId.slice(0, 8))
while sessionExists() already uses the correct suffix-based match:
ts endsWith(`-${shortId}.jsonl`)
Using includes() can incorrectly match another session whose filename happens to contain the same short ID.

Reproduction

  1. Start an interactive session so that chat history exists for the project.
  2. In another terminal, from the same project, run:

gemini --list-sessions
]
3. The active session is listed, but no row shows , current.
4. Run:

gemini --delete-session <index-of-that-session>

  1. The active session is deleted instead of printing:

Cannot delete the current active session.

Verified on current main. Platform: macOS.

What did you expect to happen?

--list-sessions should mark the active session with , current, matching the interactive Session Browser.

--delete-session on the current active session should print:

Cannot delete the current active session.

and leave the session file on disk.

listSessions() should pass config.getSessionId() into getSessionFiles(), and isCurrentSession should use the same suffix-based match as sessionExists() (endsWith(\-${shortId}.jsonl`)) rather than includes()`.

### Client information

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

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

```console
> /about
About Gemini CLI                                                                                                     │
│                                                                                                                      │
│ CLI Version                              0.57.0                                                                      │
│ Git Commit                               6b0ae9a6c                                                                   │
│ Model                                    Auto                                                                        │
│ Sandbox                                  no sandbox                                                                  │
│ OS                                       darwin                                                                      │
│ Auth Method                              gemini-api-key

Login information

Not auth-related. The issue is entirely local to session listing/deletion.

Anything else we need to know?

No response
cli version has been mentioned

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    area/coreIssues related to User Interface, OS Support, Core Functionalityeffort/small1 day or less: trivial logic, UI adjustments, docskind/bugpriority/p2Important but can be addressed in a future release.status/bot-triagedstatus/need-information

    Type

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions