{"record":{"id":"827a346417e5af7f","repo":"google-gemini/gemini-cli","slug":"failed-to-load-session-data","errorCode":null,"errorMessage":"Failed to load session data","messagePattern":"Failed to load session data","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"packages/cli/src/utils/sessionUtils.ts","lineNumber":548,"sourceCode":"      }\n    }\n\n    return this.selectSession(selectedSession);\n  }\n\n  /**\n   * Loads session data for a selected session.\n   */\n  private async selectSession(\n    sessionInfo: SessionInfo,\n  ): Promise<SessionSelectionResult> {\n    const chatsDir = path.join(this.storage.getProjectTempDir(), 'chats');\n    const sessionPath = path.join(chatsDir, sessionInfo.fileName);\n\n    try {\n      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      );","sourceCodeStart":530,"sourceCodeEnd":566,"githubUrl":"https://github.com/google-gemini/gemini-cli/blob/5024443c7217464a66e98f80d73172a26440bd8f/packages/cli/src/utils/sessionUtils.ts#L530-L566","documentation":"Thrown by selectSession when loadConversationRecord(sessionPath) returns a falsy value — the session file exists in the listing but its contents could not be parsed into a valid ConversationRecord. This is a data-integrity failure: the on-disk session is empty or unparseable.","triggerScenarios":"loadConversationRecord(sessionPath) resolves to null/undefined. The file at sessionPath is empty, truncated, or contains JSON that does not match the expected schema well enough to yield a record.","commonSituations":"Session file was partially written (process killed mid-write). File manually emptied or corrupted. Schema migration left an old file unreadable. Disk full during a prior write truncated the file.","solutions":["Inspect the session file at sessionPath (under <projectTempDir>/chats/<fileName>) — if empty/corrupt, delete or restore from backup.","If many sessions are affected, check for a recent schema/format change and migrate or clear old chats.","Resume a different, known-good session instead."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":"const stat = fs.statSync(sessionPath);\nif (stat.size === 0) throw new Error(`Session file ${sessionPath} is empty/corrupt; remove it before resuming.`);","typeGuard":null,"tryCatchPattern":"let data;\ntry { data = await loadConversationRecord(sessionPath); }\ncatch (e) { /* handle corrupt file: remove/restore, then surface friendly error */ }\nif (!data) { /* treat as corrupt */ }","preventionTips":["Write session files atomically (write tmp + rename) to avoid truncation on crash.","Add a session-file integrity check (size/schema) on startup."],"tags":["session","resume","data-integrity","filesystem","parsing"],"backgroundTag":null,"analyzedSha":"5024443c7217464a66e98f80d73172a26440bd8f","analyzedAt":"2026-08-12T06:01:53.711Z","schemaVersion":2},"datasetVersion":"2026-08-12T13:17:24.610Z"}