You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[Bug]: ReActAgent slot key collides when userId contains '/' #3337
ReActAgent.slotKey(userId, sessionId) joins the two with /, so ("u1/a", "b") and ("u1", "a/b") both map to u1/a/b. The two identities then share the cached state, CAS versions and permission engine, the same-session call gate, and interrupt routing: getAgentState("u1", "a/b") can return the other identity's cached state, interrupt("u1", "a/b") can stop the other identity's call, and without an AgentStateStore both share one conversation.
It needs a userId containing / plus a matching second identity, so it is much rarer than #2475. Found while reviewing #3335.
To Reproduce
ReActAgentagent = ReActAgent.builder().name("asst").sysPrompt("hi").model(model).build();
AgentStatea = agent.getAgentState("u1/a", "b");
AgentStateb = agent.getAgentState("u1", "a/b");
// a == b: two different (userId, sessionId) pairs get the same cached AgentState
Expected behavior
Different (userId, sessionId) pairs never share a slot.
Possible fix: key the maps by a (userId, sessionId) record instead of a joined string, or escape the user part. Tests that read slotVersions reflectively with string keys (e.g. "u1/sessA") would need updating.
Category: bug | Status: Confirmed (verified against main @ 3a6baf6c)
The collision is real and the reported consequences hold up. ReActAgent.slotKey builds every per-slot map key as a plain string join:
// agentscope-core/src/main/java/io/agentscope/core/ReActAgent.java:397-400privatestaticStringslotKey(StringuserId, StringsessionId) {
Objects.requireNonNull(sessionId, "sessionId must not be null");
return (userId == null || userId.isBlank() ? "__anon__" : userId) + "/" + sessionId;
}
slotKey("u1/a", "b") == slotKey("u1", "a/b") == "u1/a/b", and the mapping is not injective. Nothing validates the id characters: RuntimeContext.Builder accepts arbitrary userId/sessionId, and JdbcAgentStateStore (lines 569-574) explicitly documents slash-containing slot ids as legitimate input — so this shape is reachable by design, not only by misuse.
Confirmed consequences (each structure is keyed by the same ambiguous string):
Shared cached state — stateCache (ReActAgent.java:286) via getAgentState(String, String) → computeIfAbsent (:4522-4538); activateSlotForContext also does stateCache.put(slot, loaded) (:681), so two identities overwrite each other's loaded state and out-of-call accessors return whichever loaded last.
Shared CAS versions + permission engine + call gate — slotVersions (:293, read as the CAS expected in saveAgentState:4770-4775) and permissionEngineCache (:302, populated :700-704 / :4715-4716) both collide, so ASK rules granted to one identity apply to the other; callSerializationKey (:727-737) routes both onto one FIFO gate in AgentBase.callGates (AgentBase.java:108, 374-397).
Cross-identity interrupt — interrupt(userId, sessionId, msg) (:963-964) → interruptRunning(slotKey(...)) → runningCalls.get(key) (AgentBase.java:212-220, registration at :329), so interrupt("u1", "a/b") can cancel the in-flight call of ("u1/a", "b").
No-store mode shares one conversation — activateSlotForContext (:683-696) returns a single AgentState (one history) per colliding key.
Additional consequence not in the report: cross-identity persistence corruption. saveStateToSession (:475-496) re-derives the identity from the joined key through SlotRef.parse (:402-410, splits on lastIndexOf('/')) and persistAgentStateCas (:535-573) writes with those parsed values, while loads use the true identity (:671-678). A call for ("u1", "a/b") therefore persists into the store slot of ("u1/a", "b"). This is silent cross-tenant data corruption on every call-path save (:1241, :1348, :1414, :4439) — the same failure mode as #2475, reachable via the userId side instead of the sessionId side.
Severity: high — cross-tenant conversation sharing, permission-rule leakage, cross-identity interrupt, and wrong-slot persistence. Not critical because it needs a /-containing userId (or a user literally named __anon__) with both colliding identities served by the same agent instance.
Coordination note: PR #3335 (open, ReActAgent.java + AgentStateStore.java + ReActAgentPerSessionStateTest.java, "persist agent state under the caller's identity", fixes #2475) already rewrites the persist path where consequence 5 lives; the earlier attempt PR #2476 was closed unmerged. Please don't land an independent fix for the persistence half here — it should build on #3335.
Suggested direction
Key the per-slot structures structurally (e.g. a record SlotId(String userId, String sessionId)) instead of a joined string; ThreadSessionManager.SessionKey (agui starter, :307 / :359) already shows this pattern, as does InMemoryAgentStateStore (two-level map, :192-198) and JsonFileAgentStateStore (escaped path segments, :287-288 / :398-405). If a string key must stay, make it unambiguous (length-prefix the user segment, or escape / and the __anon__ sentinel in userId), and drop the SlotRef.parse round-trip by carrying userId/sessionId explicitly instead of re-deriving them from the key (CallExecution has no identity fields today; that is the approach PR fix(#2475): store userId/sessionId directly on CallExecution instead of parsing slotKey #2476 proposed and fix(core): persist agent state under the caller's identity #3335 is taking).
Tests that read slotVersions reflectively with string keys need updating: ReActAgentPerSessionStateTest.java:97-112 and the literal "u1/sessA" keys at :662 / :667.
Open question for maintainers (blocking any PR here): the same joined-key pattern is repeated in the store layer — RedisAgentStateStore.java:450, JedisAgentStateStore.java:332, RedissonAgentStateStore.java:320 (user + "/" + session) and JdbcAgentStateStore.java:562, PostgresAgentStateStore.java:710, MysqlAgentStateStore.java:902 (':' separator), CosAgentStateStore.java:256, OssAgentStateStore.java:259 (object paths). Changing those key formats breaks already-persisted data. Should the fix be scoped to agentscope-core in-memory slots only (no migration), or extended to the store layer with a documented migration/compat path? We are holding off on generating a fix PR until that scope decision and #3335's outcome are known.
Hi, I'd like to work on this. Plan: stop keying by the joined string — key the agent-state cache, CAS versions, call gate and interrupt routing by a (userId, sessionId) record (or an escape that cannot collide, e.g. length-prefixed), and keep the persisted slot key format backward-compatible for existing stores. Tests asserting ("u1/a","b") != ("u1","a/b") across all the affected surfaces. PR coming shortly.
Closing as fixed by #3335 (merged): agent state is persisted under the caller's identity, handling / in userId/sessionId keys. The sibling report #2475 (slot key with / in sessionId) was closed by the same PR. Reopen if collisions persist.
Activity
oss-maintainer commentedon Sep 28, 2026
Issue Evaluation
Category:
bug| Status: Confirmed (verified againstmain@3a6baf6c)The collision is real and the reported consequences hold up.
ReActAgent.slotKeybuilds every per-slot map key as a plain string join:slotKey("u1/a", "b") == slotKey("u1", "a/b") == "u1/a/b", and the mapping is not injective. Nothing validates the id characters:RuntimeContext.Builderaccepts arbitraryuserId/sessionId, andJdbcAgentStateStore(lines 569-574) explicitly documents slash-containing slot ids as legitimate input — so this shape is reachable by design, not only by misuse.Confirmed consequences (each structure is keyed by the same ambiguous string):
stateCache(ReActAgent.java:286) viagetAgentState(String, String)→computeIfAbsent(:4522-4538);activateSlotForContextalso doesstateCache.put(slot, loaded)(:681), so two identities overwrite each other's loaded state and out-of-call accessors return whichever loaded last.slotVersions(:293, read as the CASexpectedinsaveAgentState:4770-4775) andpermissionEngineCache(:302, populated:700-704/:4715-4716) both collide, so ASK rules granted to one identity apply to the other;callSerializationKey(:727-737) routes both onto one FIFO gate inAgentBase.callGates(AgentBase.java:108,374-397).interrupt(userId, sessionId, msg)(:963-964) →interruptRunning(slotKey(...))→runningCalls.get(key)(AgentBase.java:212-220, registration at:329), sointerrupt("u1", "a/b")can cancel the in-flight call of("u1/a", "b").activateSlotForContext(:683-696) returns a singleAgentState(one history) per colliding key.Additional consequence not in the report: cross-identity persistence corruption.
saveStateToSession(:475-496) re-derives the identity from the joined key throughSlotRef.parse(:402-410, splits onlastIndexOf('/')) andpersistAgentStateCas(:535-573) writes with those parsed values, while loads use the true identity (:671-678). A call for("u1", "a/b")therefore persists into the store slot of("u1/a", "b"). This is silent cross-tenant data corruption on every call-path save (:1241,:1348,:1414,:4439) — the same failure mode as #2475, reachable via theuserIdside instead of thesessionIdside.Severity: high — cross-tenant conversation sharing, permission-rule leakage, cross-identity interrupt, and wrong-slot persistence. Not critical because it needs a
/-containinguserId(or a user literally named__anon__) with both colliding identities served by the same agent instance.Coordination note: PR #3335 (open,
ReActAgent.java+AgentStateStore.java+ReActAgentPerSessionStateTest.java, "persist agent state under the caller's identity", fixes #2475) already rewrites the persist path where consequence 5 lives; the earlier attempt PR #2476 was closed unmerged. Please don't land an independent fix for the persistence half here — it should build on #3335.Suggested direction
record SlotId(String userId, String sessionId)) instead of a joined string;ThreadSessionManager.SessionKey(agui starter,:307/:359) already shows this pattern, as doesInMemoryAgentStateStore(two-level map,:192-198) andJsonFileAgentStateStore(escaped path segments,:287-288/:398-405). If a string key must stay, make it unambiguous (length-prefix the user segment, or escape/and the__anon__sentinel inuserId), and drop theSlotRef.parseround-trip by carryinguserId/sessionIdexplicitly instead of re-deriving them from the key (CallExecutionhas no identity fields today; that is the approach PR fix(#2475): store userId/sessionId directly on CallExecution instead of parsing slotKey #2476 proposed and fix(core): persist agent state under the caller's identity #3335 is taking).slotVersionsreflectively with string keys need updating:ReActAgentPerSessionStateTest.java:97-112and the literal"u1/sessA"keys at:662/:667.Open question for maintainers (blocking any PR here): the same joined-key pattern is repeated in the store layer —
RedisAgentStateStore.java:450,JedisAgentStateStore.java:332,RedissonAgentStateStore.java:320(user + "/" + session) andJdbcAgentStateStore.java:562,PostgresAgentStateStore.java:710,MysqlAgentStateStore.java:902(':'separator),CosAgentStateStore.java:256,OssAgentStateStore.java:259(object paths). Changing those key formats breaks already-persisted data. Should the fix be scoped toagentscope-corein-memory slots only (no migration), or extended to the store layer with a documented migration/compat path? We are holding off on generating a fix PR until that scope decision and #3335's outcome are known.Automated evaluation by github-manager-bot
refactor(core): key session slots by a SlotId record instead of an en…
aiyili commentedon Oct 21, 2026
Hi, I'd like to work on this. Plan: stop keying by the joined string — key the agent-state cache, CAS versions, call gate and interrupt routing by a (userId, sessionId) record (or an escape that cannot collide, e.g. length-prefixed), and keep the persisted slot key format backward-compatible for existing stores. Tests asserting ("u1/a","b") != ("u1","a/b") across all the affected surfaces. PR coming shortly.
Merge origin/main; rebuild slot-key fix as a minimal LF diff
Merge origin/main; rebuild slot-key fix as a minimal LF diff
juruoO-o commentedon Nov 12, 2026
Closing as fixed by #3335 (merged): agent state is persisted under the caller's identity, handling
/in userId/sessionId keys. The sibling report #2475 (slot key with/in sessionId) was closed by the same PR. Reopen if collisions persist.