google-gemini/gemini-cli · error
Failed to load session data
Error message
Failed to load session data
What it means
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.
Source
Thrown at packages/cli/src/utils/sessionUtils.ts:548
}
}
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 {
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'}`,
);View on GitHub (pinned to 5024443c72)
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.
Defensive patterns
Strategy: try-catch
Validate before calling
const stat = fs.statSync(sessionPath);
if (stat.size === 0) throw new Error(`Session file ${sessionPath} is empty/corrupt; remove it before resuming.`); Try / catch
let data;
try { data = await loadConversationRecord(sessionPath); }
catch (e) { /* handle corrupt file: remove/restore, then surface friendly error */ }
if (!data) { /* treat as corrupt */ } Prevention
- Write session files atomically (write tmp + rename) to avoid truncation on crash.
- Add a session-file integrity check (size/schema) on startup.
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- Failed to find session "${trimmedResumeArg}": ${error instan
- Failed to load session ${sessionInfo.id}: ${error instanceof
- Workspace path ${resolvedPath} does not exist
- Workspace path ${resolvedPath} is not a directory
- tar.c command failed to create ${tmpArchiveFile}
AI-assisted analysis of google-gemini/gemini-cli@5024443c72 (2026-08-12).
Data as JSON: /api/errors/827a346417e5af7f.
Report an issue: GitHub.