chatboxai/chatbox · error

Invalid session entry: ${entry.path}

Error message

Invalid session entry: ${entry.path}

What it means

Thrown during the reading phase when a session.json entry parses as JSON but fails isBackupSession - the value must be an object with a non-empty string id, a string name, and an array messages. Propagates after rollback (commitStarted is false, so only temps are cleaned).

Source

Thrown at src/renderer/packages/backup/import-backup.ts:239

    let readBytes = 0
    await readZipFileEntries(
      file,
      async (entry) => {
        throwIfAborted(options.signal)
        readBytes += entry.compressedSize ?? entry.uncompressedSize
        options.onProgress?.({
          phase: 'reading',
          current: Math.min(readBytes, file.size),
          total: file.size,
          label: entry.path,
        })
        const checksum = await sha256Checksum(entry.data)
        const staged: StagedEntry = { path: entry.path, size: entry.uncompressedSize, checksum }
        if (isBackupJsonPath(entry.path) && !isBackupSessionPath(entry.path)) {
          staged.value = parseJson(entry.data, entry.path)
        } else if (isBackupSessionPath(entry.path)) {
          const value = parseJson(entry.data, entry.path)
          if (!isBackupSession(value)) throw new Error(`Invalid session entry: ${entry.path}`)
          const tempKey = `${tempPrefix}:session:${stagedSessionCount++}`
          await options.storage.setItemNow(tempKey, value)
          tempStoreKeys.push(tempKey)
          staged.tempKey = tempKey
        } else if (isBackupResourcePath(entry.path)) {
          const tempKey = `${tempPrefix}:resource:${stagedResourceCount++}`
          await options.storage.setBlob(tempKey, bytesToBase64(entry.data))
          tempBlobKeys.push(tempKey)
          staged.tempKey = tempKey
        } else {
          throw new Error(`Unsupported backup entry: ${entry.path}`)
        }
        stagedEntries.set(entry.path, staged)
      },
      {
        signal: options.signal,
        entryLimits: (path) => ({ maxEntryUncompressedBytes: backupEntryByteLimit(path) }),
      }

View on GitHub (pinned to 81571269ad)

Solutions

  1. Re-create the backup with a compatible app version.
  2. If the session is salvageable, repair its JSON to include a non-empty string id, string name, and array messages before importing.
  3. Remove the offending session.json and its manifest entry if you accept losing that conversation.
  4. Report the schema mismatch with the source and target app versions.

Example fix

// before: malformed session.json aborts the whole import
await importBackupArchive(file, options)
// after: pre-validate each staged session with the same guard
import { isBackupSession } from './archive-layout'
for (const [path, value] of parsedSessions) {
  if (!isBackupSession(value)) throw new Error('Bad session at ' + path)
}
Defensive patterns

Strategy: type-guard

Validate before calling

// Before import, validate every staged session.json with the same guard used internally.
import { isBackupSession } from './archive-layout'
for (const [path, value] of parsedSessions) {
  if (!isBackupSession(value)) throw new Error('Invalid session entry: ' + path)
}

Type guard

import { isBackupSession } from './archive-layout'
import type { Session } from '@shared/types'
// Narrows an unknown parsed value to Session; identical predicate to the one
// inside importBackupArchive that raises this error.
const isValidSessionEntry = (value: unknown): value is Session => isBackupSession(value)

Try / catch

try {
  await importBackupArchive(file, options)
} catch (error) {
  if (error instanceof Error && error.message.startsWith('Invalid session entry')) {
    // Repair or remove the offending session.json, then re-import.
    throw new Error('Archive contains a malformed session', { cause: error })
  }
  throw error
}

Prevention

When it happens

Trigger: entry.path matches ^sessions/[^/]+/session.json$, the bytes parse as JSON, but the result lacks a valid id/name or messages is not an array.

Common situations: A backup from a future/incompatible version whose session schema dropped a required field; a tampered or corrupted session.json; a partially written session from a crashed export.

Related errors


AI-assisted analysis of chatboxai/chatbox@81571269ad (2026-08-12). Data as JSON: /api/errors/0be8f4100c42ffbd. Report an issue: GitHub.