{"record":{"id":"817e38a7c3bb5db3","repo":"mastra-ai/mastra","slug":"failed-to-retrieve-created-version-817e38","errorCode":null,"errorMessage":"Failed to retrieve created version","messagePattern":"Failed to retrieve created version","errorType":"http","errorClass":"HTTPException","httpStatus":500,"severity":"error","filePath":"packages/server/src/server/handlers/prompt-block-versions.ts","lineNumber":148,"sourceCode":"      }\n      const previousConfig = latestVersion\n        ? extractConfigFromVersion(latestVersion as unknown as Record<string, unknown>, SNAPSHOT_CONFIG_FIELDS)\n        : null;\n\n      const changedFields = calculateChangedFields(previousConfig, currentConfig);\n\n      const { versionId } = await createVersionWithRetry(\n        promptBlockStore as unknown as VersionedStoreInterface,\n        promptBlockId,\n        'blockId',\n        currentConfig,\n        changedFields,\n        { changeMessage },\n      );\n\n      const version = await promptBlockStore.getVersion(versionId);\n      if (!version) {\n        throw new HTTPException(500, { message: 'Failed to retrieve created version' });\n      }\n\n      await enforceRetentionLimit(\n        promptBlockStore as unknown as VersionedStoreInterface,\n        promptBlockId,\n        'blockId',\n        promptBlock.activeVersionId,\n      );\n\n      return version;\n    } catch (error) {\n      return handleError(error, 'Error creating prompt block version');\n    }\n  },\n});\n\n/**\n * GET /stored/prompt-blocks/:promptBlockId/versions/:versionId - Get a specific version","sourceCodeStart":130,"sourceCodeEnd":166,"githubUrl":"https://github.com/mastra-ai/mastra/blob/75dd419e613fe9c39f846ffc500716141b74fda6/packages/server/src/server/handlers/prompt-block-versions.ts#L130-L166","documentation":"After createVersionWithRetry inserts a new version snapshot, the handler immediately re-reads it with getVersion(versionId). A null result means the write reported success but the row is not readable back — an internal consistency failure, surfaced as a 500. It usually indicates a storage-layer bug, eventual-consistency lag, or a silent write failure swallowed by the retry helper.","triggerScenarios":"POST /stored/prompt-blocks/:promptBlockId/versions where createVersionWithRetry returns a versionId but promptBlockStore.getVersion(versionId) returns null — e.g. the insert failed silently, the retry helper fabricated an id, or the store's getVersion reads from a different table/connection.","commonSituations":"Storage adapter bugs after schema migrations; read-replica lag on hosted Postgres where the write went to primary but read hit a lagging replica; concurrent retention-limit deletion removing the version between insert and read.","solutions":["Retry the version-creation request; transient replication/consistency lag often resolves on retry.","Verify the version actually persisted by listing versions (GET /stored/prompt-blocks/:id/versions) and report a storage-adapter bug if it is missing despite a success response.","Check for concurrent automation (retention cleanup, restore/activate) racing version creation and serialize those operations.","Upgrade the storage adapter; if reproducible, file a bug with the adapter and @mastra/server versions."],"exampleFix":"// before\nawait createVersion(id, config); // assumes success\n// after\nconst created = await createVersion(id, config);\nconst check = await getVersion(created.versionId);\nif (!check) throw new Error('version write not confirmed, retrying');","handlingStrategy":"retry","validationCode":null,"typeGuard":null,"tryCatchPattern":"try {\n  await createVersion(blockId, config);\n} catch (e) {\n  if (e?.message === 'Failed to retrieve created version') {\n    await sleep(250); // read-your-write lag\n    await createVersion(blockId, config); // one bounded retry\n  } else throw e;\n}","preventionTips":["Add a short retry with backoff around version creation.","Keep retention cleanup and activation jobs from racing version creation.","Keep the storage adapter current; this is usually an adapter-level bug.","Verify persisted versions via list after write in critical paths."],"tags":["storage","internal-error","consistency","prompt-blocks"],"backgroundTag":"write-not-readable-back","analyzedSha":"75dd419e613fe9c39f846ffc500716141b74fda6","analyzedAt":"2026-08-30T00:15:31.844Z","schemaVersion":2},"datasetVersion":"2026-08-30T08:17:16.595Z"}