Skip to content

fix(core): promote interrupt(RuntimeContext) to Agent interface to fix slot-mismatch silent failure - #1990

Closed
Buktal wants to merge 3 commits into
agentscope-ai:mainfrom
Buktal:fix/interrupt-slot-mismatch-1988
Closed

Buktal wants to merge 3 commits into
agentscope-ai:mainfrom
Buktal:fix/interrupt-slot-mismatch-1988

Conversation

@Buktal

@Buktal Buktal commented Jul 2, 2026

Copy link
Copy Markdown
Collaborator

AgentScope-Java Version

2.0.0-SNAPSHOT

Description

Problem: The Agent.interrupt() and Agent.interrupt(Msg) methods were hardcoded to the agent's defaultSessionId. When a call was made with a RuntimeContext carrying a different sessionId, calling agent.interrupt() from a middleware triggered the wrong session's InterruptControl — a silent no-op that neither threw nor logged anything. Middlewares holding both Agent agent and RuntimeContext ctx (e.g. onModelCall, onReasoning) were forced to cast ((ReActAgent) agent).interrupt(ctx), as seen in SubAgentTool.java:200-229.

Solution: Add interrupt(RuntimeContext) and interrupt(RuntimeContext, Msg) as default methods on the Agent interface. ReActAgent already had these methods with real per-session trigger logic — now they properly @Override the interface methods. HarnessAgent gains the missing delegates so the methods work through the harness wrapper.

Changes:

File What changed
Agent.java New default interrupt(RuntimeContext) / interrupt(RuntimeContext, Msg); mark old methods @Deprecated(forRemoval=true)
AgentBase.java Upgrade Javadoc on all legacy interrupt methods, add forRemoval=true
ReActAgent.java Add @Override to existing interrupt(RuntimeContext) / interrupt(RuntimeContext, Msg)
HarnessAgent.java Add missing interrupt(RuntimeContext) / interrupt(RuntimeContext, Msg) delegates → delegate

How to test: Middlewares/tools can now write agent.interrupt(ctx) without casting — it correctly targets the session identified by the RuntimeContext. The change is backward-compatible (default methods delegate to legacy interrupt() for existing implementations).

Closes #1988, Closes #1989

Checklist

  • Code has been formatted with mvn spotless:apply
  • All tests are passing (agentscope-core — all 300+ tests pass; agentscope-harness — 6 pre-existing JUnit Failed to close extension context errors unrelated to this change)
  • Javadoc comments are complete and follow project conventions
  • Code is ready for review

…x slot-mismatch silent failure

The Agent.interrupt() and Agent.interrupt(Msg) methods were hardcoded to the
agent's defaultSessionId. When a call was made with a RuntimeContext carrying
a different sessionId, calling agent.interrupt() from a middleware triggered
the wrong session's InterruptControl — a silent no-op that neither threw nor
logged anything.

Add interrupt(RuntimeContext) and interrupt(RuntimeContext, Msg) as default
methods on the Agent interface. ReActAgent overrides them with real per-session
trigger logic (already existed, now @OverRide). HarnessAgent gains the missing
delegates. Mark all legacy interrupt methods @deprecated(forRemoval = true).

Closes agentscope-ai#1988, Closes agentscope-ai#1989
@Buktal
Buktal requested a review from a team July 2, 2026 09:33
@codecov

codecov Bot commented Jul 2, 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 enhancement New feature or request area/core/agent Agent runtime, pipeline, hooks, plan labels Jul 11, 2026

@AgentScopeJavaBot AgentScopeJavaBot left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🤖 AI Review

Promotes interrupt(RuntimeContext) to Agent interface to fix slot-mismatch silent failure. The interrupt method signature now includes RuntimeContext for proper session key resolution. Important interface-level change ensuring interrupts target the correct session slot.

Buktal added 2 commits July 13, 2026 14:48
- AgentDefaultInterruptTest: legacy fallback of the two default
  Agent.interrupt(RuntimeContext[, Msg]) methods.
- ReActAgentInterruptRuntimeContextTest: per-slot targeting,
  message forwarding, and defaultSessionId fallback for null /
  blank sessionId.
- HarnessAgentTest: two cases verifying HarnessAgent forwards
  interrupt(ctx[, msg]) to the wrapped ReActAgent slot.

Adds coverage for the 8 lines flagged by codecov on PR agentscope-ai#1990.
@Buktal Buktal closed this Aug 21, 2026
jujn added a commit that referenced this pull request Nov 19, 2026
## Summary

- route parent cancellation through a `HarnessAgent` to its `ReActAgent`
delegate
- interrupt the spawned `sub-*` session context instead of the parent
run context
- preserve cancellation-by-disposal for ordinary `Agent` implementations
and timeout promotion behavior

## Root cause

`AgentSpawnTool.interruptAgent` only handled direct `ReActAgent`
instances, so a synchronously spawned `HarnessAgent` ignored parent
cancellation. It also called `interrupt` with the parent
`RuntimeContext`, while the child runs under a newly generated `sub-*`
session.

This fix stays local to `AgentSpawnTool` and does not change the shared
`Agent` interrupt API or the `HarnessAgent` facade, avoiding overlap
with #1685 and #1990.

Closes #2408
Co-authored-by: jujn <[email protected]>
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 enhancement New feature or request

Projects

None yet

2 participants