mastra-ai/mastra · error · HTTPException

Failed to retrieve created version

Error message

Failed to retrieve created version

What it means

After createVersionWithRetry inserts a new version snapshot, the handler immediately re-reads it with getVersion(versionId). A null result means the write reported success but the row is not readable back — an internal consistency failure, surfaced as a 500. It usually indicates a storage-layer bug, eventual-consistency lag, or a silent write failure swallowed by the retry helper.

Source

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

      }
      const previousConfig = latestVersion
        ? extractConfigFromVersion(latestVersion as unknown as Record<string, unknown>, SNAPSHOT_CONFIG_FIELDS)
        : null;

      const changedFields = calculateChangedFields(previousConfig, currentConfig);

      const { versionId } = await createVersionWithRetry(
        promptBlockStore as unknown as VersionedStoreInterface,
        promptBlockId,
        'blockId',
        currentConfig,
        changedFields,
        { changeMessage },
      );

      const version = await promptBlockStore.getVersion(versionId);
      if (!version) {
        throw new HTTPException(500, { message: 'Failed to retrieve created version' });
      }

      await enforceRetentionLimit(
        promptBlockStore as unknown as VersionedStoreInterface,
        promptBlockId,
        'blockId',
        promptBlock.activeVersionId,
      );

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

/**
 * GET /stored/prompt-blocks/:promptBlockId/versions/:versionId - Get a specific version

View on GitHub (pinned to 75dd419e61)

Solutions

  1. Retry the version-creation request; transient replication/consistency lag often resolves on retry.
  2. Verify the version actually persisted by listing versions (GET /stored/prompt-blocks/:id/versions) and report a storage-adapter bug if it is missing despite a success response.
  3. Check for concurrent automation (retention cleanup, restore/activate) racing version creation and serialize those operations.
  4. Upgrade the storage adapter; if reproducible, file a bug with the adapter and @mastra/server versions.

Example fix

// before
await createVersion(id, config); // assumes success
// after
const created = await createVersion(id, config);
const check = await getVersion(created.versionId);
if (!check) throw new Error('version write not confirmed, retrying');
Defensive patterns

Strategy: retry

Try / catch

try {
  await createVersion(blockId, config);
} catch (e) {
  if (e?.message === 'Failed to retrieve created version') {
    await sleep(250); // read-your-write lag
    await createVersion(blockId, config); // one bounded retry
  } else throw e;
}

Prevention

When it happens

Trigger: POST /stored/prompt-blocks/:promptBlockId/versions where createVersionWithRetry returns a versionId but promptBlockStore.getVersion(versionId) returns null — e.g. the insert failed silently, the retry helper fabricated an id, or the store's getVersion reads from a different table/connection.

Common situations: Storage adapter bugs after schema migrations; read-replica lag on hosted Postgres where the write went to primary but read hit a lagging replica; concurrent retention-limit deletion removing the version between insert and read.

Related errors


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