{"record":{"id":"6bde131156514bcf","repo":"alibaba/spring-ai-alibaba","slug":"failed-to-delete-item-from-file-system","errorCode":null,"errorMessage":"Failed to delete item from file system","messagePattern":"Failed to delete item from file system","errorType":"exception","errorClass":"RuntimeException","httpStatus":null,"severity":"error","filePath":"spring-ai-alibaba-graph-core/src/main/java/com/alibaba/cloud/ai/graph/store/stores/FileSystemStore.java","lineNumber":137,"sourceCode":"\t}\n\n\t@Override\n\tpublic boolean deleteItem(List<String> namespace, String key) {\n\t\tvalidateDeleteItem(namespace, key);\n\n\t\tlock.writeLock().lock();\n\t\ttry {\n\t\t\tPath itemPath = createItemPath(namespace, key);\n\t\t\tif (Files.exists(itemPath)) {\n\t\t\t\tFiles.delete(itemPath);\n\t\t\t\t// Clean up empty directories\n\t\t\t\tcleanupEmptyDirectories(itemPath.getParent());\n\t\t\t\treturn true;\n\t\t\t}\n\t\t\treturn false;\n\t\t}\n\t\tcatch (Exception e) {\n\t\t\tthrow new RuntimeException(\"Failed to delete item from file system\", e);\n\t\t}\n\t\tfinally {\n\t\t\tlock.writeLock().unlock();\n\t\t}\n\t}\n\n\t@Override\n\tpublic StoreSearchResult searchItems(StoreSearchRequest searchRequest) {\n\t\tvalidateSearchItems(searchRequest);\n\n\t\tlock.readLock().lock();\n\t\ttry {\n\t\t\tList<StoreItem> allItems = getAllItems();\n\n\t\t\t// Apply filters\n\t\t\tList<StoreItem> filteredItems = allItems.stream()\n\t\t\t\t.filter(item -> matchesSearchCriteria(item, searchRequest))\n\t\t\t\t.collect(Collectors.toList());","sourceCodeStart":119,"sourceCodeEnd":155,"githubUrl":"https://github.com/alibaba/spring-ai-alibaba/blob/f82da0b50f35744c13968191be2b1cd2452ef550/spring-ai-alibaba-graph-core/src/main/java/com/alibaba/cloud/ai/graph/store/stores/FileSystemStore.java#L119-L155","documentation":"FileSystemStore.deleteItem wraps any exception during file deletion in a RuntimeException('Failed to delete item from file system'). The store deletes the JSON file backing a store item and then cleans up now-empty parent directories, all under a write lock. Any I/O or security failure in that sequence is rethrown with the original cause attached.","triggerScenarios":"store.deleteItem(namespace, key) is called and Files.delete/cleanupEmptyDirectories throws: file locked by another process, read-only filesystem, insufficient permissions, or an IOException while walking/deleting parent dirs.","commonSituations":"Deploying on read-only container filesystems; another process (backup, antivirus) holding the JSON file open; running under a user lacking write permission on the store root; disk errors.","solutions":["Inspect getCause() of the RuntimeException to see the underlying IOException","Check write permissions on the store root directory and the item file","Ensure no other process locks files under the store root","Point the store root to a writable path via configuration"],"exampleFix":"// before\nstore.deleteItem(List.of(\"agents\"), \"agent-1\");\n// after\ntry {\n    store.deleteItem(List.of(\"agents\"), \"agent-1\");\n} catch (RuntimeException e) {\n    log.error(\"delete failed\", e.getCause());\n}","handlingStrategy":"try-catch","validationCode":"java.nio.file.Path root = Path.of(storeRoot);\nif (!Files.isWritable(root)) throw new IllegalStateException(\"store root not writable\");","typeGuard":null,"tryCatchPattern":"try {\n    store.deleteItem(namespace, key);\n} catch (RuntimeException e) {\n    logger.error(\"delete failed: {}\", e.getCause() == null ? e : e.getCause());\n}","preventionTips":["Run the app as a user with write access to the store root","Exclude the store directory from backup/AV file locking","Check getCause() before deciding on retry vs fail"],"tags":["filesystem","io","store"],"backgroundTag":"file-delete-failed","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"}