{"record":{"id":"932c2d1d6fd97e93","repo":"chatboxai/chatbox","slug":"session-was-not-staged-descriptor-path","errorCode":null,"errorMessage":"Session was not staged: ${descriptor.path}","messagePattern":"Session was not staged: (.+?)","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/renderer/packages/backup/import-backup.ts","lineNumber":312,"sourceCode":"      for (const target of plan.targets) {\n        if (!target.needsWrite) continue\n        newResourceKeys.push(target.targetKey)\n        await options.storage.setBlob(target.targetKey, value)\n      }\n      completedResources++\n      options.onProgress?.({\n        phase: 'restoring',\n        current: completedResources,\n        total: resourcePlans.length + manifest.sessions.length,\n        label: plan.resource.filename,\n      })\n    }\n\n    for (let index = 0; index < manifest.sessions.length; index++) {\n      throwIfAborted(options.signal)\n      const descriptor = manifest.sessions[index]\n      const tempKey = stagedEntries.get(descriptor.path)?.tempKey\n      if (!tempKey) throw new Error(`Session was not staged: ${descriptor.path}`)\n      const stagedSession = await options.storage.getItem<Session | null>(tempKey, null)\n      if (!isBackupSession(stagedSession) || stagedSession.id !== descriptor.id) {\n        throw new Error(`Session id does not match manifest: ${descriptor.path}`)\n      }\n      let session = restoreSessionResourceKeys(stagedSession, resourceKeyMap)\n      if (options.rehydrateSession) {\n        const rehydrated = await options.rehydrateSession(session)\n        session = rehydrated.session\n        importWarnings.push(...rehydrated.warnings)\n        if (rehydrated.rollback) rehydrationRollbacks.push(rehydrated.rollback)\n      }\n      await options.storage.setItemNow(backupSessionStorageKey(session.id), session)\n\n      const meta = restoreSessionMetaResourceKeys(descriptor.meta, resourceKeyMap)\n      const existingMeta = await options.metaStorage.getById(session.id)\n      previousMeta.set(session.id, existingMeta)\n      changedMetaIds.push(session.id)\n      if (existingMeta) await options.metaStorage.update(session.id, meta)","sourceCodeStart":294,"sourceCodeEnd":330,"githubUrl":"https://github.com/chatboxai/chatbox/blob/81571269addb6bafb589a920b2883f1e1e084fd1/src/renderer/packages/backup/import-backup.ts#L294-L330","documentation":"Thrown in the restore loop when a manifest session descriptor's staged entry has no tempKey - the session.json was never staged into temp storage during reading. Reading always assigns a tempKey for session paths (lines 240-243), so this is a defensive guard against a staging/validation gap. Propagates after rollback.","triggerScenarios":"stagedEntries.get(descriptor.path)?.tempKey is undefined for a session descriptor during the restore phase.","commonSituations":"Unreachable under the normal reading+validation flow because reading stages every session.json under a tempKey and validateManifestEntries confirms the entry is present. Reachable if validation is bypassed, the reading branch for sessions changes, or stagedEntries is mutated mid-import.","solutions":["Ensure the reading phase routes every isBackupSessionPath entry through the session staging branch.","Do not skip validateManifestEntries before restore.","Regenerate the backup.","Report as a code defect if it reproduces with a valid archive."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":"// No data fix; verify the reading phase staged every session with a tempKey.\nfor (const s of manifest.sessions) {\n  if (!stagedEntries.get(s.path)?.tempKey) throw new Error('Session not staged: ' + s.path)\n}","typeGuard":null,"tryCatchPattern":"try {\n  await importBackupArchive(file, options)\n} catch (error) {\n  if (error instanceof Error && error.message.startsWith('Session was not staged')) {\n    // Defensive guard; normally unreachable. Regenerate the backup and retry.\n    throw new Error('Session staging incomplete', { cause: error })\n  }\n  throw error\n}","preventionTips":["Keep the session reading branch (isBackupSessionPath) assigning a tempKey for every session.json.","Do not bypass validateManifestEntries before the restore loop.","Avoid mutating stagedEntries mid-import."],"tags":["backup","import","session","staging","defensive"],"backgroundTag":null,"analyzedSha":"81571269addb6bafb589a920b2883f1e1e084fd1","analyzedAt":"2026-08-12T21:51:44.981Z","schemaVersion":2},"datasetVersion":"2026-08-13T04:17:16.726Z"}