mastra-ai/mastra · error · HTTPException

Version with id ${from} not found for prompt block ${promptB

Error message

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

What it means

Thrown when the 'from' version exists but belongs to a different prompt block than the one addressed in the URL (fromVersion.blockId !== promptBlockId). Masked as 404 to avoid disclosing cross-block data. It is a parent/child id mismatch, not a missing record.

Source

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

      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 promptBlock = await promptBlockStore.getById(promptBlockId);
      assertStoredResourceScope(promptBlock, await getStoredResourceScope(mastra, requestContext));

      const fromVersion = await promptBlockStore.getVersion(from);
      if (!fromVersion) {
        throw new HTTPException(404, { message: `Version with id ${from} not found` });
      }
      if (fromVersion.blockId !== promptBlockId) {
        throw new HTTPException(404, {
          message: `Version with id ${from} not found for prompt block ${promptBlockId}`,
        });
      }

      const toVersion = await promptBlockStore.getVersion(to);
      if (!toVersion) {
        throw new HTTPException(404, { message: `Version with id ${to} not found` });
      }
      if (toVersion.blockId !== promptBlockId) {
        throw new HTTPException(404, {
          message: `Version with id ${to} not found for prompt block ${promptBlockId}`,
        });
      }

      const fromConfig = extractConfigFromVersion(
        fromVersion as unknown as Record<string, unknown>,
        SNAPSHOT_CONFIG_FIELDS,
      );

View on GitHub (pinned to 75dd419e61)

Solutions

  1. Look up 'from' only from the target block's own version list before calling the route.
  2. Fix the promptBlockId path segment if the version's owner is the block you actually meant.
  3. Reset client caches so version selections always reset when the selected block changes.

Example fix

// before
const from = lastSelectedVersionId; // may belong to another block
// after
const versions = await get(`/prompt-blocks/${blockId}/versions`);
const from = versions.find(v => v.id === wantedId)?.id ?? versions[0].id;
Defensive patterns

Strategy: type-guard

Validate before calling

const versions = await getBlockVersions(promptBlockId);
if (!versions.some(v => v.id === from)) {
  throw new Error(`'from' version ${from} does not belong to block ${promptBlockId}`);
}

Type guard

function ownsVersion(version: { id: string; blockId: string } | undefined, promptBlockId: string): version is { id: string; blockId: string } {
  return !!version && version.blockId === promptBlockId;
}

Try / catch

try {
  await revertVersions(promptBlockId, from, to);
} catch (e) {
  if (e.status === 404 && e.message.includes('not found for prompt block')) {
    // mismatch: rebind 'from' to a version of this block
  }
  throw e;
}

Prevention

When it happens

Trigger: Diff/revert request pairing prompt block A in the path with a 'from' version that belongs to prompt block B.

Common situations: Building diff UIs that keep version ids from previously selected blocks, copy/paste mistakes across blocks, or clients caching (blockId, versionId) pairs inconsistently.

Related errors


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