{"record":{"id":"a7d9c1749f4b005e","repo":"linshenkx/prompt-optimizer","slug":"imageimage2imagesession-preferenceservice-is-una-a7d9c1","errorCode":null,"errorMessage":"[ImageImage2ImageSession] PreferenceService is unavailable; cannot restore session","messagePattern":"\\[ImageImage2ImageSession\\] PreferenceService is unavailable; cannot restore session","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/ui/src/stores/session/useImageImage2ImageSession.ts","lineNumber":686,"sourceCode":"        evaluationResults: evaluationResults.value,\n        isCompareMode: isCompareMode.value,\n        selectedTextModelKey: selectedTextModelKey.value,\n        selectedImageModelKey: selectedImageModelKey.value,\n        selectedTemplateId: selectedTemplateId.value,\n        selectedIterateTemplateId: selectedIterateTemplateId.value,\n        lastActiveAt: lastActiveAt.value,\n        ...assetBindingState.persistedAssetBinding(),\n      }\n\n      await $services.preferenceService.set(IMAGE_IMAGE2IMAGE_SESSION_KEY, snapshot)\n      scheduleImageStorageGc($services.preferenceService, $services.imageStorageService)\n    })\n  }\n\n  const restoreSession = async () => {\n    const $services = getPiniaServices()\n    if (!$services?.preferenceService) {\n      throw new Error('[ImageImage2ImageSession] PreferenceService is unavailable; cannot restore session')\n    }\n    if (!$services?.imageStorageService) {\n      throw new Error('[ImageImage2ImageSession] ImageStorageService is unavailable; cannot restore session')\n    }\n\n    try {\n      const saved = await $services.preferenceService.get<unknown>(\n        IMAGE_IMAGE2IMAGE_SESSION_KEY,\n        null\n      )\n\n      if (saved) {\n        const parsed =\n          typeof saved === 'string'\n            ? (JSON.parse(saved) as Record<string, unknown>)\n            : (saved as Record<string, unknown>)\n\n        const defaultState = createDefaultState()","sourceCodeStart":668,"sourceCodeEnd":704,"githubUrl":"https://github.com/linshenkx/prompt-optimizer/blob/3e677b1d9f7e0493c142c175560531e7ae786dce/packages/ui/src/stores/session/useImageImage2ImageSession.ts#L668-L704","documentation":"useImageImage2ImageSession.restoreSession requires PreferenceService to read the persisted session; if it is missing from the Pinia services container, restoration aborts before any data is loaded. Like the save path, this is a dependency-availability failure, not corrupted session data.","triggerScenarios":"Calling restoreSession when getPiniaServices()?.preferenceService is falsy (e.g. on app mount before plugins install, or in tests with a bare Pinia).","commonSituations":"Component/store mounting earlier than the services plugin; SSR hydration attempting restore; unit tests without service stubs; refactors that changed how services are registered on the container.","solutions":["Ensure the preferences service plugin is installed before dispatching restoreSession (await bootstrap in main.ts before mounting)","In tests, stub preferenceService on the Pinia container","Gate the restore call: skip or retry once services become available"],"exampleFix":"// before\nonMounted(() => { session.restoreSession() }) // may run before plugins\n\n// after\nawait appBootstrap() // installs service plugins\nonMounted(() => { session.restoreSession() })","handlingStrategy":"validation","validationCode":"const services = getPiniaServices()\nif (services?.preferenceService && services?.imageStorageService) {\n  await session.restoreSession()\n}","typeGuard":"const servicesReady = (): boolean => {\n  const s = getPiniaServices()\n  return Boolean(s?.preferenceService && s?.imageStorageService)\n}","tryCatchPattern":"try {\n  await session.restoreSession()\n} catch (e) {\n  if (e instanceof Error && e.message.includes('PreferenceService is unavailable')) {\n    // skip restore; start a fresh session\n  } else throw e\n}","preventionTips":["Await full plugin installation before mounting components that restore sessions","Stub preferenceService in tests","Retry restore once after the services container initializes"],"tags":["pinia","session-restore","preferences"],"backgroundTag":"missing-service-dependency","analyzedSha":"3e677b1d9f7e0493c142c175560531e7ae786dce","analyzedAt":"2026-08-27T21:29:16.709Z","schemaVersion":2},"datasetVersion":"2026-08-28T00:17:15.603Z"}