{"record":{"id":"a9c35702d524596d","repo":"google-gemini/gemini-cli","slug":"failed-to-load-session-sessioninfo-id-error","errorCode":null,"errorMessage":"Failed to load session ${sessionInfo.id}: ${error instanceof Error ? error.message : 'Unknown error'}","messagePattern":"Failed to load session (.+?): (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"packages/cli/src/utils/sessionUtils.ts","lineNumber":564,"sourceCode":"      const sessionData = await loadConversationRecord(sessionPath);\n      if (!sessionData) {\n        throw new Error('Failed to load session data');\n      }\n      const normalizedSessionData = {\n        ...sessionData,\n        startTime: sessionData.startTime || sessionInfo.startTime,\n        lastUpdated: sessionData.lastUpdated || sessionInfo.lastUpdated,\n      };\n\n      const displayInfo = `Session ${sessionInfo.index}: ${sessionInfo.firstUserMessage} (${sessionInfo.messageCount} messages, ${formatRelativeTime(sessionInfo.lastUpdated)})`;\n\n      return {\n        sessionPath,\n        sessionData: normalizedSessionData,\n        displayInfo,\n      };\n    } catch (error) {\n      throw new Error(\n        `Failed to load session ${sessionInfo.id}: ${error instanceof Error ? error.message : 'Unknown error'}`,\n      );\n    }\n  }\n}\n\n/**\n * Converts session/conversation data into UI history format.\n */\nexport function convertSessionToHistoryFormats(\n  messages: ConversationRecord['messages'],\n): {\n  uiHistory: HistoryItemWithoutId[];\n} {\n  const uiHistory: HistoryItemWithoutId[] = [];\n\n  for (const msg of messages) {\n    // Add thoughts if present","sourceCodeStart":546,"sourceCodeEnd":582,"githubUrl":"https://github.com/google-gemini/gemini-cli/blob/5024443c7217464a66e98f80d73172a26440bd8f/packages/cli/src/utils/sessionUtils.ts#L546-L582","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Use the embedded session id to locate and inspect the file under <projectTempDir>/chats.","Delete or restore the corrupt session file, then retry.","If caused by a CLI version change, check release notes for session-format migrations.","Fall back to starting a new session if the data is unrecoverable."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"try {\n  result = await manager.selectSession(info);\n} catch (e) {\n  if (/Failed to load session/.test(e.message)) {\n    // offer to archive/delete the bad session and continue\n  } else throw e;\n}","preventionTips":["Surface the embedded session id to the user so they can locate the file.","Keep session migrations idempotent and versioned."],"tags":["session","resume","error-wrapping","data-integrity"],"backgroundTag":null,"analyzedSha":"5024443c7217464a66e98f80d73172a26440bd8f","analyzedAt":"2026-08-12T06:01:53.711Z","schemaVersion":2},"datasetVersion":"2026-08-12T13:17:24.610Z"}