{"record":{"id":"d2e8bb624272c654","repo":"alibaba/spring-ai-alibaba","slug":"command-timed-out-restarting-session","errorCode":null,"errorMessage":"Command timed out, restarting session","messagePattern":"Command timed out, restarting session","errorType":"console","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"spring-ai-alibaba-agent-framework/src/main/java/com/alibaba/cloud/ai/graph/agent/tools/ShellSessionManager.java","lineNumber":529,"sourceCode":"\t\t\t} catch (IOException e) {\n\t\t\t\tthrow new RuntimeException(\"Failed to execute command\", e);\n\t\t\t}\n\t\t}\n\n\t\tprivate CommandResult collectOutput(String marker, long deadline, int maxOutputLines, Long maxOutputBytes) {\n\t\t\tList<String> lines = new ArrayList<>();\n\t\t\tint totalLines = 0;\n\t\t\tlong totalBytes = 0;\n\t\t\tboolean truncatedByLines = false;\n\t\t\tboolean truncatedByBytes = false;\n\t\t\tInteger exitCode = null;\n\t\t\tboolean timedOut = false;\n\n\t\t\twhile (true) {\n\t\t\t\tlong remaining = deadline - System.currentTimeMillis();\n\t\t\t\tif (remaining <= 0) {\n\t\t\t\t\ttimedOut = true;\n\t\t\t\t\tlog.warn(\"Command timed out, restarting session\");\n\t\t\t\t\trestart();\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\n\t\t\t\ttry {\n\t\t\t\t\tOutputLine outputLine = outputQueue.poll(remaining, TimeUnit.MILLISECONDS);\n\t\t\t\t\tif (outputLine == null) {\n\t\t\t\t\t\ttimedOut = true;\n\t\t\t\t\t\trestart();\n\t\t\t\t\t\tbreak;\n\t\t\t\t\t}\n\n\t\t\t\t\t// Skip EOF markers\n\t\t\t\t\tif (outputLine.content == null) {\n\t\t\t\t\t\tcontinue;\n\t\t\t\t\t}\n\n\t\t\t\t\tString line = outputLine.content;","sourceCodeStart":511,"sourceCodeEnd":547,"githubUrl":"https://github.com/alibaba/spring-ai-alibaba/blob/f82da0b50f35744c13968191be2b1cd2452ef550/spring-ai-alibaba-agent-framework/src/main/java/com/alibaba/cloud/ai/graph/agent/tools/ShellSessionManager.java#L511-L547","documentation":"collectOutput waited until the command deadline expired without the shell producing a final output line; it logs this warning, calls restart() to recreate the session, and returns with a timeout indication. The command is not allowed to run past the configured timeout.","triggerScenarios":"Running a long-running or blocking command (infinite loop, waiting on stdin, network hang) through execute so that no output line arrives before the deadline in outputQueue.poll.","commonSituations":"Agent asks the shell to run 'sleep 1000', an interactive command that blocks on input, or a command stuck on a network call exceeding the session's timeout setting.","solutions":["Increase the command timeout in the shell tool configuration if the workload legitimately needs longer.","Fix the command: add its own timeout (e.g. 'timeout 60 <cmd>'), redirect stdin from /dev/null for non-interactive use.","Split long work into smaller commands the agent can run sequentially.","Note the session was restarted; re-run any stateful setup (cd, exports) that the restart discarded."],"exampleFix":"// before\nshell.execute(\"npm install\");\n// after\nshell.execute(\"timeout 600 npm install\"); // plus raise configured timeout","handlingStrategy":"fallback","validationCode":null,"typeGuard":null,"tryCatchPattern":"if (result.timedOut()) { log.warn(\"Command {} timed out; session restarted\", cmd); /* re-init session state and retry with longer timeout */ }","preventionTips":["Wrap commands with their own 'timeout' so they terminate before the session deadline.","Avoid interactive commands; redirect stdin from /dev/null.","Set the session timeout above the slowest expected command.","Re-establish cwd/env after any timeout-triggered restart."],"tags":["timeout","shell","process"],"backgroundTag":"request-timeout","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"}