linshenkx/prompt-optimizer · error · Error

[BasicSystemSession] ImageStorageService is unavailable; can

Error message

[BasicSystemSession] ImageStorageService is unavailable; cannot save test image

What it means

useBasicSystemSession.saveSession throws when the session snapshot contains a base64 test image (testImageB64 with no existing asset id) but the ImageStorageService is not registered on the Pinia services container. The image must be persisted as an asset before saving; without the service this is impossible, so the save aborts.

Source

Thrown at packages/ui/src/stores/session/useBasicSystemSession.ts:509

      assetId: testImageAssetId.value,
    }

    return await queueImageStorageMaintenance(async () => {
      const $services = getPiniaServices()
      if (!$services?.preferenceService) {
        console.warn('[BasicSystemSession] PreferenceService is unavailable; cannot save session')
        return
      }

      try {
        let imageAssetIdToSave = imageSnapshot.assetId
        const imageMimeTypeToSave = imageSnapshot.b64 || imageSnapshot.assetId
          ? (imageSnapshot.mimeType || 'image/png')
          : ''

        if (imageSnapshot.b64 && !imageAssetIdToSave) {
          if (!$services.imageStorageService) {
            throw new Error(
              '[BasicSystemSession] ImageStorageService is unavailable; cannot save test image',
            )
          }

          imageAssetIdToSave = await persistImagePayloadAsAssetId({
            payload: {
              b64: imageSnapshot.b64,
              mimeType: imageMimeTypeToSave,
            },
            storageService: $services.imageStorageService,
            sourceType: 'uploaded',
          })

          if (!imageAssetIdToSave) {
            throw new Error('[BasicSystemSession] Failed to persist test image')
          }

          if (

View on GitHub (pinned to 3e677b1d9f)

Solutions

  1. Ensure the app initialization installs ImageStorageService on the Pinia services container before any session-saving action runs
  2. In tests, register a mock imageStorageService in createPinia setup
  3. Guard UI actions: disable save/image-upload until services are initialized
  4. If the service is intentionally optional, clear the b64 image before saving or fall back to skipping image persistence

Example fix

// before
const $services = getPiniaServices()
if (!$services.imageStorageService) throw new Error('...')

// after (test setup)
const pinia = createPinia()
setActivePinia(pinia)
pinia.use(() => ({ imageStorageService: mockImageStorageService }))
Defensive patterns

Strategy: type-guard

Validate before calling

const services = getPiniaServices()
if (!services?.imageStorageService) {
  // defer save, or block image upload in UI
}

Type guard

const hasImageStorage = (): boolean =>
  Boolean(getPiniaServices()?.imageStorageService)

Try / catch

try {
  await session.saveSession()
} catch (e) {
  if (e instanceof Error && e.message.includes('ImageStorageService is unavailable')) {
    // retry after bootstrap completes, or save without image
  } else throw e
}

Prevention

When it happens

Trigger: Calling saveSession (directly or via updateTestImage/updateTemplate/updateOptimizeModel/updateTestModel/updateIterateTemplate/assetBindingState) when getPiniaServices().imageStorageService is falsy and the current session holds an unsaved b64 image.

Common situations: Running the store outside the app bootstrap that registers services (unit tests, SSR, storybook); initialization order bug where the session store is used before plugins install services; a build/config change that skips the image-storage plugin.

Related errors


AI-assisted analysis of linshenkx/prompt-optimizer@3e677b1d9f (2026-08-27). Data as JSON: /api/errors/201f1b67e7c15083. Report an issue: GitHub.