linshenkx/prompt-optimizer · warning · Error

Image storage quota exceeded: projected count ${nextCount} e

Error message

Image storage quota exceeded: projected count ${nextCount} exceeds maxCount ${config.maxCount}

What it means

assertStorageQuotaForPayload projects the image count after adding a new asset and throws when it would exceed config.maxCount. This is a client-side quota enforcing a maximum number of stored image assets before persisting via persistImagePayloadAsAssetId.

Source

Thrown at packages/ui/src/utils/image-asset-storage.ts:192

  }

  const stats = typeof storageService.getStorageStats === 'function'
    ? await storageService.getStorageStats()
    : null

  if (!stats) {
    return
  }

  const nextCount = stats.count + 1
  const nextTotalBytes = stats.totalBytes + Math.floor(payload.b64.length * 0.75)

  if (
    typeof config.maxCount === 'number' &&
    Number.isFinite(config.maxCount) &&
    nextCount > config.maxCount
  ) {
    throw new Error(
      `Image storage quota exceeded: projected count ${nextCount} exceeds maxCount ${config.maxCount}`,
    )
  }

  if (
    typeof config.maxCacheSize === 'number' &&
    Number.isFinite(config.maxCacheSize) &&
    nextTotalBytes > config.maxCacheSize
  ) {
    throw new Error(
      `Image storage quota exceeded: projected size ${nextTotalBytes} exceeds maxCacheSize ${config.maxCacheSize}`,
    )
  }
}

export const persistImagePayloadAsAssetId = async (
  opts: PersistImagePayloadOptions,
): Promise<string | null> => {

View on GitHub (pinned to 3e677b1d9f)

Solutions

  1. Evict oldest/least-recently-used assets before inserting to stay under maxCount
  2. Raise config.maxCount if the product limit is too low
  3. Catch this specific error and prompt the user to delete images before adding more
  4. Batch inserts should check remaining quota up front, not per-item

Example fix

// before
await persistImagePayloadAsAssetId(payload) // throws when at cap

// after
while (listImageAssets().length >= config.maxCount) {
  await deleteOldestImageAsset()
}
await persistImagePayloadAsAssetId(payload)
Defensive patterns

Strategy: validation

Validate before calling

const count = listImageAssets().length
if (typeof config.maxCount === 'number' && count + 1 > config.maxCount) {
  await evictOldestImages(count + 1 - config.maxCount)
}

Type guard

null

Try / catch

try { await persistImagePayloadAsAssetId(payload) } catch (e) { if (e.message.startsWith('Image storage quota exceeded: projected count')) { await evictOldestImages(1); return persistImagePayloadAsAssetId(payload) } throw e }

Prevention

When it happens

Trigger: Calling persistImagePayloadAsAssetId when the store already holds maxCount images and one more would push it over; a low maxCount in config (e.g. 50) with a user bulk-importing images.

Common situations: Bulk uploads exceeding the configured asset limit; config regressions lowering maxCount below existing usage; long-lived local stores accumulating attachments; tests with tiny quota configs.

Related errors


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