linshenkx/prompt-optimizer · error · Error

[BasicSystemSession] ImageStorageService is unavailable; can

Error message

[BasicSystemSession] ImageStorageService is unavailable; cannot restore test image

What it means

During restoreSession, if the saved session references a stored test image asset but ImageStorageService is unavailable, the store throws before it can call getImage. Restoration of the image is mandatory when an asset id exists, so a missing service aborts that part of the restore.

Source

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

      if (saved) {
        const parsed =
          typeof saved === 'string'
            ? (JSON.parse(saved) as BasicSystemSessionState)
            : (saved as BasicSystemSessionState)

        const savedTestImageAssetId = typeof parsed.testImageAssetId === 'string' && parsed.testImageAssetId.trim()
          ? parsed.testImageAssetId.trim()
          : null
        let restoredTestImageAssetId = savedTestImageAssetId
        let restoredTestImageB64: string | null = null
        let restoredTestImageMimeType = typeof parsed.testImageMimeType === 'string'
          ? parsed.testImageMimeType
          : ''

        if (savedTestImageAssetId) {
          try {
            if (!$services.imageStorageService) {
              throw new Error(
                '[BasicSystemSession] ImageStorageService is unavailable; cannot restore test image',
              )
            }

            const storedImage = await $services.imageStorageService.getImage(savedTestImageAssetId)
            if (!storedImage?.data?.trim()) {
              console.info('[BasicSystemSession] Test image asset is missing; restoring session without it')
              restoredTestImageAssetId = null
              restoredTestImageMimeType = ''
              shouldRepairMissingTestImage = true
            } else {
              restoredTestImageB64 = storedImage.data
              restoredTestImageMimeType = storedImage.metadata?.mimeType || restoredTestImageMimeType || 'image/png'
            }
          } catch (error) {
            console.warn(
              '[BasicSystemSession] Failed to restore test image; restoring text session without it:',
              error,

View on GitHub (pinned to 3e677b1d9f)

Solutions

  1. Ensure service plugins are installed on Pinia before restoreSession is dispatched (await app bootstrap)
  2. Register a mock imageStorageService in test setups that restore sessions
  3. If the service is optional in your deployment, catch the error and restore the session without the image, prompting re-upload

Example fix

// before
await session.restoreSession() // throws if asset id saved but no service

// after
const services = getPiniaServices()
if (services?.imageStorageService) {
  await session.restoreSession()
} else {
  await session.restoreSession().catch(e => console.warn('image not restored:', e.message))
}
Defensive patterns

Strategy: fallback

Validate before calling

const services = getPiniaServices()
if (services?.imageStorageService) {
  await session.restoreSession()
} else {
  await session.restoreSession().catch(() => {}) // degrade gracefully
}

Type guard

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

Try / catch

try {
  await session.restoreSession()
} catch (e) {
  if (e instanceof Error && e.message.includes('cannot restore test image')) {
    // continue with image-less session
  } else throw e
}

Prevention

When it happens

Trigger: restoreSession when parsed.testImageAssetId is truthy and getPiniaServices().imageStorageService is falsy. The throw happens inside a try block, so it is likely converted to a handled restore failure downstream.

Common situations: Tests or SSR rendering that mount the session store without service plugins; async boot where restore runs before service installation; environments (private mode) where the storage plugin failed to construct.

Related errors


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