Skip to content

[Bug]: SessionSandboxStateStore slot IDs contain path separators, JdbcAgentStateStore rejects sandbox state writes #3231

Closed

Description

@chcodex

Environment

agentscope-harness develop-21b4781fdb (same code on current main)
state store JdbcAgentStateStore via JdbcDistributedStore.create(dataSource).agentStateStore()
scenario HarnessAgent (project mode) with E2B sandbox filesystem

Problem

After switching the Harness stateStore from JsonFileAgentStateStore to JDBC, every agent run ends with two warnings and the sandbox resume state is never persisted:

WARN SandboxManager - [sandbox] Failed to persist sandbox state:
  Failed to save sandbox state for SandboxIsolationKey{scope=SESSION, value='01M31AQP7A24X0Y4A12RKADD5P'}
Caused by: java.lang.IllegalArgumentException: Session ID cannot contain path separators
    at io.agentscope.extensions.jdbc.state.JdbcAgentStateStore.validateSlotId(JdbcAgentStateStore.java:548)
    at io.agentscope.extensions.jdbc.state.JdbcAgentStateStore.save(JdbcAgentStateStore.java:126)
    at io.agentscope.harness.agent.sandbox.SessionSandboxStateStore.save(SessionSandboxStateStore.java:60)

Root cause

Two framework pieces disagree on the sessionId contract:

  1. SessionSandboxStateStore.slotSessionId packs the isolation key into a slash-separated sessionId:
case SESSION -> "sandbox/session/" + key.getValue();
case USER -> "sandbox/user/" + agentId + "/" + key.getValue();
  1. JdbcAgentStateStore.validateSlotId rejects any slot containing / or \\:
if (slotId.contains("/") || slotId.contains("\\\\")) {
    throw new IllegalArgumentException("Session ID cannot contain path separators");
}

The path-separator restriction only makes sense for file-backed stores (JsonFileAgentStateStore splices the sessionId into a directory path); a SQL column has no such limitation. But since the restriction exists, the sandbox store — a core in-house caller — violates it, so sandbox resume state can never be persisted to any JDBC backend. File-backed stores happen to work only because / doubles as a directory separator there.

Expected

Either:

  1. Encode the isolation key in slotSessionId (e.g. URL-encode or join with a safe delimiter) so generated slot IDs satisfy the documented store contract; or
  2. Relax validateSlotId for backends where the slot is an opaque column value (JDBC/Redis), keeping the strict check only in path-based stores.

Option 1 is safer (keeps cross-backend slot compatibility); option 2 fixes only JDBC.

Workaround (app side)

We wrapped the JDBC store in a decorator that URL-encodes (userId, sessionId) before delegating (bijective, plain ULIDs unaffected). Works, but this really belongs in the framework.

Activity

  1. chcodex commented on Sep 21, 2026

    @chcodex
    ContributorAuthor

    @shanhongyu Hi, you are listed as the author of JdbcDistributedStore / JdbcAgentStateStore in the javadoc. Could you take a look at this incompatibility when you have a moment? The sandbox state store (core caller) generates slash-separated slot IDs that validateSlotId rejects, so sandbox resume state can never reach any JDBC backend. Details and two fix options are in the issue body above. Thanks!

  2. oss-maintainer commented on Sep 21, 2026

    @oss-maintainer
    Collaborator

    Issue Evaluation

    Category: bug | Status: Confirmed

    Verified against current main (8ca0080ed). All claims reproduce at the code level:

    • SessionSandboxStateStore.slotSessionId (agentscope-harness/.../sandbox/SessionSandboxStateStore.java:84-92) always emits slash-separated slot IDs (sandbox/session/…, sandbox/user/<agentId>/…).
    • JdbcAgentStateStore.validateSlotId (agentscope-extensions-jdbc/.../JdbcAgentStateStore.java:582-592) throws IllegalArgumentException for any / or \.
    • No intermediate path sanitizes the slot ID (SandboxLifecycleMiddleware.releaseForCall → SandboxManager.persistState → SessionSandboxStateStore.save), so every JDBC-backed sandbox state write fails and is only logged as a warning — sandbox resume state is silently never persisted.

    Impact: JdbcAgentStateStore users with harness sandbox enabled; Redis / Mongo / JPA / OSS / COS backends are unaffected.
    Severity: High (functional blocker; silent data-loss of sandbox resume state).

    Fix direction: of the two options in the report, relaxing validateSlotId in the JDBC store (option 2) is the smaller, non-breaking change — slotId is an opaque prepared-statement column value there, and option 1 would alter persisted slot identities for file/Redis backends. The path-separator guard only makes sense for path-based stores. Maintainer input welcome on whether the guard should additionally move into JsonFileAgentStateStore-style stores explicitly.


    Automated evaluation by github-manager-bot

  3. added
    bug
    area/core/memory
    area/ext/memory
    on Sep 21, 2026
  4. aiyili commented on Sep 21, 2026

    @aiyili
    Contributor

    Hi, I would like to work on this issue, following the evaluation's fix direction (option 2):

    • Relax the path-separator guard in JdbcAgentStateStore.validateSlotId — the slotId is only ever used as an opaque prepared-statement bind value there, while SessionSandboxStateStore legitimately generates slash-separated slot IDs (sandbox/session/..., sandbox/user/<agentId>/...).
    • Keep the remaining validations (null/blank, length, etc.) unchanged.
    • Add a regression test persisting a sandbox-shaped slot ID (sandbox/session/<ULID>) end-to-end through the store's save path.
    • Whether the guard should move explicitly into path-backed stores (JsonFileAgentStateStore-style) I will leave as the open maintainer question noted in the evaluation.

    PR coming shortly.

  5. added 2 commits that reference this issue on Sep 21, 2026
    b88f2db
    1824cbc
  6. added a commit that references this issue on Sep 21, 2026
    7d10efc
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

    area/core/memoryarea/ext/memorybug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions