fix(harness): emit subagent end before parent completion - #2544
Conversation
|
Caution The consumer version of Gemini Code Assist on GitHub has been sunset. All code review activity has officially ceased. |
|
Caution The consumer version of Gemini Code Assist on GitHub has been sunset. All code review activity has officially ceased. |
There was a problem hiding this comment.
Pull request overview
This PR fixes an intermittent race in HarnessAgent.streamEvents() subagent forwarding where a quickly completing child agent could have its sourced AGENT_END emitted too late (after the parent stream’s terminal signal), allowing the parent to close its event sink before the child end event is forwarded.
Changes:
- Emit the sourced child
AGENT_ENDon success/error before the terminal signal propagates downstream, while keeping best-effort cancel handling. - Guard child-end emission with an
AtomicBooleanto prevent duplicate end events across completion/cancellation races. - Strengthen the ordering test to require the sourced child
AGENT_ENDto occur before the parentAGENT_END.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| agentscope-harness/src/main/java/io/agentscope/harness/agent/tool/AgentSpawnTool.java | Moves sourced child AGENT_END emission earlier (success/error) and guards against duplicates; retains cancel best-effort signaling. |
| agentscope-harness/src/test/java/io/agentscope/harness/agent/HarnessAgentSubagentStreamEventsTest.java | Extends ordering assertions to require sourced child AGENT_END before parent AGENT_END. |
Codecov Report❌ Patch coverage is
📢 Thoughts on this report? Let us know! |
AgentScope-Java Version
2.0.1-SNAPSHOT
Description
Background
The Harness stream-event tests can intermittently miss the sourced child
AGENT_ENDevent. The child end event was emitted fromdoFinally, which runs after the terminal signal has propagated downstream. For a quickly completing child agent, the parent can therefore complete and close its event sink before the child end event is forwarded.This race was exposed by the CI runs of #2532, but it is independent of that middleware-ordering change.
Changes
AGENT_ENDbefore success or error is propagated to the parent.AtomicBooleanso completion and cancellation races cannot produce duplicate child end events.AGENT_ENDbefore the parentAGENT_END.The resulting order is:
Test
Result: 4 tests passed, 0 failures.
Checklist
mvn spotless:applymvn test)