fix(harness): target active session in HarnessAgent interrupt API - #2643
Open
StevenZhang2002 wants to merge 2 commits into
Open
fix(harness): target active session in HarnessAgent interrupt API#2643StevenZhang2002 wants to merge 2 commits into
StevenZhang2002 wants to merge 2 commits into
Conversation
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
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Background
Issue #2610:
HarnessAgent.interrupt()/interrupt(Msg)unconditionally resolved the defaultsession id (the agent name), so streams started via
streamEvents(List, RuntimeContext)with acustom
sessionIdcould never be cancelled — the interrupt signal was always sent to the wrongsession slot.
Purpose
Make the interrupt API target the session that is actually running:
RuntimeContext(obtained from thedelegate's current runtime context) when one exists, while keeping the legacy default-session
fallback when no call is in flight.
interrupt(RuntimeContext)/interrupt(RuntimeContext, Msg)overloads let callers targetan explicit
(userId, sessionId)slot. Because each caller supplies the session it wants tocancel, this is safe under concurrency (multiple sessions running in parallel).
Changes
agentscope-harness/src/main/java/io/agentscope/harness/agent/HarnessAgent.java:interrupt()andinterrupt(Msg)now prefer the active call's runtime context when present,and fall back to the default session otherwise.
interrupt(RuntimeContext ctx)andinterrupt(RuntimeContext ctx, Msg msg)overloadsthat 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 customsessionId→GenerateReason.INTERRUPTEDinterrupt(ctx)cancels a custom-session stream without a messageinterrupt(msg)prefers the active call's custom sessioninterrupt(msg)still works for streams under the default session (backward compat)interrupt()/interrupt(msg)with no active call fall back to the defaultsession without throwing (backward compat)
How to Test
All five test cases in
HarnessAgentInterruptTestshould pass; no existing tests are affected.Checklist
Please check the following items before code is ready to be reviewed.
mvn spotless:applymvn test)