{"record":{"id":"122af7d751787076","repo":"linshenkx/prompt-optimizer","slug":"basicsystemsession-failed-to-persist-test-image","errorCode":null,"errorMessage":"[BasicSystemSession] Failed to persist test image","messagePattern":"\\[BasicSystemSession\\] Failed to persist test image","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/ui/src/stores/session/useBasicSystemSession.ts","lineNumber":524,"sourceCode":"\n        if (imageSnapshot.b64 && !imageAssetIdToSave) {\n          if (!$services.imageStorageService) {\n            throw new Error(\n              '[BasicSystemSession] ImageStorageService is unavailable; cannot save test image',\n            )\n          }\n\n          imageAssetIdToSave = await persistImagePayloadAsAssetId({\n            payload: {\n              b64: imageSnapshot.b64,\n              mimeType: imageMimeTypeToSave,\n            },\n            storageService: $services.imageStorageService,\n            sourceType: 'uploaded',\n          })\n\n          if (!imageAssetIdToSave) {\n            throw new Error('[BasicSystemSession] Failed to persist test image')\n          }\n\n          if (\n            testImageB64.value === imageSnapshot.b64 &&\n            testImageMimeType.value === imageSnapshot.mimeType &&\n            !testImageAssetId.value\n          ) {\n            testImageAssetId.value = imageAssetIdToSave\n          }\n        }\n\n        const sessionState = {\n          prompt: prompt.value,\n          optimizedPrompt: optimizedPrompt.value,\n          reasoning: reasoning.value,\n          chainId: chainId.value,\n          versionId: versionId.value,\n          testContent: testContent.value,","sourceCodeStart":506,"sourceCodeEnd":542,"githubUrl":"https://github.com/linshenkx/prompt-optimizer/blob/3e677b1d9f7e0493c142c175560531e7ae786dce/packages/ui/src/stores/session/useBasicSystemSession.ts#L506-L542","documentation":"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).","triggerScenarios":"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).","commonSituations":"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.","solutions":["Verify the ImageStorageService.save/put implementation actually returns the stored asset id","Check storage quota/permissions on the backend (IndexedDB/OPFS/server) and inspect console for swallowed errors in persistImagePayloadAsAssetId","Log the return value of persistImagePayloadAsAssetId to confirm which layer drops the id","If using a mock in tests, make it resolve with a fake asset id"],"exampleFix":"// before\nconst imageAssetIdToSave = await persistImagePayloadAsAssetId({ payload, storageService, sourceType: 'uploaded' })\n\n// after\nconst imageAssetIdToSave = await persistImagePayloadAsAssetId({ payload, storageService, sourceType: 'uploaded' })\nif (!imageAssetIdToSave) console.error('persist failed for', payload.name)","handlingStrategy":"try-catch","validationCode":"// Verify the storage service returns ids before enabling image features\nconst ok = await services.imageStorageService.save(testBlob)\nif (!ok) throw new Error('storage service contract broken')","typeGuard":null,"tryCatchPattern":"try {\n  await session.saveSession()\n} catch (e) {\n  if (e instanceof Error && e.message.includes('Failed to persist test image')) {\n    // clear image and retry once, or prompt re-upload\n  } else throw e\n}","preventionTips":["Ensure ImageStorageService.save returns the asset id","Mock storage services in tests with resolving ids","Monitor storage quota and surface early warnings"],"tags":["image-storage","session","persistence"],"backgroundTag":"silent-write-failure","analyzedSha":"3e677b1d9f7e0493c142c175560531e7ae786dce","analyzedAt":"2026-08-27T21:29:16.709Z","schemaVersion":2},"datasetVersion":"2026-08-28T00:17:15.603Z"}