mastra-ai/mastra · error · HTTPException

Failed to retrieve created version

Error message

Failed to retrieve created version

What it means

Thrown as HTTP 500 when createVersion on the scorer store returned (or resolved without) a usable versionId, and the follow-up getVersion(versionId) could not fetch the row that was supposedly created. This indicates the write did not land or the returned id is invalid — an internal consistency failure rather than user error.

Source

Thrown at packages/server/src/server/handlers/scorer-versions.ts:157

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

      const changedFields = calculateChangedFields(previousConfig, currentConfig);

      const { versionId } = await createVersionWithRetry(
        scorerStore as unknown as VersionedStoreInterface,
        scorerId,
        'scorerDefinitionId',
        currentConfig,
        changedFields,
        { changeMessage },
      );

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

      await enforceRetentionLimit(
        scorerStore as unknown as VersionedStoreInterface,
        scorerId,
        'scorerDefinitionId',
        scorer.activeVersionId,
      );

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

/**
 * GET /stored/scorers/:scorerId/versions/:versionId - Get a specific version

View on GitHub (pinned to 75dd419e61)

Solutions

  1. Retry the version creation request once to rule out transient consistency issues
  2. Check server logs/storage adapter logs for a failed transaction or underlying DB error
  3. Verify the backing database is healthy (connections, replication lag)
  4. If using a custom versioned store, ensure createVersion commits before returning and the id matches a readable row

Example fix

// before (custom store: returns id before commit)
const id = crypto.randomUUID(); queueInsert(row); return id;
// after
const id = crypto.randomUUID(); await this.db.insert(rows).values(row); return id;
Defensive patterns

Strategy: retry

Try / catch

async function createVersionWithRetry(scorerId: string, msg?: string, attempts = 2) {
  for (let i = 0; i < attempts; i++) {
    const res = await fetch(`/api/scorers/${scorerId}/versions`, { method: 'POST', body: JSON.stringify({ changeMessage: msg }) });
    if (res.ok) return res.json();
    const body = await res.json();
    if (res.status === 500 && body.message === 'Failed to retrieve created version' && i < attempts - 1) continue;
    throw body;
  }
}

Prevention

When it happens

Trigger: POST /api/scorers/{scorerId}/versions where the store's createVersion succeeds nominally but the subsequent getVersion(versionId) returns undefined — e.g. a store bug, a failed transaction that still returned an id, or replication lag/consistency issues in the backing database.

Common situations: Distributed databases with read-after-write inconsistency; concurrent deletes racing the create; buggy custom versioned store implementations; partial migration leaving the versions table unusable.

Related errors


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