linshenkx/prompt-optimizer · error · Error

[BasicSystemSession] Failed to persist test image

Error message

[BasicSystemSession] Failed to persist test image

What it means

After calling persistImagePayloadAsAssetId to store the session's test image, saveSession verifies a truthy asset id was returned; if the persistence helper resolves without producing an id, it throws this error. This catches silent failures of the image storage pipeline (e.g. a service that no-ops or returns undefined).

Source

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

        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 (
            testImageB64.value === imageSnapshot.b64 &&
            testImageMimeType.value === imageSnapshot.mimeType &&
            !testImageAssetId.value
          ) {
            testImageAssetId.value = imageAssetIdToSave
          }
        }

        const sessionState = {
          prompt: prompt.value,
          optimizedPrompt: optimizedPrompt.value,
          reasoning: reasoning.value,
          chainId: chainId.value,
          versionId: versionId.value,
          testContent: testContent.value,

View on GitHub (pinned to 3e677b1d9f)

Solutions

  1. Verify the ImageStorageService.save/put implementation actually returns the stored asset id
  2. Check storage quota/permissions on the backend (IndexedDB/OPFS/server) and inspect console for swallowed errors in persistImagePayloadAsAssetId
  3. Log the return value of persistImagePayloadAsAssetId to confirm which layer drops the id
  4. If using a mock in tests, make it resolve with a fake asset id

Example fix

// before
const imageAssetIdToSave = await persistImagePayloadAsAssetId({ payload, storageService, sourceType: 'uploaded' })

// after
const imageAssetIdToSave = await persistImagePayloadAsAssetId({ payload, storageService, sourceType: 'uploaded' })
if (!imageAssetIdToSave) console.error('persist failed for', payload.name)
Defensive patterns

Strategy: try-catch

Validate before calling

// Verify the storage service returns ids before enabling image features
const ok = await services.imageStorageService.save(testBlob)
if (!ok) throw new Error('storage service contract broken')

Try / catch

try {
  await session.saveSession()
} catch (e) {
  if (e instanceof Error && e.message.includes('Failed to persist test image')) {
    // clear image and retry once, or prompt re-upload
  } else throw e
}

Prevention

When it happens

Trigger: saveSession with a b64 test image where persistImagePayloadAsAssetId completes but returns undefined/null/empty (storage write failed silently, wrong service implementation, asset id assignment bug).

Common situations: A custom or mocked ImageStorageService whose save method doesn't return the asset id; storage backend rejecting the write without throwing (quota, permissions); refactors of persistImagePayloadAsAssetId changing its return contract.

Related errors


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