{"record":{"id":"45687c70c086f83e","repo":"mastra-ai/mastra","slug":"failed-to-resolve-created-prompt-block","errorCode":null,"errorMessage":"Failed to resolve created prompt block","messagePattern":"Failed to resolve created prompt block","errorType":"http","errorClass":"HTTPException","httpStatus":500,"severity":"error","filePath":"packages/server/src/server/handlers/stored-prompt-blocks.ts","lineNumber":207,"sourceCode":"\n      await promptBlockStore.create({\n        promptBlock: {\n          id,\n          authorId,\n          metadata: scopeStoredResourceMetadata(metadata, await getStoredResourceScope(mastra, requestContext)),\n          name,\n          description,\n          content,\n          rules,\n          requestContextSchema,\n        },\n      });\n\n      // Return the resolved prompt block (thin record + version config)\n      // Use draft status since newly created entities start as drafts\n      const resolved = await promptBlockStore.getByIdResolved(id, { status: 'draft' });\n      if (!resolved) {\n        throw new HTTPException(500, { message: 'Failed to resolve created prompt block' });\n      }\n\n      const latestVersion = await promptBlockStore.getLatestVersion(id);\n      const hasDraft = !!(\n        latestVersion &&\n        (!resolved.activeVersionId || latestVersion.id !== resolved.activeVersionId)\n      );\n\n      return { ...resolved, hasDraft };\n    } catch (error) {\n      return handleError(error, 'Error creating stored prompt block');\n    }\n  },\n});\n\n/**\n * PATCH /stored/prompt-blocks/:storedPromptBlockId - Update a stored prompt block\n */","sourceCodeStart":189,"sourceCodeEnd":225,"githubUrl":"https://github.com/mastra-ai/mastra/blob/75dd419e613fe9c39f846ffc500716141b74fda6/packages/server/src/server/handlers/stored-prompt-blocks.ts#L189-L225","documentation":"After creating a prompt block, the handler re-reads it via `promptBlockStore.getByIdResolved(id, { status: 'draft' })` to return the resolved view (thin record + version config). If the resolved lookup returns null immediately after a successful create, the store's resolution logic is inconsistent with creation, and the server throws this 500 error. This indicates an internal storage/versioning defect rather than a caller mistake.","triggerScenarios":"POST /stored/prompt-blocks where `create()` succeeded but `getByIdResolved(id, { status: 'draft' })` returns null — i.e. the store created the record but cannot resolve it with draft status immediately afterward.","commonSituations":"Storage adapters with eventually-consistent reads; partially implemented `getByIdResolved` in custom or newer storage backends; versioning records not written atomically with the base record during create; storage migration/version mismatch leaving the create path writing records the resolve path cannot read.","solutions":["Upgrade @mastra/core and the storage package so create and getByIdResolved are consistent","Check server logs/database to confirm the prompt block row (and its draft version row) was actually written","If using a custom storage adapter, implement getByIdResolved to resolve records created by create()","As a workaround, verify the block exists via GET /stored/prompt-blocks/:id?status=draft after a 500 and retry only if it was not persisted"],"exampleFix":null,"handlingStrategy":"retry","validationCode":null,"typeGuard":null,"tryCatchPattern":"try {\n  const created = await client.createStoredPromptBlock(body);\n  return created;\n} catch (e) {\n  if (isHTTPException(e) && e.status === 500 && e.message === 'Failed to resolve created prompt block') {\n    // verify persistence, then retry once; else report storage bug\n    const check = await fetch(`${baseUrl}/api/stored/prompt-blocks/${body.id}?status=draft`);\n    if (!check.ok) throw e;\n    return check.json();\n  }\n  throw e;\n}","preventionTips":["Keep core and storage packages on matching versions","If using a custom store, test create-then-resolve round trips","Report persistent occurrences as a storage adapter bug with DB state"],"tags":["storage","versioning","server","internal"],"backgroundTag":"storage-read-after-write-failed","analyzedSha":"75dd419e613fe9c39f846ffc500716141b74fda6","analyzedAt":"2026-08-30T00:15:31.844Z","schemaVersion":2},"datasetVersion":"2026-08-30T08:17:16.595Z"}