{"record":{"id":"6e95051e820315d5","repo":"mastra-ai/mastra","slug":"version-with-id-versionid-not-found-for-prompt","errorCode":null,"errorMessage":"Version with id ${versionId} not found for prompt block ${promptBlockId}","messagePattern":"Version with id (.+?) not found for prompt block (.+?)","errorType":"http","errorClass":"HTTPException","httpStatus":404,"severity":"error","filePath":"packages/server/src/server/handlers/prompt-block-versions.ts","lineNumber":198,"sourceCode":"      const storage = mastra.getStorage();\n\n      if (!storage) {\n        throw new HTTPException(500, { message: 'Storage is not configured' });\n      }\n\n      const promptBlockStore = await storage.getStore('promptBlocks');\n      if (!promptBlockStore) {\n        throw new HTTPException(500, { message: 'Prompt blocks storage domain is not available' });\n      }\n\n      const version = await promptBlockStore.getVersion(versionId);\n\n      if (!version) {\n        throw new HTTPException(404, { message: `Version with id ${versionId} not found` });\n      }\n\n      if (version.blockId !== promptBlockId) {\n        throw new HTTPException(404, {\n          message: `Version with id ${versionId} not found for prompt block ${promptBlockId}`,\n        });\n      }\n      const promptBlock = await promptBlockStore.getById(promptBlockId);\n      assertStoredResourceScope(promptBlock, await getStoredResourceScope(mastra, requestContext));\n\n      return version;\n    } catch (error) {\n      return handleError(error, 'Error getting prompt block version');\n    }\n  },\n});\n\n/**\n * POST /stored/prompt-blocks/:promptBlockId/versions/:versionId/activate - Set a version as active\n */\nexport const ACTIVATE_PROMPT_BLOCK_VERSION_ROUTE = createRoute({\n  method: 'POST',","sourceCodeStart":180,"sourceCodeEnd":216,"githubUrl":"https://github.com/mastra-ai/mastra/blob/75dd419e613fe9c39f846ffc500716141b74fda6/packages/server/src/server/handlers/prompt-block-versions.ts#L180-L216","documentation":"The version id exists, but version.blockId !== promptBlockId: the version belongs to a different prompt block than the one in the URL path. The handler intentionally returns 404 (not 403/409) to avoid leaking cross-resource ids, telling you the pairing of path ids is invalid.","triggerScenarios":"GET /stored/prompt-blocks/:promptBlockId/versions/:versionId where versionId resolves to a version whose parent blockId differs from :promptBlockId — typically mixing ids from two prompt blocks in one request.","commonSituations":"Client code holding a versionId from block A while iterating blocks; UI state where the selected block changed but the selected version did not; copy-pasting a version link between blocks.","solutions":["Fetch versions scoped to the block (GET /stored/prompt-blocks/:promptBlockId/versions) and use a versionId belonging to that block.","Track blockId and versionId together in client state instead of independently.","If the version lives under another block, correct the path's promptBlockId to the owning block's id.","Check for stale references after a block was recreated (new block id, orphaned old version ids)."],"exampleFix":"// before\ngetVersion(blockB.id, versionFromBlockA);\n// after\nconst { versions } = await listVersions(blockB.id);\nconst v = versions.find(x => x.id === versionFromBlockA) ?? versions[0];\ngetVersion(blockB.id, v.id);","handlingStrategy":"validation","validationCode":"const version = await fetchVersion(blockId, versionId); // may 404\n// to pre-check ownership without the mismatch path:\nconst { versions } = await listVersions(blockId);\nif (!versions.some(v => v.id === versionId)) throw new Error('versionId does not belong to this prompt block');","typeGuard":"function belongsToBlock(version: { blockId: string } | null | undefined, blockId: string): version is { blockId: string } {\n  return !!version && version.blockId === blockId;\n}","tryCatchPattern":"try {\n  await fetchVersion(blockId, versionId);\n} catch (e) {\n  if (e.status === 404 && e.message.includes('not found for prompt block')) {\n    // version belongs to another block; re-scope from that block's version list\n  } else throw e;\n}","preventionTips":["Keep (blockId, versionId) pairs together in client state.","Reset selected version whenever the selected block changes.","Scope all version reads through the block's version list endpoint."],"tags":["http-404","id-mismatch","versioning","rest"],"backgroundTag":"resource-id-mismatch","analyzedSha":"75dd419e613fe9c39f846ffc500716141b74fda6","analyzedAt":"2026-08-30T00:15:31.844Z","schemaVersion":2},"datasetVersion":"2026-08-30T08:17:16.595Z"}