{"record":{"id":"ee963d5f70b7e07b","repo":"linshenkx/prompt-optimizer","slug":"favorites-payload-exceeds-hard-limit-of-favorite","errorCode":null,"errorMessage":"favorites payload exceeds hard limit of ${FAVORITES_HARD_LIMIT_BYTES} bytes","messagePattern":"favorites payload exceeds hard limit of (.+?) bytes","errorType":"validation","errorClass":"FavoriteValidationError","httpStatus":null,"severity":"error","filePath":"packages/core/src/services/favorite/storage-guards.ts","lineNumber":138,"sourceCode":"\nexport const assertFavoritesPayloadWithinBudget = (\n  favorites: FavoritePrompt[],\n  options?: {\n    warnOnSoftLimit?: boolean\n    logWarning?: (message: string) => void\n  },\n): {\n  totalBytes: number\n  softLimitExceeded: boolean\n} => {\n  favorites.forEach((favorite) => {\n    assertFavoriteMetadataHasNoInlineImages(favorite.metadata)\n    assertFavoriteFitsItemBudget(favorite)\n  })\n\n  const totalBytes = getSerializedByteLength(JSON.stringify(favorites))\n  if (totalBytes > FAVORITES_HARD_LIMIT_BYTES) {\n    throw new FavoriteValidationError(\n      `favorites payload exceeds hard limit of ${FAVORITES_HARD_LIMIT_BYTES} bytes`,\n    )\n  }\n\n  const softLimitExceeded =\n    totalBytes > FAVORITES_SOFT_LIMIT_BYTES - FAVORITES_SOFT_WARNING_HEADROOM_BYTES\n  if (softLimitExceeded && options?.warnOnSoftLimit) {\n    const logWarning = options.logWarning ?? console.warn\n    logWarning(\n      `favorites payload exceeds soft limit (${totalBytes} bytes > ${FAVORITES_SOFT_LIMIT_BYTES} bytes)`,\n    )\n  }\n\n  return {\n    totalBytes,\n    softLimitExceeded,\n  }\n}","sourceCodeStart":120,"sourceCodeEnd":156,"githubUrl":"https://github.com/linshenkx/prompt-optimizer/blob/3e677b1d9f7e0493c142c175560531e7ae786dce/packages/core/src/services/favorite/storage-guards.ts#L120-L156","documentation":"Collection-wide guard in assertFavoritesPayloadWithinBudget: after each favorite passes the metadata and per-item checks, the total serialized size of the whole favorites array must stay under FAVORITES_HARD_LIMIT_BYTES. A soft-limit warning is computed afterwards but the hard throw happens first.","triggerScenarios":"Saving a favorite when JSON.stringify(favorites) across the entire collection exceeds FAVORITES_HARD_LIMIT_BYTES — the accumulation of all entries, not any single one, trips it.","commonSituations":"Long-lived installs accumulating thousands of favorites, importing a large batch at once, or many entries each near the per-item limit.","solutions":["Delete old or unused favorites to bring total serialized size back under the limit","Reduce oversized individual entries (see the per-item limit error)","Track total size (TextEncoder on the serialized array) and prune or archive before saving new entries"],"exampleFix":"// before\nawait manager.addFavorite(newFav); // store already near cap\n\n// after\nconst all = await manager.getFavorites();\nconst total = new TextEncoder().encode(JSON.stringify(all)).length;\nif (total + new TextEncoder().encode(JSON.stringify(newFav)).length > LIMIT) {\n  await manager.deleteFavorite(oldestId);\n}\nawait manager.addFavorite(newFav);","handlingStrategy":"fallback","validationCode":"const all = await manager.getFavorites();\nconst totalBytes = new TextEncoder().encode(JSON.stringify(all)).length;\nconst incomingBytes = new TextEncoder().encode(JSON.stringify(newFavorite)).length;\nif (totalBytes + incomingBytes > FAVORITES_HARD_LIMIT_BYTES) {\n  await manager.deleteFavorite(oldestFavoriteId); // prune before saving\n}","typeGuard":null,"tryCatchPattern":"try {\n  await manager.addFavorite(newFav);\n} catch (e) {\n  if (e instanceof FavoriteValidationError && /payload exceeds hard limit/.test(e.message)) {\n    await pruneOldestFavorites();\n    await manager.addFavorite(newFav);\n  }\n}","preventionTips":["Track total serialized size and prune/archive before approaching the cap","Heed soft-limit warnings before they become hard failures","Avoid bulk imports of thousands of entries without size accounting"],"tags":["validation","size-limit","storage","quota"],"backgroundTag":"payload-size-limit-exceeded","analyzedSha":"3e677b1d9f7e0493c142c175560531e7ae786dce","analyzedAt":"2026-08-27T21:29:16.709Z","schemaVersion":2},"datasetVersion":"2026-08-28T00:17:15.603Z"}