agentscope-java icon indicating copy to clipboard operation
agentscope-java copied to clipboard

[Bug]:PostgresAgentStateStore存储记忆有问题

Open BEN5890 opened this issue 4 months ago • 2 comments

private String slotSessionId(SandboxIsolationKey key) { IsolationScope scope = key.getScope(); return switch (scope) { case SESSION -> "sandbox/session/" + key.getValue(); case USER -> "sandbox/user/" + agentId + "/" + key.getValue(); case AGENT -> "sandbox/agent/" + agentId; case GLOBAL -> "sandbox/global"; }; } 和 protected void validateSessionId(String sessionId) { if (sessionId == null || sessionId.trim().isEmpty()) { throw new IllegalArgumentException("AgentStateStore ID cannot be null or empty"); } if (sessionId.contains("/") || sessionId.contains("\")) { throw new IllegalArgumentException("AgentStateStore ID cannot contain path separators"); } if (sessionId.length() > 255) { throw new IllegalArgumentException("AgentStateStore ID cannot exceed 255 characters"); } } 存在冲突

BEN5890 avatar Jul 20 '26 14:07 BEN5890

这个我来修一下 👍

根因:SessionSandboxStateStore.slotSessionId() 用 / 拼 slot id(如 sandbox/session/<id>),而 SQL store 的 validateSessionId 会拒绝 / 和 \,所以带隔离作用域时 sandbox 状态在 Postgres/MySQL 上持久化会必抛 IllegalArgumentException(不止 Postgres,MySQL 也一样)。

打算对齐 MysqlAgentStateStore#slotId 已经在用的 : 分隔符约定,把 / 换成 :,一处修好所有 store,并补一个覆盖四种作用域的回归测试。PR 马上提。

logicwu0 avatar Jul 21 '26 06:07 logicwu0

This is a valid bug. There's a conflict between slotSessionId() and validateSessionId() in PostgresAgentStateStore:

  • slotSessionId() generates paths like sandbox/session/{value} and sandbox/user/{agentId}/{value} — these contain / characters.
  • validateSessionId() explicitly rejects any sessionId containing / or \\.

This means any session ID generated by slotSessionId() would fail validation, making the store unusable for SESSION and USER isolation scopes.

Suggested fix: Either:

  1. Change validateSessionId() to allow / in paths (since they're internal storage keys, not user-facing IDs), or
  2. Use a different separator (e.g., : or __) in slotSessionId() that doesn't conflict with the validation rules.

oss-maintainer avatar Jul 28 '26 09:07 oss-maintainer