[Bug]:agentscope.agent.event.emitter 和 AsyncToolMiddleware
AsyncToolMiddleware 开启后, next.apply 没有把contextview putall一份,导致后续拿不到agentscope.agent.event.emitter,agentSpawnTool没法向agent输出子agent事件 source标识子智能体 Optional
然后目前转后台工具执行,AsyncToolMiddleware虽然如果超时会捕获事件 添加到buffer,但是对于工具执行next.apply内部还是会发送ToolCallResult事件。
I am investigating the Reactor subscriber-context loss in AsyncToolMiddleware on current main (6a056809a). I will first add a deterministic regression covering AgentEventEmitter and caller context propagation across the detached subscription, then validate a minimal fix. I will keep the separate post-timeout event-routing semantics out of scope unless the regression demonstrates they must change. This work uses AI assistance; any proposed PR will remain draft pending independent review.
Issue Evaluation
Category: bug | Status: Confirmed on current main
Verified against the codebase:
- Root Cause:
AsyncToolMiddleware(agentscope-harness/.../middleware/AsyncToolMiddleware.java:99-179) subscribes tonext.apply(input)inside aFlux.createsink withoutdeferContextual/contextWrite, so the Reactor subscriber Context is not propagated across that boundary.AgentEventEmitter.fromContext(ctxView)(the emitter stored underagentscope.agent.event.emitter, seeAgentEventEmitter.java:45) therefore finds nothing, andAgentSpawnToolcannot stream sub-agent events to the parent. - Second symptom is also real: after the async timeout path, only
ToolResultTextDeltaEventis forwarded from the background buffer to the inbox (AsyncToolMiddleware.java:237-289) and the sink is completed (:234), so aToolCallResultEventemitted later insidenext.applynever reaches the caller's stream — matching the "only received if the agent stream happens to still be running" observation. - Impact: sub-agent event streaming and background tool results are lost whenever
AsyncToolMiddlewareis enabled; middleware chain construction (MiddlewareChain.java:46-62) does not restore context acrossnext.applyeither. - Severity: high (breaks observable event flow for harness sub-agents).
Note: community PR #3299 ("fix(harness): preserve subscriber context in async tool execution") targets exactly this and is still open, not yet merged into main. To avoid duplicate work, we should review/merge #3299 rather than generate a competing fix; a regression test that pins the AgentEventEmitter context propagation through the async path would strengthen it.
Automated evaluation by github-manager-bot