Skip to content

fix(core): pass the builder permission context to the legacy state loader on 2.0.x (#2888) - #4452

Merged
juruoO-o merged 2 commits into
agentscope-ai:2.0.xfrom
aiyili:fix/legacy-permission-context-20x
Dec 1, 2026
Merged

juruoO-o merged 2 commits into
agentscope-ai:2.0.xfrom
aiyili:fix/legacy-permission-context-20x

Conversation

@aiyili

@aiyili aiyili commented Nov 27, 2026 •

Copy link
Copy Markdown
Contributor

Fixes #2888 on 2.0.x, where the call still exists. main no longer has it.

Problem

A session that only has v1 keys (memory_messages / toolkit_activeGroups) is reconstructed by LegacyStateLoader on first load. Legacy keys carry no permission context, and ReActAgent.loadOrCreateAgentStateForSlot calls the three-argument overload, which passes null. The reconstructed state therefore gets the default context although the builder configured one, mode and rules alike. The fresh-state branch of the same method does use the builder's context.

On 2.0.x this shows through getAgentState(userId, sessionId) and getAgentState(ctx), which return the state as loaded. A call() is not affected: activateSlotForContext applies the builder's context the first time it activates a slot.

Fix

permCtx is forwarded to the four-argument overload, the shape of #2886 and #3221. Nothing else changes: a state that already exists is still loaded as it was persisted.

Tests

ReActAgentLegacyPermissionContextTest (new, 4 cases). LegacyStateLoaderTest already covers the loader's four-argument overload; nothing covered the caller.

Case Unmodified 2.0.x With the fix
the legacy session is reconstructed with the builder's context (mode and deny rule), keeping the conversation and the tool groups fails: expected ... mode=BYPASS, denyRules={shell=[...]} but was mode=DEFAULT with no rules passes
without a builder context the default is kept passes passes
an existing state keeps its own context passes passes
a call() applies the builder's context on first activation passes passes

The last two pass before and after on purpose: they bound the change. A variant of the fix that also overwrites the context of an existing state fails the third case (expected: <EXPLORE> but was: <BYPASS>).

Verification

The full agentscope-core suite was run before and after the change on Windows and in a Linux container. The failing lists are identical; the only difference is the 4 added tests.

Environment Before After Failing before and after
Windows 3237 run, 0 F + 3 E 3241 run, 0 F + 3 E 2 × DangerousPathBypassTest.symlink* (no symlink privilege), SkillBoxTest$UploadContainment.preservesLegacyNamesWithRelativeNonNormalizedWorkDirectory
Linux container (maven:3.9-eclipse-temurin-17) 3242 run, 0 F + 0 E 3246 run, 0 F + 0 E none

CI. The first run of this PR was red for reasons that lay in the base branch: since the backports of 2026-11-13, every PR against 2.0.x failed the Windows job, at first in agentscope-core, and had its Ubuntu job cancelled. Those causes are fixed by #4454 and #4461, merged into 2.0.x on 2026-11-27; the harness part went in with #4461. The current run of this PR, on top of them, is green on both systems. The local before/after runs recorded above were made before the fixes existed, which is why the "before" column lists failures that the branch no longer has.

…ader on 2.0.x (agentscope-ai#2888)

`ReActAgent.loadOrCreateAgentStateForSlot` reconstructed a session that only has v1 keys through the three-argument `LegacyStateLoader.loadFromLegacySessionWithPresence`, which passes no permission context. Legacy keys carry none, so the state got the default context although the builder had configured one, while the fresh-state branch of the same method used the builder's. On `2.0.x` this shows through `getAgentState(...)`, which returns the state as loaded; a `call()` applies the builder's context again on first activation.

Forwards `permCtx` to the four-argument overload, the shape of agentscope-ai#2886 and agentscope-ai#3221. An existing state is still loaded as it was persisted.

Test: `ReActAgentLegacyPermissionContextTest` covers the legacy path with and without a builder context, an existing state, and the first activation of a call.
@codecov

codecov Bot commented Nov 27, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@juruoO-o
juruoO-o merged commit eb5d08e into agentscope-ai:2.0.x Dec 1, 2026
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants