Skip to content

fix(core): preserve permission context when loading legacy v1 session state - #2769

Merged
jujn merged 4 commits into
agentscope-ai:mainfrom
Letter2025:fix/legacy-permctx
Aug 26, 2026
Merged

jujn merged 4 commits into
agentscope-ai:mainfrom
Letter2025:fix/legacy-permctx

Conversation

@Letter2025

Copy link
Copy Markdown
Contributor

fix(core): preserve permission context when loading legacy v1 session state

Closes #2768

Problem

ReActAgent.loadOrCreateAgentStateForSlot(...) loads a session's state in this order:

  1. a new-format agent_state entry from the AgentStateStore,
  2. else v1 legacy session keys (memory_messages / toolkit_activeGroups) via
    LegacyStateLoader,
  3. else a fresh state built from the caller's parameters (freshState(permCtx, ...)).

Step 2 is leaky: LegacyStateLoader reconstructs the AgentState with only the legacy
conversation context (+ tool activation groups) and never sets permissionContext. Legacy
keys cannot carry one — the concept did not exist in v1 — so the reconstructed state silently
falls back to the default DEFAULT permission mode. This happens even though the caller
explicitly supplied a non-default permission context (for example BYPASS) that step 3 would
have preserved, and even though permCtx is already in scope at the call site.

Affected sessions: any session that still has v1-era keys but no new-format agent_state yet —
typically the first turn after a 1.x → 2.0 migration. The caller-configured permission mode is
silently downgraded, weakening permission semantics.

Change

  • LegacyStateLoader.loadFromLegacySession(...) / loadFromLegacySessionWithPresence(...):
    new overloads accepting a PermissionContextState; when non-null it is attached to the
    reconstructed AgentState. The existing overloads are kept and delegate with null, so
    behaviour for callers without a specific permission context is unchanged.
  • ReActAgent.loadOrCreateAgentStateForSlot(...): pass the in-scope permCtx into the legacy
    load, exactly like freshState already does.

Tests

LegacyStateLoaderTest (5 tests):

  • supplied permission context is preserved (presence + non-presence variants);
  • no permission context keeps the default mode (old overload behaviour);
  • legacy messages and tool activation groups survive reconstruction alongside the permission
    context;
  • no legacy keys reports found=false.

Checklist

  • Conventional Commit message
  • Unit tests included
  • Backward compatible, no API breakage (old overloads kept)
  • Full build verified locally (blocked by sandbox; CI runs mvn clean verify on Linux + Windows)

… state

LegacyStateLoader reconstructs an AgentState from v1 session keys
(memory_messages / toolkit_activeGroups) and never set a permissionContext, so a
session with legacy keys and no new-format agent_state silently downgraded to the
default permission mode even when the caller supplied a non-default context
(for example BYPASS). Add overloads accepting a PermissionContextState and pass the
in-scope permCtx from ReActAgent.loadOrCreateAgentStateForSlot, matching what
freshState already does. Backward compatible: the old overloads keep the default
behaviour when no permission context is supplied.
@codecov

codecov Bot commented Aug 18, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@AgentScopeJavaBot AgentScopeJavaBot added bug Something isn't working area/core/agent Agent runtime, pipeline, hooks, plan labels Aug 19, 2026
@dailingtao

Copy link
Copy Markdown
Contributor

LGTM. The legacy v1 session loading path now correctly preserves the caller-supplied permission context while keeping the existing overload behavior backward compatible. The tests cover permission propagation, default behavior, and preservation of legacy session data.

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

Labels

area/core/agent Agent runtime, pipeline, hooks, plan bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

ReActAgent legacy-state load silently drops permissionContext (downgrades to DEFAULT)

4 participants