alibaba/spring-ai-alibaba · error · IllegalStateException
Default Scheduled Agent Manager is shut down
Error message
Default Scheduled Agent Manager is shut down
What it means
DefaultScheduledAgentManager.registerTask throws IllegalStateException when the manager has been shut down (shutdown flag set). Once shutdown() was called, no new scheduled agent tasks may be registered — the manager's executor and state are no longer usable.
Source
Thrown at spring-ai-alibaba-graph-core/src/main/java/com/alibaba/cloud/ai/graph/scheduling/DefaultScheduledAgentManager.java:80
}
/**
* Get the task scheduler
*/
@Override
public TaskScheduler getTaskScheduler() {
return taskScheduler;
}
/**
* Register a new scheduled agent execution
* @param task the ScheduledAgentTask to register
* @return the unique Task ID assigned to this Task
*/
@Override
public String registerTask(ScheduledAgentTask task) {
if (shutdown) {
throw new IllegalStateException("Default Scheduled Agent Manager is shut down");
}
String taskId = String.format("agent-task-%s-%d", task.getName(), taskIdGenerator.getAndIncrement());
lock.writeLock().lock();
try {
activeTasks.put(taskId, task);
log.debug("Registered scheduled agent task: {}", taskId);
return taskId;
}
finally {
lock.writeLock().unlock();
}
}
/**
* Unregister a scheduled agent execution
* @param taskId the task ID to unregister
* @return true if the task was found and removed, false otherwise
*/View on GitHub (pinned to f82da0b50f)
Solutions
- Create a new DefaultScheduledAgentManager instance and register the task on it
- Reorder lifecycle so registration happens before shutdown (verify bean dependencies/creation order)
- Check whether shutdown() is being called unintentionally earlier in your code or tests
- Guard registration code with a manager.isShutdown()/liveness check and reinitialize if needed
Example fix
// before manager.shutdown(); String id = manager.registerTask(task); // throws // after manager.shutdown(); DefaultScheduledAgentManager manager2 = new DefaultScheduledAgentManager(); String id = manager2.registerTask(task);
Defensive patterns
Strategy: validation
Validate before calling
if (manager == null || manager.isShutdown()) {
manager = new DefaultScheduledAgentManager();
}
manager.registerTask(task); Type guard
boolean canRegister(DefaultScheduledAgentManager m) {
return m != null && !m.isShutdown();
} Try / catch
try {
manager.registerTask(task);
} catch (IllegalStateException e) {
if (String.valueOf(e.getMessage()).contains("shut down")) {
manager = new DefaultScheduledAgentManager();
manager.registerTask(task);
} else throw e;
} Prevention
- Register all tasks during application startup, before any shutdown path
- Align the manager lifecycle with the Spring context (destroy after all registration)
- In tests, create a fresh manager per test case
- Never cache a manager reference across a context restart
When it happens
Trigger: Calling registerTask(ScheduledAgentTask) after DefaultScheduledAgentManager.shutdown() (e.g. after Spring context close or explicit shutdown).
Common situations: Registering tasks in a @PostConstruct that runs after something already closed the manager; restarting tasks in tests after context shutdown; application shutdown hooks racing with task registration.
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
- Schedule already started
- Cannot create update map after mergeAll() has been called
- mergeAll() can only be called once
- Shell session not initialized. Call initialize() before exec
- Unexpected value:
AI-assisted analysis of alibaba/spring-ai-alibaba@f82da0b50f (2026-09-09).
Data as JSON: /api/errors/27e2b5566af981fd.
Report an issue: GitHub.