Repository navigation
Description
AgentScope-Java is an open-source project. To involve a broader community, we recommend asking your questions in English.
Describe the bug
When a middleware (e.g., MiddlewareBase.onModelCall) calls agent.interrupt() on an Agent instance, the interruption has no effect on the current agent call if that call was invoked with a RuntimeContext whose sessionId differs from the agent's defaultSessionId. This is a silent failure — no error is thrown, no warning is logged, and the agent continues executing as if no interruption was requested.
The root cause is that Agent.interrupt() (inherited from AgentBase) delegates to ReActAgent.interrupt(null, defaultSessionId), which triggers the interrupt signal on the default session's slot, while checkInterrupted() checks the current call's slot (determined by RuntimeContext.sessionId). When these two slots differ, the signal goes to the wrong InterruptControl instance, and the current call never sees it.
To Reproduce
Minimal reproduction:
```java
// 1. Create a ReActAgent with a default session ID
ReActAgent agent = ReActAgent.builder()
.name("TestAgent")
.model(mockModel)
.defaultSessionId("default-session")
.middleware(new MiddlewareBase() {
@OverRide
public Flux onModelCall(
Agent agent, RuntimeContext ctx, ModelCallInput input,
Function<ModelCallInput, Flux> next) {
// This should interrupt the current call, but doesn't
agent.interrupt();
return next.apply(input);
}
})
.build();
// 2. Invoke with a DIFFERENT sessionId via RuntimeContext
RuntimeContext ctx = RuntimeContext.builder()
.sessionId("my-session") // ≠ "default-session"
.build();
// 3. Observe: the agent does NOT interrupt
Msg result = agent.call(List.of(new UserMessage("test")), ctx).block();
// Expected: InterruptedException
// Actual: call completes normally (silent failure)
```
Why this happens:
agent.interrupt()→ReActAgent.interrupt()→interrupt(null, "default-session")→ triggersInterruptControlfor slot(__anon__, default-session)call(msgs, ctx)→activateSlotForContext(ctx)→ uses slot(__anon__, my-session)→checkInterrupted()checks that slot'sInterruptControl- Two different
InterruptControlinstances → signal never seen by the current call
Current workaround (as seen in SubAgentTool.java:200-229):
```java
if (agent instanceof ReActAgent ra) {
ra.interrupt(ctx); // ← forced to cast and call non-interface method
}
```
Expected behavior
One of:
agent.interrupt()should interrupt the current call, regardless of which session the call is running on- The
Agentinterface should provide a session-aware interrupt method (e.g.,interrupt(RuntimeContext)) so middlewares can interrupt the current call without casting - The framework should log a warning or throw an exception when
interrupt()is called but targets the wrong session
Error messages
None. This is a silent failure — the most dangerous kind. No exception, no log line, no indication that the interruption was ignored.
Environment
- AgentScope-Java Version: 2.0.0-SNAPSHOT (main branch as of 2026-07-02)
- Java Version: 17
- OS: Windows 11 Pro 10.0.26200
Additional context
Root cause: Slot mismatch between interrupt() (hardcoded defaultSessionId) and checkInterrupted() (current call's sessionId).
Evidence that this is a known issue:
SubAgentTool.java:200-229 already works around this by casting to ReActAgent and calling the non-interface interrupt(RuntimeContext) method:
```java
// Uses interrupt(RuntimeContext) instead of the deprecated interrupt(InterruptSource)
// because the latter only looks up [the default session] ...
private void interruptAgent(Agent agent, RuntimeContext ctx) {
if (agent instanceof ReActAgent ra) {
ra.interrupt(ctx);
}
}
```
Full root cause analysis and API redesign proposal: See Enhancement issue (will be linked after submission).
Metadata
Metadata
Assignees
Labels
Type
Projects
- StatusShow more project fieldsDone
Activity
Buktal commentedon Jul 2, 2026
Related: See #1989 for a comprehensive API redesign proposal addressing this issue at the interface level.