Repository navigation
Description
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:
- Run an agent on Windows (NTFS filesystem) with a session that triggers task record persistence or session log writing
- Start a conversation that goes through
CompactionMiddlewareorwriteTaskRecord - 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:
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: fix(harness): normalize Windows list_files paths #1892 and fix(skill): Remove Windows reserved characters from FileSystemSkillRepository source (#947) #1031 already addressed Windows path compatibility in other areas
Activity
ma19881117 commentedon Sep 2, 2026
Update — root cause on our side (please read before triaging)
We traced the failure further and found the immediate trigger was on the caller side:
sessionIdfrom a session registry, with afallback of
orElse(sessionKey)when the registry entry is missing (our/newreset removed the entry while a stale route mapping survived).
agent:{agentId}:main:main-{uuid})as
RuntimeContext.sessionId, which of course contains:.main-{uuid}), so we nolonger hit the crash.
That said, we believe there is still a legitimate robustness gap in
AgentScope-Java, which is why we're keeping this issue open rather than closing it:
RuntimeContext.sessionIdhas no documented character constraint, yet it isused verbatim in file paths (
agents/{agentId}/tasks/{sessionId}.json,sessions/{sessionId}.log.jsonl, ...).<>:"/\|?*) in an id surfaces as a rawInvalidPathExceptionfrom deep inside the workspace layer, with no hint thatthe caller-supplied id is the problem.
Suggestion — either would help:
WorkspaceManager(e.g. replace reserved charswith
-), orcharacter set.
wylovelyi commentedon Sep 3, 2026
Opened #2952. Sanitizes the segment (and keeps the existing path-traversal guard) wherever it is concatenated into a file name in , using a helper that replaces Windows/NTFS reserved characters () with . This is symmetric: both writers () and readers () go through the same , so a file written with a reserved-char id is still readable. Mirrors the merged precedent #1031/#2921 (small, focus)*. Reproduced the original on Windows during local verification; added 2 unit tests (reserved chars replaced, ordinary ids unchanged). Verified with and the full test suite (895 tests, 0 failures).
wylovelyi commentedon Sep 3, 2026
Opened #2952.
Sanitizes the
sessionIdsegment (and keeps the existing path-traversal guard) wherever it is concatenated into a file name inWorkspaceManager, using asafeSegment()helper that replaces Windows/NTFS reserved characters (<>:"/\|?*) with-.This is symmetric: both writers (
SessionTranscriptWriter) and readers (SessionSearchTool) go through the sameresolve*, so a file written with a reserved-char id is still readable. Mirrors the merged precedent #1031 / #2921 (small, focused change). Reproduced the originalInvalidPathExceptionon Windows during local verification; added 2 unit tests (reserved chars replaced, ordinary ids unchanged). Verified withspotless:checkand the fullagentscope-harnesstest suite (895 tests, 0 failures).oss-maintainer commentedon Sep 13, 2026
Issue Evaluation
Category:
bug| Status: ConfirmedVerified against
main@39cd304a.Root cause: session/task identifiers are interpolated into workspace-relative paths with no filename-character sanitization, so a
sessionIdcontaining:is rejected by the Windows path parser.agentscope-harness/src/main/java/io/agentscope/harness/agent/workspace/WorkspaceManager.java:619-621—taskRecordPath()returnsAGENTS_DIR + "/" + agentId + "/" + TASKS_DIR + "/" + sessionId + ".json"verbatim; same raw interpolation inresolveSessionFile(:347-348),resolveSessionContextFile(:352-354),resolveSessionLogFile(:358-359).WorkspaceManager.java:926-932→AbstractFilesystem.java:178-188— the only guard isvalidatePath(), which rejects..traversal segments and nothing else;normalizeRelativePath()(:915-924) handles backslashes/leading slashes only.writeTaskRecord()(:476) →taskRecordPath()(:619) →persistTaskMap()(:671) →writeUtf8WorkspaceRelative()(:715,:720) →writeLocalFile()(:883) →workspace.resolve(...)→WindowsPathParser.parse→InvalidPathException.HarnessAgentBuilderSupport.sanitizeIdentifier()(:699-704) strips/ \ whitespace ctrlbut not:, soderiveChildSessionId()(:678-691) propagates the parent's colons; a caller-supplieddefaultSessionId(HarnessAgent.java:1651-1653) is unrestricted. Gateway ids are safe by accident (SessionIdUtils.deterministicHash()hex, :42-51).Impact: on Windows/NTFS any run that persists a task record or session log with a colon-bearing session key throws and aborts the turn (
WorkspaceTaskRepository.persistRecord():820-822,CompactionMiddlewareviaConversationCompactor, transcript writers). Non-Windows users are unaffected but share the same unsanitized key space. Severity: high.Suggested fix (repo has prior art for exactly this): add a
safeSegment()helper inWorkspaceManagermodelled onJsonFileAgentStateStore.safeSegment()(agentscope-core/src/main/java/io/agentscope/core/state/JsonFileAgentStateStore.java:398-405—^[a-zA-Z0-9_\-.]+$allowlist with Base64-URL fallback) and apply it toagentId/sessionIdat the four call sites above; widensanitizeIdentifier()(:703) to[/\\\s\p{Cntrl}:*?"<>|], matchingGitSkillRepository.java:375. Two design notes before a PR: (1) the Base64 fallback changes on-disk file names for affected ids, so existing Windows workloads would not find their old task records — an offset/migration note or a:→-replacement (theGitSkillRepositoryshape, lossy but reversible-looking) should be chosen explicitly; (2) collision behaviour —:→-is not injective, whereas the Base64 path is, which is why the state-store helper exists.We will not auto-generate a PR until the preferred encoding shape is confirmed. Reply with the option you want (allowlist+Base64 like
safeSegment(), or simple:*?"<>|→-replacement) — maintainer/approvealso works.Automated evaluation by github-manager-bot
oss-maintainer commentedon Sep 13, 2026
Status update — an open PR already implements a fix for this; our PR-generation offer is withdrawn
A search-based duplicate sweep (the queue is 265 open PRs, so a title-only list scan is not sufficient) found:
fix(harness): sanitize session ids used in workspace file names(@wylovelyi, OPEN, non-draft,MERGEABLE, opened 2026-09-03) statesCloses #2937and touches exactly the file named in the root cause above —agentscope-harness/.../workspace/WorkspaceManager.java— plus a newWorkspaceManagerPathSafetyTest.java. It was independently reproduced on Windows 11 / JDK 17.Mapping to the two options in our comment above: #2952 implements the replacement shape (
UNSAFE_SEGMENT_CHARS = [<>:"/\\|?*]→-, applied at the foursessionId-becomes-filename sites), not the allowlist+Base64 shape fromJsonFileAgentStateStore.safeSegment().One concrete review point for #2952 that follows from the analysis above and is not visible in its diff:
:→-is not injective, sosess:1andsess-1map to the same file name and would silently share/overwrite a task record. The Base64 fallback insafeSegment()exists precisely to avoid that. Either a collision suffix or a documented "ids must be unique after sanitization" note onRuntimeContext.sessionIdwould close this; that is a review comment on #2952, not a reason to file a competing PR.Also still unaddressed by #2952 (out of its scope, flagged for the record):
HarnessAgentBuilderSupport.sanitizeIdentifier()(:699-704) does not strip:, soderiveChildSessionId()(:678-691) keeps propagating parent colons upstream of the workspace layer.We are not filing a PR for this issue. #2952 stays the active path and currently only needs maintainer review.
Automated by github-manager-bot
fix(harness): percent-encode reserved characters in session-id file n…