Skip to content

fix(agent): forward reasoning middleware events#2179

Open
guslegend0510 wants to merge 1 commit into
agentscope-ai:mainfrom
guslegend0510:fix/2160-inbox-hint-events
Open

fix(agent): forward reasoning middleware events#2179
guslegend0510 wants to merge 1 commit into
agentscope-ai:mainfrom
guslegend0510:fix/2160-inbox-hint-events

Conversation

@guslegend0510

Copy link
Copy Markdown
Contributor

AgentScope-Java Version

2.0.1-SNAPSHOT

Description

Fixes #2160.

InboxMiddleware emits HintBlockEvent values from its onReasoning(...)
middleware hook, but these events were not observable through
HarnessAgent.streamEvents().

The reasoning middleware stream was exhausted with .then(...), while event
publication happened inside the nested model-call stream. As a result, events
added directly by onReasoning middleware were discarded from the public event
stream.

This change moves event publication to the outer reasoning middleware boundary
and removes the nested publication point. This ensures that:

  • HintBlockEvent emitted by InboxMiddleware is forwarded through
    streamEvents().
  • Hint source identity, block ID, reply ID, and content are preserved.
  • Core model events are still emitted exactly once.

Testing

  • Added reasoningMiddlewareEventsAreForwardedExactlyOnce.
  • Verified HintBlockEvent fields are preserved.
  • Verified ModelCallStartEvent is not duplicated.
  • agentscope-core: 2210 tests passed, 9 skipped, 0 failures.
  • InboxMiddlewareTest: 6 tests passed.
  • agentscope-core Spotless check passed.

Checklist

  • Code has been formatted and checked with Spotless
  • Relevant unit tests are passing
  • Regression test has been added
  • No

@guslegend0510 guslegend0510 requested a review from a team July 13, 2026 13:38
@codecov

codecov Bot commented Jul 13, 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/core/agent Agent runtime, pipeline, hooks, plan labels Jul 14, 2026

@AgentScopeJavaBot AgentScopeJavaBot left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🤖 AI Review

This PR fixes a genuine event-forwarding bug in ReActAgent's reactive stream pipeline. InboxMiddleware (and any other onReasoning middleware) injects HintBlockEvent values at the outer reasoning middleware boundary, but the original code only called publishEvent at the inner model-call boundary (reasoningStream). Events injected by onReasoning middlewares were thus silently consumed by .then(...) and never reached HarnessAgent.streamEvents().

The fix is minimal and surgically precise: move .doOnNext(this::publishEvent) from the inner reasoningStream() to the outer reasoning() method. The accompanying test directly reproduces the bug scenario and asserts no double-publishing. This correctly resolves issue #2160.

@AgentScopeJavaBot AgentScopeJavaBot left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🤖 AI Review

This PR fixes a genuine event-forwarding bug in ReActAgent's reactive stream pipeline. InboxMiddleware (and any other onReasoning middleware) injects HintBlockEvent values at the outer reasoning middleware boundary, but the original code only called publishEvent at the inner model-call boundary (reasoningStream). Events injected by onReasoning middlewares were thus silently consumed by .then(...) and never reached HarnessAgent.streamEvents().

The fix is minimal and surgically precise: move .doOnNext(this::publishEvent) from the inner reasoningStream() to the outer reasoning() method. The accompanying test directly reproduces the bug scenario and asserts no double-publishing. This correctly resolves issue #2160.

@oss-maintainer oss-maintainer left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Summary

Fixes reasoning middleware events not being forwarded to the event stream. The issue was that publishEvent was called inside the middleware chain, but events added by onReasoning middlewares were not published.

Findings

  • [Info] ReActAgent.java:1981-1985 — Moved publishEvent to the outer reasoning boundary. Now events from onReasoning middlewares are forwarded.
  • [Info] ReActAgent.java:2123 — Removed duplicate publishEvent from modelCallStream to avoid double-publishing.
  • [Info] Test reasoningMiddlewareEventsAreForwardedExactlyOnce() verifies HintBlockEvent is forwarded and core events are not duplicated.

Verdict

Correct fix with good test coverage. LGTM.


Automated review by github-manager

@jujn jujn left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/core/agent Agent runtime, pipeline, hooks, plan bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: InboxMiddleware HintBlockEvent is absent from streamEvents

4 participants