mastra-ai/mastra · warning · HTTPException
Cannot delete the active version. Activate a different versi
Error message
Cannot delete the active version. Activate a different version first.
What it means
The delete-version endpoint refuses to delete the scorer's currently active version. If scorer.activeVersionId equals the requested versionId, a 400 with this message is returned. This invariant guarantees a scorer always has a usable active configuration.
Source
Thrown at packages/server/src/server/handlers/scorer-versions.ts:418
const scorer = await scorerStore.getById(scorerId);
if (!scorer) {
throw new HTTPException(404, { message: `Scorer with id ${scorerId} not found` });
}
assertStoredResourceScope(scorer, await getStoredResourceScope(mastra, requestContext));
const version = await scorerStore.getVersion(versionId);
if (!version) {
throw new HTTPException(404, { message: `Version with id ${versionId} not found` });
}
if (version.scorerDefinitionId !== scorerId) {
throw new HTTPException(404, {
message: `Version with id ${versionId} not found for scorer ${scorerId}`,
});
}
if (scorer.activeVersionId === versionId) {
throw new HTTPException(400, {
message: 'Cannot delete the active version. Activate a different version first.',
});
}
await scorerStore.deleteVersion(versionId);
// Clear the editor cache so subsequent requests see the updated config
mastra.getEditor()?.scorer.clearCache(scorerId);
return {
success: true,
message: `Version ${version.versionNumber} deleted successfully`,
};
} catch (error) {
return handleError(error, 'Error deleting scorer version');
}
},
});View on GitHub (pinned to 75dd419e61)
Solutions
- Activate a different version first: POST /stored/scorers/:scorerId/versions/:otherVersionId/activate, then delete the original version.
- Create a new version snapshot and activate it, then delete the unwanted version.
- Filter the active version out of bulk-delete lists client-side by comparing against scorer.activeVersionId.
- If no alternative version is acceptable, delete and recreate the whole scorer instead of deleting its active version.
Example fix
// before
await fetch(`/api/stored/scorers/${scorerId}/versions/${versionId}`, { method: 'DELETE' }); // 400 if active
// after
if (scorer.activeVersionId === versionId) {
await fetch(`/api/stored/scorers/${scorerId}/versions/${fallbackVersionId}/activate`, { method: 'POST' });
}
await fetch(`/api/stored/scorers/${scorerId}/versions/${versionId}`, { method: 'DELETE' }); Defensive patterns
Strategy: validation
Validate before calling
const scorer = await fetch(`/api/stored/scorers`).then(r => r.json()).then(r => r.results.find(s => s.id === scorerId));
if (scorer.activeVersionId === versionId) throw new Error('Activate a different version before deleting this one'); Type guard
function isDeletable(versionId: string, scorer: { activeVersionId: string | null }): boolean {
return scorer.activeVersionId !== versionId;
} Try / catch
try {
await deleteScorerVersion(scorerId, versionId);
} catch (e) {
if (e.status === 400 && /Cannot delete the active version/.test(e.message)) {
const other = (await listVersions(scorerId)).find(v => v.id !== versionId);
await activateVersion(scorerId, other.id);
return deleteScorerVersion(scorerId, versionId);
}
throw e;
} Prevention
- Check scorer.activeVersionId before queuing a version for deletion
- Always keep at least one alternative version available before deleting
- Exclude the active version from bulk-delete lists
When it happens
Trigger: DELETE /stored/scorers/:scorerId/versions/:versionId where versionId is the scorer's activeVersionId — e.g. trying to delete the version currently powering the scorer's published behavior.
Common situations: Cleanup scripts deleting 'old' versions that turn out to still be active; users attempting to remove the only/current version in the UI; deleting the version the scorer fell back to after a rollback.
Related errors
- bad request: ${responseText}
- Invalid agent-builder action: ${actionId}. Valid actions are
- Invalid agent-builder action: ${actionId}
- Cannot delete the active version. Activate a different versi
- Agent ID is required
AI-assisted analysis of mastra-ai/mastra@75dd419e61 (2026-08-30).
Data as JSON: /api/errors/09885ef01c793263.
Report an issue: GitHub.