linshenkx/prompt-optimizer · error · Error
[ImageImage2ImageSession] PreferenceService is unavailable;
Error message
[ImageImage2ImageSession] PreferenceService is unavailable; cannot restore session
What it means
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.
Source
Thrown at packages/ui/src/stores/session/useImageImage2ImageSession.ts:686
evaluationResults: evaluationResults.value,
isCompareMode: isCompareMode.value,
selectedTextModelKey: selectedTextModelKey.value,
selectedImageModelKey: selectedImageModelKey.value,
selectedTemplateId: selectedTemplateId.value,
selectedIterateTemplateId: selectedIterateTemplateId.value,
lastActiveAt: lastActiveAt.value,
...assetBindingState.persistedAssetBinding(),
}
await $services.preferenceService.set(IMAGE_IMAGE2IMAGE_SESSION_KEY, snapshot)
scheduleImageStorageGc($services.preferenceService, $services.imageStorageService)
})
}
const restoreSession = async () => {
const $services = getPiniaServices()
if (!$services?.preferenceService) {
throw new Error('[ImageImage2ImageSession] PreferenceService is unavailable; cannot restore session')
}
if (!$services?.imageStorageService) {
throw new Error('[ImageImage2ImageSession] ImageStorageService is unavailable; cannot restore session')
}
try {
const saved = await $services.preferenceService.get<unknown>(
IMAGE_IMAGE2IMAGE_SESSION_KEY,
null
)
if (saved) {
const parsed =
typeof saved === 'string'
? (JSON.parse(saved) as Record<string, unknown>)
: (saved as Record<string, unknown>)
const defaultState = createDefaultState()View on GitHub (pinned to 3e677b1d9f)
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
Example fix
// before
onMounted(() => { session.restoreSession() }) // may run before plugins
// after
await appBootstrap() // installs service plugins
onMounted(() => { session.restoreSession() }) Defensive patterns
Strategy: validation
Validate before calling
const services = getPiniaServices()
if (services?.preferenceService && services?.imageStorageService) {
await session.restoreSession()
} Type guard
const servicesReady = (): boolean => {
const s = getPiniaServices()
return Boolean(s?.preferenceService && s?.imageStorageService)
} Try / catch
try {
await session.restoreSession()
} catch (e) {
if (e instanceof Error && e.message.includes('PreferenceService is unavailable')) {
// skip restore; start a fresh session
} else throw e
} Prevention
- Await full plugin installation before mounting components that restore sessions
- Stub preferenceService in tests
- Retry restore once after the services container initializes
When it happens
Trigger: Calling restoreSession when getPiniaServices()?.preferenceService is falsy (e.g. on app mount before plugins install, or in tests with a bare Pinia).
Common situations: 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.
Related errors
- [BasicSystemSession] ImageStorageService is unavailable; can
- [ImageImage2ImageSession] PreferenceService is unavailable;
- [BasicSystemSession] ImageStorageService is unavailable; can
- [ImageImage2ImageSession] ImageStorageService is unavailable
AI-assisted analysis of linshenkx/prompt-optimizer@3e677b1d9f (2026-08-27).
Data as JSON: /api/errors/a7d9c1749f4b005e.
Report an issue: GitHub.