google-gemini/gemini-cli · error

Failed to load session ${sessionInfo.id}: ${error instanceof

Error message

Failed to load session ${sessionInfo.id}: ${error instanceof Error ? error.message : 'Unknown error'}

What it means

Thrown by the catch block of selectSession wrapping any error that occurs while loading session data (including the 'Failed to load session data' error from 154). It annotates the failure with sessionInfo.id so the user knows which session failed. The underlying message is preserved or 'Unknown error' if it was not an Error instance.

Source

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

      const sessionData = await loadConversationRecord(sessionPath);
      if (!sessionData) {
        throw new Error('Failed to load session data');
      }
      const normalizedSessionData = {
        ...sessionData,
        startTime: sessionData.startTime || sessionInfo.startTime,
        lastUpdated: sessionData.lastUpdated || sessionInfo.lastUpdated,
      };

      const displayInfo = `Session ${sessionInfo.index}: ${sessionInfo.firstUserMessage} (${sessionInfo.messageCount} messages, ${formatRelativeTime(sessionInfo.lastUpdated)})`;

      return {
        sessionPath,
        sessionData: normalizedSessionData,
        displayInfo,
      };
    } catch (error) {
      throw new Error(
        `Failed to load session ${sessionInfo.id}: ${error instanceof Error ? error.message : 'Unknown error'}`,
      );
    }
  }
}

/**
 * Converts session/conversation data into UI history format.
 */
export function convertSessionToHistoryFormats(
  messages: ConversationRecord['messages'],
): {
  uiHistory: HistoryItemWithoutId[];
} {
  const uiHistory: HistoryItemWithoutId[] = [];

  for (const msg of messages) {
    // Add thoughts if present

View on GitHub (pinned to 5024443c72)

Solutions

  1. Use the embedded session id to locate and inspect the file under <projectTempDir>/chats.
  2. Delete or restore the corrupt session file, then retry.
  3. If caused by a CLI version change, check release notes for session-format migrations.
  4. Fall back to starting a new session if the data is unrecoverable.
Defensive patterns

Strategy: try-catch

Try / catch

try {
  result = await manager.selectSession(info);
} catch (e) {
  if (/Failed to load session/.test(e.message)) {
    // offer to archive/delete the bad session and continue
  } else throw e;
}

Prevention

When it happens

Trigger: Any throw inside selectSession's try block — most commonly the inner 'Failed to load session data' (154), but also loadConversationRecord throwing, or property access on undefined normalizedSessionData.

Common situations: Same root causes as 154 plus: schema mismatch where required fields (startTime/lastUpdated) are missing and downstream code throws. Version mismatch between the CLI that wrote the session and the one reading it.

Related errors


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