alibaba/spring-ai-alibaba · warning
Failed to delete: {}
Error message
Failed to delete: {} What it means
During deleteDirectory (invoked from doCleanup), an individual file or directory could not be deleted by Files.delete; the warning logs the offending path with the IOException and continues walking, so cleanup is best-effort rather than atomic.
Source
Thrown at spring-ai-alibaba-agent-framework/src/main/java/com/alibaba/cloud/ai/graph/agent/tools/ShellSessionManager.java:353
* Check if a session is registered for the given threadId. Package-private for testing.
*/
static boolean isSessionInRegistry(String threadId) {
return SESSION_REGISTRY.containsKey(threadId);
}
public Long getMaxOutputBytes() {
return maxOutputBytes;
}
private void deleteDirectory(Path directory) throws IOException {
if (Files.exists(directory)) {
try (var stream = Files.walk(directory)) {
stream.sorted(Comparator.reverseOrder())
.forEach(path -> {
try {
Files.delete(path);
} catch (IOException e) {
log.warn("Failed to delete: {}", path, e);
}
});
}
}
}
/**
* Persistent shell session that executes commands sequentially.
* <p>This is a static nested class to avoid implicit reference to the outer
* {@link ShellSessionManager} instance, which could cause memory leaks when
* sessions are stored in the static {@link #SESSION_REGISTRY}.</p>
*/
private static class ShellSession {
private static final Logger log = LoggerFactory.getLogger(ShellSession.class);
private static final String DONE_MARKER_PREFIX = "__LC_SHELL_DONE__";
private final Path workspace;
private final List<String> command;View on GitHub (pinned to f82da0b50f)
Solutions
- Ensure the shell process for the session is stopped/terminated before doCleanup runs.
- Check filesystem permissions on the session working directory and its children.
- Avoid sharing one scratch directory across concurrent sessions.
- If deletion is advisory only, treat this as non-fatal; otherwise retry cleanup after a short delay.
Defensive patterns
Strategy: try-catch
Validate before calling
if (!Files.isWritable(directory)) log.warn("Cleanup will likely fail on {}", directory); Try / catch
try { cleanup(); } catch (Exception e) { log.warn("Session cleanup incomplete; residual files may remain", e); } Prevention
- Terminate the shell process before deleting its working directory.
- Use one scratch directory per session, never shared.
- On Windows, watch for file locking; delay deletion until handles are released.
When it happens
Trigger: Files.walk cleanup encountering a locked file (process still holding it open), a file deleted concurrently, or OS-level permission denial on some path under the session working directory.
Common situations: Deleting a shell session temp dir while the spawned shell process still runs; Windows file locking; read-only mounts; other sessions sharing the same scratch directory.
Understand the failure class
Background: "failed to write file", "Could not save figure", "Error saving remote file" — file write failed: causes and fixes across languages and libraries — this error's family across 38 libraries.
Related errors
- Failed to delete JAR files from working directory
- Failed to delete temporary directory: {}
- Got error when creating files
- Got error when creating files
- Failed to create temp directory for converter
AI-assisted analysis of alibaba/spring-ai-alibaba@f82da0b50f (2026-09-09).
Data as JSON: /api/errors/77e2566631a62477.
Report an issue: GitHub.