{"record":{"id":"380daf2325923390","repo":"mastra-ai/mastra","slug":"failed-to-retrieve-created-version-380daf","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/scorer-versions.ts","lineNumber":157,"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        scorerStore as unknown as VersionedStoreInterface,\n        scorerId,\n        'scorerDefinitionId',\n        currentConfig,\n        changedFields,\n        { changeMessage },\n      );\n\n      const version = await scorerStore.getVersion(versionId);\n      if (!version) {\n        throw new HTTPException(500, { message: 'Failed to retrieve created version' });\n      }\n\n      await enforceRetentionLimit(\n        scorerStore as unknown as VersionedStoreInterface,\n        scorerId,\n        'scorerDefinitionId',\n        scorer.activeVersionId,\n      );\n\n      return version;\n    } catch (error) {\n      return handleError(error, 'Error creating scorer version');\n    }\n  },\n});\n\n/**\n * GET /stored/scorers/:scorerId/versions/:versionId - Get a specific version","sourceCodeStart":139,"sourceCodeEnd":175,"githubUrl":"https://github.com/mastra-ai/mastra/blob/75dd419e613fe9c39f846ffc500716141b74fda6/packages/server/src/server/handlers/scorer-versions.ts#L139-L175","documentation":"Thrown as HTTP 500 when createVersion on the scorer store returned (or resolved without) a usable versionId, and the follow-up getVersion(versionId) could not fetch the row that was supposedly created. This indicates the write did not land or the returned id is invalid — an internal consistency failure rather than user error.","triggerScenarios":"POST /api/scorers/{scorerId}/versions where the store's createVersion succeeds nominally but the subsequent getVersion(versionId) returns undefined — e.g. a store bug, a failed transaction that still returned an id, or replication lag/consistency issues in the backing database.","commonSituations":"Distributed databases with read-after-write inconsistency; concurrent deletes racing the create; buggy custom versioned store implementations; partial migration leaving the versions table unusable.","solutions":["Retry the version creation request once to rule out transient consistency issues","Check server logs/storage adapter logs for a failed transaction or underlying DB error","Verify the backing database is healthy (connections, replication lag)","If using a custom versioned store, ensure createVersion commits before returning and the id matches a readable row"],"exampleFix":"// before (custom store: returns id before commit)\nconst id = crypto.randomUUID(); queueInsert(row); return id;\n// after\nconst id = crypto.randomUUID(); await this.db.insert(rows).values(row); return id;","handlingStrategy":"retry","validationCode":null,"typeGuard":null,"tryCatchPattern":"async function createVersionWithRetry(scorerId: string, msg?: string, attempts = 2) {\n  for (let i = 0; i < attempts; i++) {\n    const res = await fetch(`/api/scorers/${scorerId}/versions`, { method: 'POST', body: JSON.stringify({ changeMessage: msg }) });\n    if (res.ok) return res.json();\n    const body = await res.json();\n    if (res.status === 500 && body.message === 'Failed to retrieve created version' && i < attempts - 1) continue;\n    throw body;\n  }\n}","preventionTips":["Use a database with strong read-after-write consistency for the versions table","Alert on this 500 — it usually indicates a store/DB bug, not user error","Keep custom versioned stores committing before returning ids","Watch replication lag if reading versions from a replica"],"tags":["storage","server","consistency"],"backgroundTag":"read-after-write-inconsistency","analyzedSha":"75dd419e613fe9c39f846ffc500716141b74fda6","analyzedAt":"2026-08-30T00:15:31.844Z","schemaVersion":2},"datasetVersion":"2026-08-30T08:17:16.595Z"}