agentscope-ai / agentscope-ai/agentscope-java
[Bug]: Windows NTFS: session key containing ':' causes InvalidPathException in WorkspaceManager task/session file paths
- Vorherrschende Sprache
- Java
- Sterne
- 5.6k
- Forks
- 1.3k
- Ø Merge
- 4 T. 12 Std.
- Gemergte PRs (30 T.)
- 77
Beschreibung
**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
Beitragsleitfaden
Bewertung
Dieses Issue wurde noch nicht bewertet.