alibaba/spring-ai-alibaba · warning
Command timed out, restarting session
Error message
Command timed out, restarting session
What it means
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.
Source
Thrown at spring-ai-alibaba-agent-framework/src/main/java/com/alibaba/cloud/ai/graph/agent/tools/ShellSessionManager.java:529
} catch (IOException e) {
throw new RuntimeException("Failed to execute command", e);
}
}
private CommandResult collectOutput(String marker, long deadline, int maxOutputLines, Long maxOutputBytes) {
List<String> lines = new ArrayList<>();
int totalLines = 0;
long totalBytes = 0;
boolean truncatedByLines = false;
boolean truncatedByBytes = false;
Integer exitCode = null;
boolean timedOut = false;
while (true) {
long remaining = deadline - System.currentTimeMillis();
if (remaining <= 0) {
timedOut = true;
log.warn("Command timed out, restarting session");
restart();
break;
}
try {
OutputLine outputLine = outputQueue.poll(remaining, TimeUnit.MILLISECONDS);
if (outputLine == null) {
timedOut = true;
restart();
break;
}
// Skip EOF markers
if (outputLine.content == null) {
continue;
}
String line = outputLine.content;View on GitHub (pinned to f82da0b50f)
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.
Example fix
// before
shell.execute("npm install");
// after
shell.execute("timeout 600 npm install"); // plus raise configured timeout Defensive patterns
Strategy: fallback
Try / catch
if (result.timedOut()) { log.warn("Command {} timed out; session restarted", cmd); /* re-init session state and retry with longer timeout */ } Prevention
- 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.
When it happens
Trigger: 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.
Common situations: 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.
Understand the failure class
Background: Request timed out: what client-side request timeouts mean across libraries (Request timed out, TIMED_OUT, APITimeoutError) — this error's family across 39 libraries.
- Timeouts: ETIMEDOUT, deadlines, and hung requests — what actually expires when a request times out.
Related errors
- Startup command failed:
- Failed to initialize shell session
- Failed to restart shell session
- Shell session is not running
- Failed to execute command
AI-assisted analysis of alibaba/spring-ai-alibaba@f82da0b50f (2026-09-09).
Data as JSON: /api/errors/d2e8bb624272c654.
Report an issue: GitHub.