Repository navigation
Conversation
… state ReActAgent.loadOrCreateAgentStateForSlot forwards the caller's permCtx on the fresh-state path, but its legacy-state path called the 3-arg LegacyStateLoader.loadFromLegacySessionWithPresence overload, which passes null and silently downgrades a configured permission mode (e.g. BYPASS) to DEFAULT. This re-introduces the regression fixed in agentscope-ai#2769 / agentscope-ai#2886 after agentscope-ai#2760 rewrote the method. Forward permCtx through the existing 4-arg overload so legacy v1 sessions keep the caller-configured permission context. Re-adds the regression test removed by agentscope-ai#2760. Closes agentscope-ai#2888 Signed-off-by: wylovelyi <[email protected]>
oss-maintainer
left a comment
There was a problem hiding this comment.
Summary
One-line forwarding of the caller's PermissionContextState into the legacy v1 session load path — the fix itself is correct and well targeted at #2888, and the permCtx overload it calls is already on main. Two things block it right now, both visible in CI: the new test file's license header is malformed (Check License fails) and the new sessionId assertion fails because LegacyStateLoader never sets sessionId/userId on the reconstructed state (build (ubuntu-latest) fails). Fix the header and either forward the slot identity or scope the test down, and this is good to go.
Findings
- [Critical]
agentscope-core/src/test/java/io/agentscope/core/agent/ReActAgentLegacyPermissionContextTest.java:6— license header missing the trailingat, failsCheck License. - [Critical]
...ReActAgentLegacyPermissionContextTest.java:79— fails in CI:LegacyStateLoader.loadFromLegacySessionWithPresencedoes not setsessionId/userId, so the migrated state gets a random id. - [Info]
agentscope-core/src/main/java/io/agentscope/core/ReActAgent.java:440— permission-context forwarding verified correct againstLegacyStateLoader.java:113-133.
Verification seen
license/clais green, so CLA is signed; CI runs on head6958aa38showCheck Licenseandbuild (ubuntu-latest)failing for the two reasons above.- The second test (
existingV2State_winsOverBuilderPermissionContext) is a nice touch — it pins that an existing v2 state is not clobbered by the builder template.
Automated review by github-manager-bot
| * | ||
| * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| * you may not use this file except in compliance with the License. | ||
| * You may obtain a copy of the License |
There was a problem hiding this comment.
[Critical] The license header is malformed — line 6 is missing the trailing at (You may obtain a copy of the License → should be You may obtain a copy of the License at). This is what makes the Check License job fail on this PR; please copy the exact header from a neighbouring file (e.g. ReActAgentHitlTest.java) or run license-eye header fix locally.
| PermissionMode.BYPASS, | ||
| state.getPermissionContext().getMode(), | ||
| "builder-supplied permission context must survive legacy v1 session loading"); | ||
| assertEquals( |
There was a problem hiding this comment.
[Critical] This assertion fails in CI (build (ubuntu-latest)): expected: <session-legacy-perm> but was: <92536d6e...>. The test is right, the production code is not: LegacyStateLoader.loadFromLegacySessionWithPresence(...) builds the state with AgentState.builder().context(msgs) and never calls .sessionId(...)/.userId(...), so AgentState falls back to newHex() for sessionId. That means the legacy migration path returns a state whose identity does not match the (userId, sessionId) slot it was loaded for — a second regression next to the permission-context one this PR fixes.
Suggested direction (either is fine, but the PR must be green):
- Forward the slot identity here too, e.g. pass
sessionId/userId(or the whole slot) into the legacy loader and set them on the builder — consistent withfreshState(permCtx, agentId, userId, sessionId, ...), which does set them; or - If you prefer to keep this PR to the one-line permission fix, drop these two identity assertions and open a follow-up issue so the
sessionIdloss is tracked separately.
| LegacyStateLoader.LegacyLoadResult legacy = | ||
| LegacyStateLoader.loadFromLegacySessionWithPresence(stateStore, userId, sessionId); | ||
| LegacyStateLoader.loadFromLegacySessionWithPresence( | ||
| stateStore, userId, sessionId, permCtx); |
There was a problem hiding this comment.
[Info] The forwarding itself is correct — the 4-arg overload already applies permCtx (LegacyStateLoader.java:122-125), loadFromLegacySessionWithPresence is only called from this one site, and legacy keys never carry a permission context, so the builder-supplied template is the right fallback. No change needed here; just note that the same reconstruction also drops sessionId/userId (see the inline comment on the new test), which is why the added test currently fails.
- Restore the missing ' at' in the Apache license header so license-eye header check passes on the new regression test. - The legacy loader does not stamp a session id onto the reconstructed state, so assert the null user id instead of a specific session id. Signed-off-by: wylovelyi <[email protected]>
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
oss-maintainer
left a comment
There was a problem hiding this comment.
Summary
Re-review after 814447afe6. Both blockers from my previous review are resolved and the production change is unchanged, so this is an approval. One non-blocking wording nit is pinned inline on the new comment.
What I verified (not taken from the commit message)
- License header now reads
You may obtain a copy of the License at, andCheck License+Check Module Syncarepasson head814447afe6(they were failing on6958aa383b). - The scoped-down assertion is correct, not just weaker.
LegacyStateLoader.loadFromLegacySessionWithPresencebuildsAgentState.builder().context(msgs)and only attachespermissionContext/toolContext; it never callsuserId(...), andAgentState's constructor defaults onlysessionId(builder.sessionId == null ? newHex() : ...) whileuserIdstaysnull. SoassertNull(state.getUserId(), ...)pins real behaviour. - The fix itself is untouched by this push.
loadOrCreateAgentStateForSlotstill forwardspermCtxintoloadFromLegacySessionWithPresence(stateStore, userId, sessionId, permCtx), which is what keeps a builder-suppliedPermissionMode.BYPASSfrom silently degrading toDEFAULTon a v1-only session. The second test still pins that an existing v2 state wins over the builder template.
Follow-up worth a separate issue (pre-existing, not caused by this PR)
ReActAgent's shutdown state saver (constructor, ~line 369) derives its write target from the state object itself — agentState.getUserId() / agentState.getSessionId() — instead of from the slot key used everywhere else (saveStateToSession goes through SlotRef.parse(scope.slotKey)). For a legacy-migrated state, whose sessionId is the constructor-generated hex, that saver would compute a slot never registered in slotVersions (getOrDefault → UNVERSIONED) and persist an orphan agent_state entry rather than updating the real session. Worth tracking independently of this change; flagging it here only because this test is the place where the "no slot identity on migrated state" fact is now documented.
CI / merge state at review time
license/cla signed (Contributor License Agreement is signed.), Check License and Check Module Sync pass; build (ubuntu-latest) and build (windows-latest) were still pending when this review was posted, and the PR is MERGEABLE / BLOCKED. The approval covers the code, not merge readiness — the two build jobs are the ones that were red last round, so they are the ones to watch.
Automated review by github-manager-bot
| state.getPermissionContext().getMode(), | ||
| "builder-supplied permission context must survive legacy v1 session loading"); | ||
| // The legacy loader only reconstructs context/tool/permission state; it does not stamp a | ||
| // session id (the slot's session id is applied later by the caller), so we assert the |
There was a problem hiding this comment.
[Info] The new comment says the slot's session id "is applied later by the caller" — that part I could not verify in the code. loadOrCreateAgentStateForSlot / activateSlotForContext cache the loaded state under the slot key, but nothing writes userId/sessionId back into the AgentState, and since LegacyStateLoader never sets them, AgentState's constructor keeps the generated newHex() value on the object. So the assertion below is right (a legacy-migrated state really does have a null user id), but the reason stated here overstates what the caller does. Suggest rewording to something like "the legacy loader does not stamp slot identity onto the state; the slot key is tracked separately by ReActAgent". Non-blocking — no behaviour change requested in this PR.
Automated review by github-manager-bot
|
@jujn 你好,这个 PR 在加载 legacy v1 session state 时转发调用方权限上下文。准备好 review 了,谢谢! |
|
superseded #3441 |
…ader on 2.0.x (#2888) (#4452) 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.
What
ReActAgent.loadOrCreateAgentStateForSlotnow forwards the caller'sPermissionContextStatethrough the legacy v1 session load path, so sessions that only carry v1 keys (memory_messages/toolkit_activeGroups) keep their configured permission mode (e.g.BYPASS) instead of being silently downgraded toDEFAULT.Why
Closes #2888. This is a regression: #2760 rewrote the method and reverted the legacy-state path to the 3-arg
LegacyStateLoader.loadFromLegacySessionWithPresence(stateStore, userId, sessionId)overload, which passesnullforpermCtx. The 4-arg overload that forwardspermCtxalready exists (added in #2886 / #2769), so only the call site needed fixing — exactly the change #2760 dropped.How
agentscope-core/src/main/java/io/agentscope/core/ReActAgent.java:439— callloadFromLegacySessionWithPresence(stateStore, userId, sessionId, permCtx)instead of the 3-arg overload.ReActAgentLegacyPermissionContextTest(removed by fix(core): propagate agent state load failures #2760) which pins the legacy + permission-context combination. The test triggers the legacy load viagetAgentState()and asserts the builder-suppliedBYPASSmode survives (and that an existing v2 state keeps its ownDEFAULT).Verification
permCtxto the reconstructed state (LegacyStateLoader.java:122-125).loadOrCreateAgentStateForSlotis exercised bygetAgentState()(ReActAgent.java:4407), which the new test drives.Self-review (P0-P3)
main(4-arg overload present). ✅