alibaba/spring-ai-alibaba · error · IllegalStateException
Cannot delete running experiment:
Error message
Cannot delete running experiment:
What it means
Thrown by ExperimentServiceImpl.deleteById when the experiment's stored status equals ExperimentStatus.RUNNING's code. The library forbids deleting experiments that are still running to avoid orphaning in-flight runs.
Solutions
- Stop the experiment (stop(id)) first, then delete it
- If the status is stale after a crash, reset it to STOPPED/FAILED manually or via an update before deleting
- Confirm the experiment truly finished and the status column was updated
Example fix
// before
experimentService.deleteById(id); // fails if RUNNING
// after
Experiment exp = experimentService.getById(id);
if (ExperimentStatus.RUNNING.getCode().equals(exp.getStatus())) {
experimentService.stop(id);
}
experimentService.deleteById(id); Defensive patterns
Strategy: try-catch
Validate before calling
Experiment exp = experimentService.getById(id); boolean deletable = exp != null && !ExperimentStatus.RUNNING.getCode().equals(exp.getStatus());
Type guard
boolean isDeletable(Experiment exp) { return exp != null && !ExperimentStatus.RUNNING.getCode().equals(exp.getStatus()); } Try / catch
try { service.deleteById(id); } catch (IllegalStateException e) { return ResponseEntity.status(409).body(e.getMessage()); } Prevention
- Stop running experiments before deleting
- Fix stale RUNNING statuses after crashes (reconcile on startup)
- Disable delete buttons in UI for running experiments
When it happens
Trigger: Calling deleteById on an experiment whose status column contains the RUNNING code — usually while it is actively executing or was left in RUNNING state after a crash.
Common situations: User tries to delete a currently running evaluation; a previous server restart left the status stuck at RUNNING so even finished experiments cannot be deleted; status never transitioned due to an earlier failure.
Understand the failure class
Background: "Invalid state transition" errors: "status must be X, actually Y", "already rejected/charging/uninstalled", "cannot ... while running" — what they mean when a library rejects your call — this error's family across 31 libraries.
Related errors
- AgentScopeRoutingAgent
- APP_COMPONENT_QUERYCONFIG_ERROR
- APP_COMPONENT_REFER_ERROR
- APP_NOT_FOUND
- Cannot delete published version:
AI-assisted analysis of alibaba/spring-ai-alibaba@f82da0b50f (2026-09-09).
Data as JSON: /api/errors/65378eef8687258f.
Report an issue: GitHub.
Appendix: 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:315
@Override
@Transactional
public void deleteById(Long id) {
log.info("删除实验: {}", id);
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);View on GitHub (pinned to f82da0b50f)