{"record":{"id":"09885ef01c793263","repo":"mastra-ai/mastra","slug":"cannot-delete-the-active-version-activate-a-diffe-09885e","errorCode":null,"errorMessage":"Cannot delete the active version. Activate a different version first.","messagePattern":"Cannot delete the active version\\. Activate a different version first\\.","errorType":"http","errorClass":"HTTPException","httpStatus":400,"severity":"warning","filePath":"packages/server/src/server/handlers/scorer-versions.ts","lineNumber":418,"sourceCode":"\n      const scorer = await scorerStore.getById(scorerId);\n      if (!scorer) {\n        throw new HTTPException(404, { message: `Scorer with id ${scorerId} not found` });\n      }\n      assertStoredResourceScope(scorer, await getStoredResourceScope(mastra, requestContext));\n\n      const version = await scorerStore.getVersion(versionId);\n      if (!version) {\n        throw new HTTPException(404, { message: `Version with id ${versionId} not found` });\n      }\n      if (version.scorerDefinitionId !== scorerId) {\n        throw new HTTPException(404, {\n          message: `Version with id ${versionId} not found for scorer ${scorerId}`,\n        });\n      }\n\n      if (scorer.activeVersionId === versionId) {\n        throw new HTTPException(400, {\n          message: 'Cannot delete the active version. Activate a different version first.',\n        });\n      }\n\n      await scorerStore.deleteVersion(versionId);\n\n      // Clear the editor cache so subsequent requests see the updated config\n      mastra.getEditor()?.scorer.clearCache(scorerId);\n\n      return {\n        success: true,\n        message: `Version ${version.versionNumber} deleted successfully`,\n      };\n    } catch (error) {\n      return handleError(error, 'Error deleting scorer version');\n    }\n  },\n});","sourceCodeStart":400,"sourceCodeEnd":436,"githubUrl":"https://github.com/mastra-ai/mastra/blob/75dd419e613fe9c39f846ffc500716141b74fda6/packages/server/src/server/handlers/scorer-versions.ts#L400-L436","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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."],"exampleFix":"// before\nawait fetch(`/api/stored/scorers/${scorerId}/versions/${versionId}`, { method: 'DELETE' }); // 400 if active\n// after\nif (scorer.activeVersionId === versionId) {\n  await fetch(`/api/stored/scorers/${scorerId}/versions/${fallbackVersionId}/activate`, { method: 'POST' });\n}\nawait fetch(`/api/stored/scorers/${scorerId}/versions/${versionId}`, { method: 'DELETE' });","handlingStrategy":"validation","validationCode":"const scorer = await fetch(`/api/stored/scorers`).then(r => r.json()).then(r => r.results.find(s => s.id === scorerId));\nif (scorer.activeVersionId === versionId) throw new Error('Activate a different version before deleting this one');","typeGuard":"function isDeletable(versionId: string, scorer: { activeVersionId: string | null }): boolean {\n  return scorer.activeVersionId !== versionId;\n}","tryCatchPattern":"try {\n  await deleteScorerVersion(scorerId, versionId);\n} catch (e) {\n  if (e.status === 400 && /Cannot delete the active version/.test(e.message)) {\n    const other = (await listVersions(scorerId)).find(v => v.id !== versionId);\n    await activateVersion(scorerId, other.id);\n    return deleteScorerVersion(scorerId, versionId);\n  }\n  throw e;\n}","preventionTips":["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"],"tags":["http-400","validation","scorers","versions"],"backgroundTag":"protected-resource-state","analyzedSha":"75dd419e613fe9c39f846ffc500716141b74fda6","analyzedAt":"2026-08-30T00:15:31.844Z","schemaVersion":2},"datasetVersion":"2026-08-30T03:17:51.788Z"}