Skip to content

[Bug]: agent.interrupt() is a silent no-op in MiddlewareBase callbacks when the call carries a RuntimeContext #1988

Closed

Description

@Buktal

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") → triggers InterruptControl for slot (__anon__, default-session)
  • call(msgs, ctx) → activateSlotForContext(ctx) → uses slot (__anon__, my-session) → checkInterrupted() checks that slot's InterruptControl
  • Two different InterruptControl instances → 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:

  1. agent.interrupt() should interrupt the current call, regardless of which session the call is running on
  2. The Agent interface should provide a session-aware interrupt method (e.g., interrupt(RuntimeContext)) so middlewares can interrupt the current call without casting
  3. 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).

Activity

  1. Buktal commented on Jul 2, 2026

    @Buktal
    CollaboratorAuthor

    Related: See #1989 for a comprehensive API redesign proposal addressing this issue at the interface level.

  2. added
    bug
    area/core/agent
    on Jul 11, 2026
  3. moved this from In progress to Done in AgentScope Javaon Aug 21, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    area/core/agentbug

    Type

    No type

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions