Skip to content

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

Open

Description

@ma19881117

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:

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

This is safe because:

Activity

  1. added
    bug
    on Sep 2, 2026
  2. ma19881117 commented on Sep 2, 2026

    @ma19881117
    Author

    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:

    • Our gateway resolves the runtime sessionId from a session registry, with a
      fallback of orElse(sessionKey) when the registry entry is missing (our /new
      reset removed the entry while a stale route mapping survived).
    • That fallback passed the full sessionKey (agent:{agentId}:main:main-{uuid})
      as RuntimeContext.sessionId, which of course contains :.
    • We've fixed our fallback to pass the real session id (main-{uuid}), so we no
      longer 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:

    1. RuntimeContext.sessionId has no documented character constraint, yet it is
      used verbatim in file paths (agents/{agentId}/tasks/{sessionId}.json,
      sessions/{sessionId}.log.jsonl, ...).
    2. On Windows/NTFS, any reserved character (<>:"/\|?*) in an id surfaces as a raw
      InvalidPathException from deep inside the workspace layer, with no hint that
      the caller-supplied id is the problem.

    Suggestion — either would help:

    • sanitize file-name segments in WorkspaceManager (e.g. replace reserved chars
      with -), or
    • validate ids early and fail fast with a clear message documenting the allowed
      character set.
  3. wylovelyi commented on Sep 3, 2026

    @wylovelyi

    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).

  4. wylovelyi commented on Sep 3, 2026

    @wylovelyi

    Opened #2952.

    Sanitizes the sessionId segment (and keeps the existing path-traversal guard) wherever it is concatenated into a file name in WorkspaceManager, using a safeSegment() helper that replaces Windows/NTFS reserved characters (<>:"/\|?*) with -.

    This is symmetric: both writers (SessionTranscriptWriter) and readers (SessionSearchTool) go through the same resolve*, so a file written with a reserved-char id is still readable. Mirrors the merged precedent #1031 / #2921 (small, focused change). Reproduced the original InvalidPathException on Windows during local verification; added 2 unit tests (reserved chars replaced, ordinary ids unchanged). Verified with spotless:check and the full agentscope-harness test suite (895 tests, 0 failures).

  5. oss-maintainer commented on Sep 13, 2026

    @oss-maintainer
    Collaborator

    Issue Evaluation

    Category: bug | Status: Confirmed

    Verified against main @ 39cd304a.

    Root cause: session/task identifiers are interpolated into workspace-relative paths with no filename-character sanitization, so a sessionId containing : is rejected by the Windows path parser.

    • agentscope-harness/src/main/java/io/agentscope/harness/agent/workspace/WorkspaceManager.java:619-621 — taskRecordPath() returns AGENTS_DIR + "/" + agentId + "/" + TASKS_DIR + "/" + sessionId + ".json" verbatim; same raw interpolation in resolveSessionFile (:347-348), resolveSessionContextFile (:352-354), resolveSessionLogFile (:358-359).
    • WorkspaceManager.java:926-932 → AbstractFilesystem.java:178-188 — the only guard is validatePath(), which rejects .. traversal segments and nothing else; normalizeRelativePath() (:915-924) handles backslashes/leading slashes only.
    • Crash path matches your stack trace: writeTaskRecord() (:476) → taskRecordPath() (:619) → persistTaskMap() (:671) → writeUtf8WorkspaceRelative() (:715,:720) → writeLocalFile() (:883) → workspace.resolve(...) → WindowsPathParser.parse → InvalidPathException.
    • Not only user-supplied ids are at risk: HarnessAgentBuilderSupport.sanitizeIdentifier() (:699-704) strips / \ whitespace ctrl but not :, so deriveChildSessionId() (:678-691) propagates the parent's colons; a caller-supplied defaultSessionId (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, CompactionMiddleware via ConversationCompactor, 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 in WorkspaceManager modelled on JsonFileAgentStateStore.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 to agentId/sessionId at the four call sites above; widen sanitizeIdentifier() (:703) to [/\\\s\p{Cntrl}:*?"<>|], matching GitSkillRepository.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 (the GitSkillRepository shape, 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 /approve also works.


    Automated evaluation by github-manager-bot

  6. oss-maintainer commented on Sep 13, 2026

    @oss-maintainer
    Collaborator

    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 #2952 fix(harness): sanitize session ids used in workspace file names (@wylovelyi, OPEN, non-draft, MERGEABLE, opened 2026-09-03) states Closes #2937 and touches exactly the file named in the root cause above — agentscope-harness/.../workspace/WorkspaceManager.java — plus a new WorkspaceManagerPathSafetyTest.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 four sessionId-becomes-filename sites), not the allowlist+Base64 shape from JsonFileAgentStateStore.safeSegment().

    One concrete review point for #2952 that follows from the analysis above and is not visible in its diff: :→- is not injective, so sess:1 and sess-1 map to the same file name and would silently share/overwrite a task record. The Base64 fallback in safeSegment() exists precisely to avoid that. Either a collision suffix or a documented "ids must be unique after sanitization" note on RuntimeContext.sessionId would 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 :, so deriveChildSessionId() (: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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions