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]: Builder permission rules are snapshotted into persisted sessions; rule changes never reach existing sessions #3291
The builder-time permissionContext(...) is copied into AgentState only when a session slot is first created (loadOrCreateAgentStateForSlot → freshState(initialPermissionContext, ...)). After that, each call rebuilds the PermissionEngine from the persistedAgentState.permissionContext, so the rules declared in code never reach existing sessions again.
With a persistent AgentStateStore (Redis, JSON file), a code change to the permission rules therefore applies only to sessions created after the deployment:
Tightening fails open. A tool moved from ALLOW to ASK keeps running without confirmation in every existing session. The same applies to a newly added DENY rule.
New ALLOW rules do not apply. A tool added in a later release, with an ALLOW rule, still asks for confirmation in existing sessions (DEFAULT mode).
Reproduction (verified on 2.0.3, Redis state store)
Build agent v1 with PermissionMode.DEFAULT and an ALLOW rule for tool T. Call it on (userId=u, sessionId=s), and have the model call T. T runs.
Build agent v2 on the same store, with an ASK rule for T instead ("redeploy"). Call it on the same (u, s), and have the model call T.
Expected: PERMISSION_ASKING.
Actual: T runs without confirmation (MODEL_STOP).
Call v2 on a new session (u, s2). It returns PERMISSION_ASKING, as expected.
Discussion
replacePermissionContext can push new rules into a slot, but it has to be called per session by the host. It also currently has the stale-cache write issue addressed in #2731. There seems to be no supported way to say "the rules declared in code are authoritative for every call", while keeping per-session runtime changes (such as setPermissionMode, and rules accepted through ConfirmResult) where they are wanted.
Possible directions:
An opt-in builder flag. On each call, the engine is built from the builder rules merged with the session's runtime additions, rather than from the persisted snapshot alone.
Or persist only the runtime additions (mode changes, user-accepted rules) in AgentState, and always compose them with the current builder rules.
Category: bug | Status: Confirmed (verified against main, 2.0.4-SNAPSHOT)
The report is accurate. Builder-declared permission rules are copied into AgentState.permissionContextonly when a session slot is first created, and every later call rebuilds the PermissionEngine from the persisted snapshot, so in-code rule changes never reach pre-existing sessions.
Root cause (code paths)
ReActAgent.loadOrCreateAgentStateForSlot returns the stored agent_state when one exists; freshState(initialPermissionContext, ...) (which writes the builder context) only runs for a new slot — agentscope-core/src/main/java/io/agentscope/core/ReActAgent.java:421-468.
ReActAgent.activateSlotForContext builds the engine from the loaded state: new PermissionEngine(loaded.getPermissionContext()) (ReActAgent.java:659-707, esp. 697-705), and saveStateToSession re-persists that same snapshot (ReActAgent.java:475-496).
PermissionEngine snapshots rules at construction (state/PermissionEngine.java:59-106); PermissionContextState.withMode preserves the stale rule tables (state/PermissionContextState.java:148-159).
setPermissionMode / replacePermissionContext operate per session on the persisted context (ReActAgent.java:4621-4656); there is no option that makes builder rules authoritative per call.
Impact
Any deployment with a persistent AgentStateStore (Redis / JSON / JDBC), for ReActAgent and HarnessAgent (which delegates).
Confirmed by execution on current main: ALLOW→ASK on an existing session runs the tool uncconfirmed (MODEL_STOP instead of PERMISSION_ASKING); a newly added ALLOW rule still prompts on old sessions; a newly added DENY/ASK does not apply to old sessions.
Additional finding: with a store configured, rules accepted through a HITL ConfirmResult are applied only to the in-memory engine and are lost at the next call boundary, so "always allow for this session" does not survive across calls (ReActAgent.java:2113-2119).
Not affected: sessions with a trivial persisted context stay on the lightweight permission path (ReActAgent.java:3349), and store-less in-process agents keep the memoized engine — worth covering in the fix's test matrix.
Severity: high — a security control silently fails open for the whole pre-existing session population after a rule change; the only current mitigation is calling replacePermissionContext per session (or flushing sessions) on every deploy.
Next step: a fix proposal (spec) will be posted here for review — reply /approve to proceed with PR generation. Suggested direction: compose the per-call engine from the current builder rules as the base and layer only the session's runtime deltas on top (mode override + user-accepted rules), persisting deltas instead of the full rule snapshot, with precedence so a stale persisted ALLOW can never relax a newer builder ASK/DENY. Please coordinate with #2731, which touches the same setPermissionMode / replacePermissionContext paths and is still open.
Cross-reference: the maintainer evaluation on #3135 independently lists the same defect ("Builder permissionContext(...) is silently ignored once a persisted state exists. Precedence should either reconcile the two or be documented explicitly."). Also worth noting for prioritisation: persisted sessions have no expiry by default, so after a release that tightens a rule, every existing session keeps the old rule for as long as it lives.
Status: 72 h feedback window expired — no automated PR will be generated, this proposal window here is closed
The evaluation above (2026-09-25 11:12:06Z) reached its 72 hour limit at 2026-09-28 11:12:06Z without any of the three feedback commands arriving, so the spec-and-PR step is not being taken: we are not opening a PR for #3291 and no automated PR will be generated from this thread. No action is needed from anyone.
What landed under the window:
@xuchaoguo1983 (2026-09-25 14:50:22Z) cross-referenced [Bug]:ASKING 状态会被持久化到状态存储中 #3135, whose evaluation independently records the same defect, and added that persisted sessions have no expiry by default — so a stale rule keeps serving an existing session for as long as that session lives. Useful prioritisation input; it is not one of the feedback commands, so the gate stayed unsatisfied.
The finding itself still stands as written: builder-declared permission rules are copied into AgentState.permissionContext only when a session slot is first created, and later calls rebuild the PermissionEngine from the persisted snapshot, so rule changes never reach pre-existing sessions. This stand-down is about our own proposal window, not about the defect.
Two coordination notes for whoever picks this up: #3135 reports the same defect from the persisted-ASKING side, and #2731 is still open against the adjacent setPermissionMode / replacePermissionContext paths. If an automated proposal is still wanted here, say so on this issue and we will re-evaluate.
Direction I plan to take: an opt-in builder flag rather than changing what gets persisted. With it enabled, each call composes the engine from the current builder rules as the base and layers the session's runtime deltas on top — a mode override, and the rules accepted through a HITL ConfirmResult. With it disabled nothing changes, including the persisted format.
Why that rather than composing by default:
It needs no migration and no change to AgentState.permissionContext, so an existing store keeps working and the change cannot alter the sessions it is meant to protect until someone opts in.
It fixes the evaluation's second finding on the way: today a confirmed rule goes to the in-memory engine only (ReActAgent.java:2113-2119) and is lost when the engine is rebuilt at the next call boundary. Under the flag, accepted rules are part of the deltas being layered, so they survive.
The seam is the engine construction in activateSlotForContext (ReActAgent.java:697-707), which currently reads loaded.getPermissionContext() in both branches.
Test matrix I intend to cover, including the two cases the evaluation flagged as unaffected: a persistent store with an existing slot (the defect), a fresh slot, a store-less agent (memoized engine), and a session whose persisted context is trivial so it stays on the lightweight path.
Happy to be told the composition direction is wanted instead — that one changes persisted semantics and I would rather not start there without a maintainer saying so.
Correction to one claim above: I said this option fixes the evaluation's second finding — that rules accepted through a ConfirmResult are lost at the call boundary. It does not.
Those rules are written to the live engine only (ReActAgent.java:2179) and are never persisted, so rebuilding the engine per call drops them however the context is composed. Carrying them across calls means persisting them, which changes what gets stored — the thing this option deliberately leaves alone. I have kept it out of the change and will raise it separately.
Activity
oss-maintainer commentedon Sep 25, 2026
Issue Evaluation
Category:
bug| Status: Confirmed (verified againstmain,2.0.4-SNAPSHOT)The report is accurate. Builder-declared permission rules are copied into
AgentState.permissionContextonly when a session slot is first created, and every later call rebuilds thePermissionEnginefrom the persisted snapshot, so in-code rule changes never reach pre-existing sessions.Root cause (code paths)
ReActAgent.loadOrCreateAgentStateForSlotreturns the storedagent_statewhen one exists;freshState(initialPermissionContext, ...)(which writes the builder context) only runs for a new slot —agentscope-core/src/main/java/io/agentscope/core/ReActAgent.java:421-468.ReActAgent.activateSlotForContextbuilds the engine from the loaded state:new PermissionEngine(loaded.getPermissionContext())(ReActAgent.java:659-707, esp. 697-705), andsaveStateToSessionre-persists that same snapshot (ReActAgent.java:475-496).PermissionEnginesnapshots rules at construction (state/PermissionEngine.java:59-106);PermissionContextState.withModepreserves the stale rule tables (state/PermissionContextState.java:148-159).setPermissionMode/replacePermissionContextoperate per session on the persisted context (ReActAgent.java:4621-4656); there is no option that makes builder rules authoritative per call.Impact
AgentStateStore(Redis / JSON / JDBC), forReActAgentandHarnessAgent(which delegates).main: ALLOW→ASK on an existing session runs the tool uncconfirmed (MODEL_STOPinstead ofPERMISSION_ASKING); a newly added ALLOW rule still prompts on old sessions; a newly added DENY/ASK does not apply to old sessions.ConfirmResultare applied only to the in-memory engine and are lost at the next call boundary, so "always allow for this session" does not survive across calls (ReActAgent.java:2113-2119).ReActAgent.java:3349), and store-less in-process agents keep the memoized engine — worth covering in the fix's test matrix.Severity: high — a security control silently fails open for the whole pre-existing session population after a rule change; the only current mitigation is calling
replacePermissionContextper session (or flushing sessions) on every deploy.Next step: a fix proposal (spec) will be posted here for review — reply
/approveto proceed with PR generation. Suggested direction: compose the per-call engine from the current builder rules as the base and layer only the session's runtime deltas on top (mode override + user-accepted rules), persisting deltas instead of the full rule snapshot, with precedence so a stale persisted ALLOW can never relax a newer builder ASK/DENY. Please coordinate with #2731, which touches the samesetPermissionMode/replacePermissionContextpaths and is still open.Automated evaluation by github-manager-bot
xuchaoguo1983 commentedon Sep 25, 2026
Cross-reference: the maintainer evaluation on #3135 independently lists the same defect ("Builder
permissionContext(...)is silently ignored once a persisted state exists. Precedence should either reconcile the two or be documented explicitly."). Also worth noting for prioritisation: persisted sessions have no expiry by default, so after a release that tightens a rule, every existing session keeps the old rule for as long as it lives.oss-maintainer commentedon Sep 28, 2026
Status: 72 h feedback window expired — no automated PR will be generated, this proposal window here is closed
The evaluation above (2026-09-25 11:12:06Z) reached its 72 hour limit at 2026-09-28 11:12:06Z without any of the three feedback commands arriving, so the spec-and-PR step is not being taken: we are not opening a PR for #3291 and no automated PR will be generated from this thread. No action is needed from anyone.
What landed under the window:
The finding itself still stands as written: builder-declared permission rules are copied into
AgentState.permissionContextonly when a session slot is first created, and later calls rebuild thePermissionEnginefrom the persisted snapshot, so rule changes never reach pre-existing sessions. This stand-down is about our own proposal window, not about the defect.Two coordination notes for whoever picks this up: #3135 reports the same defect from the persisted-ASKING side, and #2731 is still open against the adjacent
setPermissionMode/replacePermissionContextpaths. If an automated proposal is still wanted here, say so on this issue and we will re-evaluate.Automated by github-manager-bot
kyy-logs commentedon Sep 29, 2026
I'd like to take this one.
Direction I plan to take: an opt-in builder flag rather than changing what gets persisted. With it enabled, each call composes the engine from the current builder rules as the base and layers the session's runtime deltas on top — a mode override, and the rules accepted through a HITL
ConfirmResult. With it disabled nothing changes, including the persisted format.Why that rather than composing by default:
AgentState.permissionContext, so an existing store keeps working and the change cannot alter the sessions it is meant to protect until someone opts in.setPermissionMode/replacePermissionContextpaths and their neighbours (fix(core): reload authoritative state before permission admin writes #2731, [Bug]:ASKING 状态会被持久化到状态存储中 #3135, [Bug]: User messages sent together with a permission-HITL resume are silently dropped #3294) alone, which is also what makes it landable while those are open.ReActAgent.java:2113-2119) and is lost when the engine is rebuilt at the next call boundary. Under the flag, accepted rules are part of the deltas being layered, so they survive.The seam is the engine construction in
activateSlotForContext(ReActAgent.java:697-707), which currently readsloaded.getPermissionContext()in both branches.Test matrix I intend to cover, including the two cases the evaluation flagged as unaffected: a persistent store with an existing slot (the defect), a fresh slot, a store-less agent (memoized engine), and a session whose persisted context is trivial so it stays on the lightweight path.
Happy to be told the composition direction is wanted instead — that one changes persisted semantics and I would rather not start there without a maintainer saying so.
kyy-logs commentedon Sep 29, 2026
Correction to one claim above: I said this option fixes the evaluation's second finding — that rules accepted through a
ConfirmResultare lost at the call boundary. It does not.Those rules are written to the live engine only (
ReActAgent.java:2179) and are never persisted, so rebuilding the engine per call drops them however the context is composed. Carrying them across calls means persisting them, which changes what gets stored — the thing this option deliberately leaves alone. I have kept it out of the change and will raise it separately.fix(permission): make declared rules authoritative on every call (age…