mastra-ai/mastra · error · HTTPException

Version with id ${versionId} not found for prompt block ${pr

Error message

Version with id ${versionId} not found for prompt block ${promptBlockId}

What it means

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.

Source

Thrown at packages/server/src/server/handlers/prompt-block-versions.ts:198

      const storage = mastra.getStorage();

      if (!storage) {
        throw new HTTPException(500, { message: 'Storage is not configured' });
      }

      const promptBlockStore = await storage.getStore('promptBlocks');
      if (!promptBlockStore) {
        throw new HTTPException(500, { message: 'Prompt blocks storage domain is not available' });
      }

      const version = await promptBlockStore.getVersion(versionId);

      if (!version) {
        throw new HTTPException(404, { message: `Version with id ${versionId} not found` });
      }

      if (version.blockId !== promptBlockId) {
        throw new HTTPException(404, {
          message: `Version with id ${versionId} not found for prompt block ${promptBlockId}`,
        });
      }
      const promptBlock = await promptBlockStore.getById(promptBlockId);
      assertStoredResourceScope(promptBlock, await getStoredResourceScope(mastra, requestContext));

      return version;
    } catch (error) {
      return handleError(error, 'Error getting prompt block version');
    }
  },
});

/**
 * POST /stored/prompt-blocks/:promptBlockId/versions/:versionId/activate - Set a version as active
 */
export const ACTIVATE_PROMPT_BLOCK_VERSION_ROUTE = createRoute({
  method: 'POST',

View on GitHub (pinned to 75dd419e61)

Solutions

  1. Fetch versions scoped to the block (GET /stored/prompt-blocks/:promptBlockId/versions) and use a versionId belonging to that block.
  2. Track blockId and versionId together in client state instead of independently.
  3. If the version lives under another block, correct the path's promptBlockId to the owning block's id.
  4. Check for stale references after a block was recreated (new block id, orphaned old version ids).

Example fix

// before
getVersion(blockB.id, versionFromBlockA);
// after
const { versions } = await listVersions(blockB.id);
const v = versions.find(x => x.id === versionFromBlockA) ?? versions[0];
getVersion(blockB.id, v.id);
Defensive patterns

Strategy: validation

Validate before calling

const version = await fetchVersion(blockId, versionId); // may 404
// to pre-check ownership without the mismatch path:
const { versions } = await listVersions(blockId);
if (!versions.some(v => v.id === versionId)) throw new Error('versionId does not belong to this prompt block');

Type guard

function belongsToBlock(version: { blockId: string } | null | undefined, blockId: string): version is { blockId: string } {
  return !!version && version.blockId === blockId;
}

Try / catch

try {
  await fetchVersion(blockId, versionId);
} catch (e) {
  if (e.status === 404 && e.message.includes('not found for prompt block')) {
    // version belongs to another block; re-scope from that block's version list
  } else throw e;
}

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Related errors


AI-assisted analysis of mastra-ai/mastra@75dd419e61 (2026-08-30). Data as JSON: /api/errors/6e95051e820315d5. Report an issue: GitHub.