Repository navigation
Description
Issue draft — A3: LegacyStateLoader drops permission context (silent downgrade)
Title: ReActAgent legacy-state load silently drops permissionContext (downgrades to DEFAULT)
Body:
Problem
ReActAgent.loadOrCreateAgentStateForSlot(...) loads a session's state in this order:
- a new-format
agent_stateentry from theAgentStateStore, - else v1 legacy session keys (
memory_messages/toolkit_activeGroups) via
LegacyStateLoader, - else a fresh state built from the caller's parameters.
Step 2 is leaky: LegacyStateLoader.loadFromLegacySessionWithPresence(...) reconstructs the
AgentState with only context(msgs) (+ tool context), and never sets permissionContext.
Legacy keys carry no permission context (the concept did not exist in v1), so the reconstructed
state falls back to the default DEFAULT mode — even when the caller explicitly supplied a
non-default permission context (for example BYPASS) that freshState(permCtx, ...) (step 3)
would have preserved, and even though permCtx is already in scope at the call site.
Concrete trace (on main):
// ReActAgent.loadOrCreateAgentStateForSlot
AgentState fresh = freshState(permCtx, agentId, userId, sessionId, initialActiveToolGroups); // has permCtx
...
LegacyStateLoader.LegacyLoadResult legacy =
LegacyStateLoader.loadFromLegacySessionWithPresence(stateStore, userId, sessionId); // permCtx NOT passed
if (legacy.found()) {
return new VersionedState<>(legacy.state(), version); // permission mode silently DEFAULT
}// LegacyStateLoader.loadFromLegacySessionWithPresence
AgentState.Builder builder = AgentState.builder().context(msgs); // no .permissionContext(...)Impact: any session that has v1-era keys but no new-format agent_state yet (typical for the
first post-upgrade turn) silently loses its caller-configured permission mode. This can weaken
permission semantics (e.g. a pre-seeded BYPASS session degrading to DEFAULT).
Proposed fix
LegacyStateLoader.loadFromLegacySession(...)/...WithPresence(...): add overloads accepting
aPermissionContextState; attach it to the reconstructedAgentStatewhen non-null (old
overloads kept for backward compatibility).ReActAgent.loadOrCreateAgentStateForSlot(...): pass the in-scopepermCtxinto the legacy
load, exactly likefreshStatealready does.
Behavior for callers without a specific permission context is unchanged.
Environment
- agentscope-java
main(2.0.3-SNAPSHOT); reproduced against 2.0.1 sources too (same path)
Metadata
Metadata
Assignees
Labels
Type
Projects
- StatusShow more project fieldsIn progress
Activity
fix(core): preserve permission context when loading legacy v1 session…
fix(core): keep slot identity while loading legacy v1 session state (a…