linshenkx/prompt-optimizer · error · Error
[ImageImage2ImageSession] PreferenceService is unavailable;
Error message
[ImageImage2ImageSession] PreferenceService is unavailable; cannot save session
What it means
The image-to-image session's saveSession requires PreferenceService from the Pinia services container to persist session state; if it is missing, saving aborts immediately with this error. It reflects an incomplete dependency container rather than a user data problem.
Source
Thrown at packages/ui/src/stores/session/useImageImage2ImageSession.ts:610
id: imageId,
mimeType: normalizedMime,
sizeBytes: Math.floor(b64.length * 0.75),
createdAt: Date.now(),
accessedAt: Date.now(),
source: 'uploaded'
},
data: b64
})
}
return imageId
}
const saveSession = async () => {
return await queueImageStorageMaintenance(async () => {
const $services = getPiniaServices()
if (!$services?.preferenceService) {
throw new Error('[ImageImage2ImageSession] PreferenceService is unavailable; cannot save session')
}
if (!$services?.imageStorageService) {
throw new Error('[ImageImage2ImageSession] ImageStorageService is unavailable; cannot save session')
}
// 准备保存的数据
let inputImageIdToSave = inputImageId.value
// v2: 多列 variants
const baseVariantResults: TestVariantResults = {
a: testVariantResults.value.a ?? originalImageResult.value,
b: testVariantResults.value.b ?? optimizedImageResult.value,
c: testVariantResults.value.c,
d: testVariantResults.value.d,
}
// 保存输入图像
if (inputImageB64.value && !inputImageId.value) {
inputImageIdToSave = await saveInputImage(View on GitHub (pinned to 3e677b1d9f)
Solutions
- Install the preferences service plugin on Pinia during app bootstrap before any session save can run
- In tests, provide a stub preferenceService (getKey/setKey) on the services container
- Debounce/guard save triggers (watchers) until services are ready
Example fix
// before
const pinia = createPinia()
setActivePinia(pinia) // no plugins -> saveSession throws
// after
const pinia = createPinia()
pinia.use(() => ({ preferenceService: mockPreferenceService, imageStorageService: mockImageStorage }))
setActivePinia(pinia) Defensive patterns
Strategy: type-guard
Validate before calling
const services = getPiniaServices()
if (!services?.preferenceService) {
// defer save until services ready
} Type guard
const hasPreferenceService = (): boolean => Boolean(getPiniaServices()?.preferenceService)
Try / catch
try {
await saveSession()
} catch (e) {
if (e instanceof Error && e.message.includes('PreferenceService is unavailable')) return
throw e
} Prevention
- Register preference service plugin during bootstrap
- Stub preferenceService in tests
- Queue saves until the services container is fully populated
When it happens
Trigger: Invoking saveSession (image image 2 image session) when getPiniaServices()?.preferenceService is falsy. Note saveSession also runs inside queueImageStorageMaintenance, so queued maintenance tasks surface the same error.
Common situations: Unit tests creating the store with a bare createPinia() and no service plugins; plugin installation order bugs; SSR or edge runtimes where the preferences plugin isn't registered; refactors renaming preferenceService.
Related errors
- [BasicSystemSession] ImageStorageService is unavailable; can
- [ImageImage2ImageSession] ImageStorageService is unavailable
- [ImageImage2ImageSession] PreferenceService is unavailable;
- Image understanding service is not available for multimodal
- Image storage service is required to resolve evaluation imag
AI-assisted analysis of linshenkx/prompt-optimizer@3e677b1d9f (2026-08-27).
Data as JSON: /api/errors/78d66ac6c5c719b5.
Report an issue: GitHub.