Skip to content

fix(harness): auto-inject ALLOW rules for plan mode tools#1960

Open
Buktal wants to merge 1 commit into
agentscope-ai:mainfrom
Buktal:fix/plan-mode-permission-coordination
Open

fix(harness): auto-inject ALLOW rules for plan mode tools#1960
Buktal wants to merge 1 commit into
agentscope-ai:mainfrom
Buktal:fix/plan-mode-permission-coordination

Conversation

@Buktal

@Buktal Buktal commented Jun 29, 2026

Copy link
Copy Markdown
Contributor

AgentScope-Java Version

2.0.0-SNAPSHOT

Description

Problem:
Issue #1910 reported that PlanModeMiddleware whitelist and PermissionEngine were not coordinated. When enablePlanMode(true) is called, plan_enter, plan_write, and todo_write are in PlanModeMiddleware.ALWAYS_ALLOWED (execution-layer whitelist), but PermissionEngine still prompts ASK in DEFAULT mode because it has no awareness of plan mode context.

Root Cause:

  • PlanModeMiddleware controls onActing phase (execution gate)
  • PermissionEngine controls onReasoning phase (permission prompt)
  • They operate independently with no coordination

Solution:
When HarnessAgent.Builder.enablePlanMode(true) is called, automatically inject unconditional ALLOW rules for plan_enter, plan_write, and todo_write into PermissionContextState. plan_exit is deliberately excluded to preserve HITL (Human-in-the-Loop) confirmation semantics.

Changes:

  1. Add permissionContext mirror field in HarnessAgent.Builder (default: empty context)
  2. Modify permissionContext() setter to store locally instead of forwarding to inner immediately
  3. In build(): when planModeEnabled = true, merge user context + plan mode allow rules, then call inner.permissionContext() once
  4. When planModeEnabled = false, directly forward user context to inner (behavior unchanged)
  5. Add 6 tests verifying auto-injection behavior

Testing:

  • 6 new tests in HarnessAgentPlanModePermissionTest:
    • plan_enter / plan_write / todo_write get ALLOW rules ✅
    • plan_exit has no ALLOW rule (preserves ASK) ✅
    • User-configured rules are preserved ✅
    • No injection when plan mode disabled ✅
  • All 590 existing tests pass (Failures: 0)

Backward Compatibility:

  • planModeEnabled = false (default): behavior unchanged
  • User-configured permission rules are preserved and merged
  • User ASK rules take precedence over auto-injected ALLOW rules (PermissionEngine evaluation order)

Fixes #1910

Checklist

  • Code has been formatted with mvn spotless:apply
  • All tests are passing (590 tests, 0 failures)
  • Javadoc comments are complete
  • Documentation updated (inline comments explain the coordination)
  • Code is ready for review

When HarnessAgent.Builder.enablePlanMode(true) is called, plan_enter,
plan_write, and todo_write now get unconditional ALLOW rules injected
into PermissionContextState so PermissionEngine does not prompt ASK
under DEFAULT mode.

plan_exit deliberately excluded to preserve HITL confirmation.

Changes:
- Add permissionContext mirror field in HarnessAgent.Builder
- Modify permissionContext() setter to store locally instead of
  forwarding to inner immediately
- In build(): merge user context + plan mode allow rules, then set
  inner.permissionContext() once
- Add 6 tests verifying auto-injection behavior

Fixes agentscope-ai#1910
@Buktal Buktal requested a review from a team June 29, 2026 09:33
@codecov

codecov Bot commented Jun 29, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 94.44444% with 1 line in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
...java/io/agentscope/harness/agent/HarnessAgent.java 94.44% 0 Missing and 1 partial ⚠️

📢 Thoughts on this report? Let us know!

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.

[Bug]:Plan Mode 的“白名单机制”和“权限确认机制”没有联动

1 participant