google-gemini/gemini-cli · error

Failed to find session

Error message

Failed to find session "${trimmedResumeArg}": ${error instanceof Error ? error.message : String(error)}

What it means

Thrown when resuming a session by identifier and this.findSession(trimmedResumeArg) throws an error that is NOT a SessionError (those are rethrown unchanged). It wraps unexpected/low-level errors (filesystem, JSON parse, permission) with the identifier that was requested for diagnosis.

Solutions

  1. Read the wrapped error message (after the colon) to identify the underlying cause (ENOENT, EACCES, SyntaxError).
  2. Verify the chats directory (storage.getProjectTempDir()/chats) is readable and not corrupted.
  3. If a specific session file is corrupt, remove or restore it, then retry the resume.
  4. If the identifier is wrong, double-check it against the session list (`--list-sessions` or equivalent).
Defensive patterns

Strategy: try-catch

Validate before calling

// Validate the identifier format and chats dir accessibility before resuming.
const fs = require('fs');
const chatsDir = path.join(storage.getProjectTempDir(), 'chats');
fs.accessSync(chatsDir, fs.constants.R_OK);

Try / catch

try {
  selectedSession = await manager.findSession(id);
} catch (e) {
  if (e instanceof SessionError) throw e; // already detailed
  throw new Error(`Failed to find session '${id}': ${e.message}`);
}

Prevention

When it happens

Trigger: findSession throws something other than SessionError — e.g. an FS error reading the chats directory, an unexpected JSON.parse failure, or a permission error. The wrapper at sessionUtils.ts:527 catches and rethrows with context.

Common situations: Chats directory is corrupted or has permission issues. Disk error while listing session files. A bug in findSession producing a non-SessionError. Race where the session file is deleted between listing and reading.

Related errors


AI-assisted analysis of google-gemini/gemini-cli@5024443c72 (2026-08-12). Data as JSON: /api/errors/9d0267c58bd1b16d. Report an issue: GitHub.

Appendix: source

Thrown at packages/cli/src/utils/sessionUtils.ts:527

      }

      // Sort by startTime (oldest first, so newest sessions get highest numbers)
      sessions.sort(
        (a, b) =>
          new Date(a.startTime).getTime() - new Date(b.startTime).getTime(),
      );

      selectedSession = sessions[sessions.length - 1];
    } else {
      try {
        selectedSession = await this.findSession(trimmedResumeArg);
      } catch (error) {
        // SessionError already has detailed messages - just rethrow
        if (error instanceof SessionError) {
          throw error;
        }
        // Wrap unexpected errors with context
        throw new Error(
          `Failed to find session "${trimmedResumeArg}": ${error instanceof Error ? error.message : String(error)}`,
        );
      }
    }

    return this.selectSession(selectedSession);
  }

  /**
   * Loads session data for a selected session.
   */
  private async selectSession(
    sessionInfo: SessionInfo,
  ): Promise<SessionSelectionResult> {
    const chatsDir = path.join(this.storage.getProjectTempDir(), 'chats');
    const sessionPath = path.join(chatsDir, sessionInfo.fileName);

    try {

View on GitHub (pinned to 5024443c72)