alibaba/spring-ai-alibaba · error · RuntimeException
Failed to delete experiment
Error message
Failed to delete experiment
What it means
Thrown by ExperimentServiceImpl.deleteById when experimentMapper.deleteById returns 0 rows affected after the existence and status checks passed. The library interprets a non-positive delete result as a failure to remove the row.
Source
Thrown at spring-ai-alibaba-admin/spring-ai-alibaba-admin-server-start/src/main/java/com/alibaba/cloud/ai/studio/admin/service/impl/ExperimentServiceImpl.java:321
if (id == null) {
throw new IllegalArgumentException("Experiment ID cannot be null");
}
// 检查实验是否存在
ExperimentDO experimentDO = experimentMapper.selectById(id);
if (experimentDO == null) {
throw new IllegalArgumentException("Experiment not found: " + id);
}
// 检查实验状态,运行中的实验不能删除
if (Objects.equals(experimentDO.getStatus(), ExperimentStatus.RUNNING.getCode())) {
throw new IllegalStateException("Cannot delete running experiment: " + id);
}
// 删除实验
int result = experimentMapper.deleteById(id);
if (result <= 0) {
throw new RuntimeException("Failed to delete experiment");
}
//
// // 删除相关的实验结果
// experimentResultMapper.deleteByExperimentId(id);
log.info("实验删除成功: {}", id);
}
@Override
public void restartById(Long id) {
//清理历史数据
experimentResultMapper.deleteByExperimentId(id);
//实验执行
ExperimentDO experimentDO = experimentMapper.selectById(id);
startExperimentExecution(experimentDO);
View on GitHub (pinned to f82da0b50f)
Solutions
- Handle it idempotently: if the record is already gone, treat the delete as successful instead of throwing
- Check database logs for lock/permission errors on the experiment table
- Retry the operation and re-check existence first
Example fix
// before
int result = experimentMapper.deleteById(id);
if (result <= 0) {
throw new RuntimeException("Failed to delete experiment");
}
// after
int result = experimentMapper.deleteById(id);
if (result <= 0 && experimentMapper.selectById(id) != null) {
throw new IllegalStateException("Failed to delete experiment: " + id);
} Defensive patterns
Strategy: retry
Validate before calling
if (experimentMapper.selectById(id) == null) return; // nothing to delete, already gone
Type guard
null
Try / catch
try { service.deleteById(id); } catch (RuntimeException e) { if (experimentMapper.selectById(id) == null) { /* treat as success */ } else { throw e; } } Prevention
- Treat delete of a missing row as idempotent success
- Investigate DB lock/permission errors in logs
- Avoid concurrent deletes of the same experiment
When it happens
Trigger: Concurrent deletion by another request between the selectById check and the delete; database write failure, lock timeout, or permission problem causing the DELETE to affect no rows.
Common situations: Two clients deleting the same experiment simultaneously; database connectivity/transaction issues in the admin server; soft-delete plugins intercepting the delete.
Related errors
- 数据项删除失败:
- Failed to create dataset version
- Failed to stop experiment
- Failed to fetch evaluator name for id: {}
- INVALID_PARAMS
AI-assisted analysis of alibaba/spring-ai-alibaba@f82da0b50f (2026-09-09).
Data as JSON: /api/errors/e98edb82973febfd.
Report an issue: GitHub.