Skip to content

fix(harness): target active session in HarnessAgent interrupt API - #2643

Open
StevenZhang2002 wants to merge 2 commits into
agentscope-ai:mainfrom
StevenZhang2002:fix/2610-harness-interrupt
Open

fix(harness): target active session in HarnessAgent interrupt API#2643
StevenZhang2002 wants to merge 2 commits into
agentscope-ai:mainfrom
StevenZhang2002:fix/2610-harness-interrupt

Conversation

@StevenZhang2002

Copy link
Copy Markdown

Background

Issue #2610: HarnessAgent.interrupt() / interrupt(Msg) unconditionally resolved the default
session id (the agent name), so streams started via streamEvents(List, RuntimeContext) with a
custom sessionId could never be cancelled — the interrupt signal was always sent to the wrong
session slot.

Purpose

Make the interrupt API target the session that is actually running:

  1. The context-free overloads now prefer the active call's RuntimeContext (obtained from the
    delegate's current runtime context) when one exists, while keeping the legacy default-session
    fallback when no call is in flight.
  2. New interrupt(RuntimeContext) / interrupt(RuntimeContext, Msg) overloads let callers target
    an explicit (userId, sessionId) slot. Because each caller supplies the session it wants to
    cancel, this is safe under concurrency (multiple sessions running in parallel).

Changes

  • agentscope-harness/src/main/java/io/agentscope/harness/agent/HarnessAgent.java:
    • interrupt() and interrupt(Msg) now prefer the active call's runtime context when present,
      and fall back to the default session otherwise.
    • Added interrupt(RuntimeContext ctx) and interrupt(RuntimeContext ctx, Msg msg) overloads
      that delegate directly to the target session (with Javadoc documenting the issue context).
  • agentscope-harness/src/test/java/io/agentscope/harness/agent/HarnessAgentInterruptTest.java
    (new): a blocking model is used to keep a stream in flight while an interrupt is fired. Covers:
    • interrupt(ctx, msg) cancels a stream running under a custom sessionIdGenerateReason.INTERRUPTED
    • interrupt(ctx) cancels a custom-session stream without a message
    • context-free interrupt(msg) prefers the active call's custom session
    • context-free interrupt(msg) still works for streams under the default session (backward compat)
    • context-free interrupt() / interrupt(msg) with no active call fall back to the default
      session without throwing (backward compat)

How to Test

All five test cases in HarnessAgentInterruptTest should pass; no existing tests are affected.

Checklist

Please check the following items before code is ready to be reviewed.

  • Code has been formatted with mvn spotless:apply
  • All tests are passing (mvn test)
  • Javadoc comments are complete and follow project conventions
  • Related documentation has been updated (e.g. links, examples, etc.)
  • Code is ready for review

interrupt() / interrupt(Msg) always resolved the default session id, so
streams started via streamEvents(List, RuntimeContext) with a custom
sessionId could never be cancelled. Prefer the active call's runtime
context when one exists, and expose interrupt(RuntimeContext[, Msg])
overloads that target an explicit session (safe under concurrency).

Fixes agentscope-ai#2610
@CLAassistant

CLAassistant commented Aug 10, 2026

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

@codecov

codecov Bot commented Aug 10, 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 bug Something isn't working area/docs Documentation area/harness agentscope-harness (test/runtime support) labels Aug 11, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/docs Documentation area/harness agentscope-harness (test/runtime support) bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants