{"record":{"id":"c07901b03c981149","repo":"alibaba/spring-ai-alibaba","slug":"shelltoolagenthook-no-shelltool2-injected-skippi-c07901","errorCode":null,"errorMessage":"ShellToolAgentHook: No ShellTool2 injected, skipping cleanup","messagePattern":"ShellToolAgentHook: No ShellTool2 injected, skipping cleanup","errorType":"console","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"spring-ai-alibaba-agent-framework/src/main/java/com/alibaba/cloud/ai/graph/agent/hook/shelltool/ShellToolAgentHook.java","lineNumber":102,"sourceCode":"\n\t\tlog.info(\"ShellToolAgentHook: Initializing shell session before agent execution\");\n\n\t\ttry {\n\t\t\tsessionManager.initialize(config);\n\t\t\tlog.info(\"Shell session initialized successfully\");\n\t\t} catch (Exception e) {\n\t\t\tlog.error(\"Failed to initialize shell session\", e);\n\t\t\tthrow new RuntimeException(\"Failed to initialize shell session\", e);\n\t\t}\n\n\t\treturn CompletableFuture.completedFuture(new HashMap<>());\n\t}\n\n\t@Override\n\tpublic CompletableFuture<Map<String, Object>> afterAgent(OverAllState state, RunnableConfig config) {\n\t\tShellSessionManager sessionManager = getSessionManager();\n\t\tif (sessionManager == null) {\n\t\t\tlog.warn(\"ShellToolAgentHook: No ShellTool2 injected, skipping cleanup\");\n\t\t\treturn CompletableFuture.completedFuture(new HashMap<>());\n\t\t}\n\n\t\tlog.info(\"ShellToolAgentHook: Cleaning up shell session after agent execution\");\n\n\t\ttry {\n\t\t\tsessionManager.cleanup(config);\n\t\t\tlog.info(\"Shell session cleaned up successfully\");\n\t\t} catch (Exception e) {\n\t\t\tlog.error(\"Failed to cleanup shell session\", e);\n\t\t\t// Don't throw exception in cleanup to avoid masking original errors\n\t\t}\n\n\t\treturn CompletableFuture.completedFuture(new HashMap<>());\n\t}\n\n\t@Override\n\tpublic String getName() {","sourceCodeStart":84,"sourceCodeEnd":120,"githubUrl":"https://github.com/alibaba/spring-ai-alibaba/blob/f82da0b50f35744c13968191be2b1cd2452ef550/spring-ai-alibaba-agent-framework/src/main/java/com/alibaba/cloud/ai/graph/agent/hook/shelltool/ShellToolAgentHook.java#L84-L120","documentation":"ShellToolAgentHook.afterAgent logs this warning and skips cleanup when no ShellTool2 (and thus no ShellSessionManager) is injected. Since no session was ever created in beforeAgent, there is nothing to clean up; the hook returns an empty state delta. Persistent symptom of a mis-wired hook rather than an error in itself.","triggerScenarios":"Same root cause as the beforeAgent warning: injectTool() was never called or failed with a non-ShellTool2 callback, so getSessionManager() is null when afterAgent runs after agent execution.","commonSituations":"Same as 1030 — hook registered without ShellTool2; also appears whenever an agent graph runs to completion after the earlier 'skipping initialization' warning.","solutions":["Inject a ShellTool2 into the hook via the builder and rebuild the agent","Confirm the registered ToolCallback is extractable as ShellTool2","If no shell session management is wanted, remove the hook entirely to avoid log noise","If sessions were created out-of-band, clean them up manually or via a lifecycle manager since this hook will not"],"exampleFix":"// before\nAgent agent = Agent.builder().hooks(ShellToolAgentHook.builder().build()).build();\n// after\nAgent agent = Agent.builder()\n    .tools(shellTool2)\n    .hooks(ShellToolAgentHook.builder().shellTool2(shellTool2).build())\n    .build();","handlingStrategy":"validation","validationCode":"if (getSessionManager() == null && cleanupRequired) { throw new IllegalStateException(\"Shell session cleanup requires injected ShellTool2\"); }","typeGuard":"boolean hookIsWired(ShellToolAgentHook hook) { return hook.getSessionManager() != null; }","tryCatchPattern":null,"preventionTips":["Fix the injection at build time — this warning is always downstream of the beforeAgent one","Unregister the hook if shell tooling is not used, to keep logs clean","Track session lifecycle externally if sessions are created outside this hook"],"tags":["shell","shelltool","hook","cleanup","missing-dependency"],"backgroundTag":"missing-dependency","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"}