{"record":{"id":"27e2b5566af981fd","repo":"alibaba/spring-ai-alibaba","slug":"default-scheduled-agent-manager-is-shut-down","errorCode":null,"errorMessage":"Default Scheduled Agent Manager is shut down","messagePattern":"Default Scheduled Agent Manager is shut down","errorType":"exception","errorClass":"IllegalStateException","httpStatus":null,"severity":"error","filePath":"spring-ai-alibaba-graph-core/src/main/java/com/alibaba/cloud/ai/graph/scheduling/DefaultScheduledAgentManager.java","lineNumber":80,"sourceCode":"\t}\n\n\t/**\n\t * Get the task scheduler\n\t */\n\t@Override\n\tpublic TaskScheduler getTaskScheduler() {\n\t\treturn taskScheduler;\n\t}\n\n\t/**\n\t * Register a new scheduled agent execution\n\t * @param task the ScheduledAgentTask to register\n\t * @return the unique Task ID assigned to this Task\n\t */\n\t@Override\n\tpublic String registerTask(ScheduledAgentTask task) {\n\t\tif (shutdown) {\n\t\t\tthrow new IllegalStateException(\"Default Scheduled Agent Manager is shut down\");\n\t\t}\n\t\tString taskId = String.format(\"agent-task-%s-%d\", task.getName(), taskIdGenerator.getAndIncrement());\n\t\tlock.writeLock().lock();\n\t\ttry {\n\t\t\tactiveTasks.put(taskId, task);\n\t\t\tlog.debug(\"Registered scheduled agent task: {}\", taskId);\n\t\t\treturn taskId;\n\t\t}\n\t\tfinally {\n\t\t\tlock.writeLock().unlock();\n\t\t}\n\t}\n\n\t/**\n\t * Unregister a scheduled agent execution\n\t * @param taskId the task ID to unregister\n\t * @return true if the task was found and removed, false otherwise\n\t */","sourceCodeStart":62,"sourceCodeEnd":98,"githubUrl":"https://github.com/alibaba/spring-ai-alibaba/blob/f82da0b50f35744c13968191be2b1cd2452ef550/spring-ai-alibaba-graph-core/src/main/java/com/alibaba/cloud/ai/graph/scheduling/DefaultScheduledAgentManager.java#L62-L98","documentation":"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.","triggerScenarios":"Calling registerTask(ScheduledAgentTask) after DefaultScheduledAgentManager.shutdown() (e.g. after Spring context close or explicit shutdown).","commonSituations":"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.","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"],"exampleFix":"// before\nmanager.shutdown();\nString id = manager.registerTask(task); // throws\n// after\nmanager.shutdown();\nDefaultScheduledAgentManager manager2 = new DefaultScheduledAgentManager();\nString id = manager2.registerTask(task);","handlingStrategy":"validation","validationCode":"if (manager == null || manager.isShutdown()) {\n    manager = new DefaultScheduledAgentManager();\n}\nmanager.registerTask(task);","typeGuard":"boolean canRegister(DefaultScheduledAgentManager m) {\n    return m != null && !m.isShutdown();\n}","tryCatchPattern":"try {\n    manager.registerTask(task);\n} catch (IllegalStateException e) {\n    if (String.valueOf(e.getMessage()).contains(\"shut down\")) {\n        manager = new DefaultScheduledAgentManager();\n        manager.registerTask(task);\n    } else throw e;\n}","preventionTips":["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"],"tags":["illegal-state","shutdown","scheduling","lifecycle"],"backgroundTag":"invalid-state-transition","analyzedSha":"f82da0b50f35744c13968191be2b1cd2452ef550","analyzedAt":"2026-09-09T15:32:42.421Z","contentChangedAt":"2026-09-09T15:32:42.421Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}