agentscope-ai / agentscope-ai/agentscope-java

[Bug]: Windows NTFS: session key containing ':' causes InvalidPathException in WorkspaceManager task/session file paths

Đang mở
#2,937 3 bình luận 0 reaction 0 người được giao Xem trên GitHub
bug
Ngôn ngữ chính
Java
Star
5.6k
Fork
1.3k
Merge trung bình
4 ngày 12 giờ
Pull request đã merge (30 ngày)
77

Mô tả

**Describe the bug**

On Windows (NTFS), `WorkspaceManager` throws `InvalidPathException` when constructing file paths for task records and session logs. The session key contains colons (`:`), which is a reserved character in NTFS filenames and therefore illegal in file paths on Windows.

**To Reproduce**
Steps to reproduce the behavior:

1. Run an agent on Windows (NTFS filesystem) with a session that triggers task record persistence or session log writing
2. Start a conversation that goes through `CompactionMiddleware` or `writeTaskRecord`
3. See error — the agent crashes with `InvalidPathException`

**Expected behavior**

File paths should be sanitized before being used on Windows. The agent should continue functioning without crashing, regardless of the session key format.

**Error messages**

```
java.nio.file.InvalidPathException: Illegal char <:> at index 70: admin/agents/uca-admin-user-guided-chatbi-app_xxx/tasks/agent:9ce59443-f70a-4941-8aa9-ec8d62a78663:main:main-58045a8f-4720-4757-9685-e5bde8acf539.json
at java.base/sun.nio.fs.WindowsPathParser.normalize(WindowsPathParser.java:182)
at java.base/sun.nio.fs.WindowsPathParser.parse(WindowsPathParser.java:154)
at java.base/sun.nio.fs.WindowsPathParser.parse(WindowsPathParser.java:138)
at java.base/sun.nio.fs.WindowsPathParser.parse(WindowsPathParser.java:45)
at java.base/sun.nio.fs.WindowsPath.parse(WindowsPath.java:92)
...
at io.agentscope.harness.agent.workspace.WorkspaceManager.writeTaskRecord(WorkspaceManager.java:456)
```

**Environment (please complete the following information):**

- AgentScope-Java Version: 2.0.1
- Java Version: 21
- OS: Windows 10 (NTFS)

**Additional context**

**Root cause:** Session keys use `:` as a hierarchical separator (e.g., `agent:{uuid}:main:main-{uuid}`). This format is valid as an in-memory key but cannot be used directly as a filename on Windows NTFS, where `:` is a reserved character (used for alternate data streams).

The following methods in `WorkspaceManager` construct file paths using the raw session key:

| Method | Path Pattern |
|--------|-------------|
| `taskRecordPath()` | `agents/{agentId}/tasks/{sessionId}.json` |
| `resolveSessionFile()` | `agents/{agentId}/sessions/{sessionId}.json` |
| `resolveSessionContextFile()` | `agents/{agentId}/sessions/{sessionId}.jsonl` |
| `resolveSessionLogFile()` | `agents/{agentId}/sessions/{sessionId}.log.jsonl` |

**Suggested fix:** Add a filename sanitization utility and apply it in all four path constructors:

```java
static String sanitizeFileName(String sessionId) {
return sessionId == null ? null : sessionId.replace(':', '-');
}
```

This is safe because:
- The sanitized filename is only used for storage; the in-memory session key is unchanged
- Both read and write paths go through the same sanitization, so they remain consistent
- Linux/macOS are unaffected (`-` is valid in POSIX filenames)
- Precedent: #1892 and #1031 already addressed Windows path compatibility in other areas

Hướng dẫn đóng góp

Mở hướng dẫn đóng góp

Đánh giá

Issue này chưa được đánh giá.

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.