Skip to content

fix: propagate Reactor context to chunk event hooks in ReActAgent#1762

Open
Vinke2 wants to merge 2 commits into
agentscope-ai:mainfrom
Vinke2:patch-1
Open

fix: propagate Reactor context to chunk event hooks in ReActAgent#1762
Vinke2 wants to merge 2 commits into
agentscope-ai:mainfrom
Vinke2:patch-1

Conversation

@Vinke2

@Vinke2 Vinke2 commented Jun 15, 2026

Copy link
Copy Markdown

Three bare .subscribe() calls in ReActAgent (fireReasoningChunk, fireActingChunk, fireSummaryChunk) created new subscription chains without the parent Reactor context, causing ReasoningChunkEvent, ActingChunkEvent, and SummaryChunkEvent to have an empty ContextView in downstream hooks.

Fix each with Flux.deferContextual + contextWrite to capture and propagate the parent context, matching the existing pattern used by executeToolCalls at line 2389-2391.

AgentScope-Java Version

[The version of AgentScope-Java you are working on, e.g. 1.0.12, check your pom.xml dependency version or run mvn dependency:tree | grep agentscope-parent:pom(only mac/linux)]

Description

[Please describe the background, purpose, changes made, and how to test this PR]

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

Three bare .subscribe() calls in ReActAgent (fireReasoningChunk,
fireActingChunk, fireSummaryChunk) created new subscription chains
without the parent Reactor context, causing ReasoningChunkEvent,
ActingChunkEvent, and SummaryChunkEvent to have an empty ContextView
in downstream hooks.

Fix each with Flux.deferContextual + contextWrite to capture and
propagate the parent context, matching the existing pattern used by
executeToolCalls at line 2389-2391.
@Vinke2 Vinke2 requested a review from a team June 15, 2026 06:27
@CLAassistant

CLAassistant commented Jun 15, 2026

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

@codecov

codecov Bot commented Jun 15, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 72.91667% with 13 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
...e/src/main/java/io/agentscope/core/ReActAgent.java 72.91% 8 Missing and 5 partials ⚠️

📢 Thoughts on this report? Let us know!

@AgentScopeJavaBot AgentScopeJavaBot added bug Something isn't working area/core/agent Agent runtime, pipeline, hooks, plan labels Jun 15, 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 is a well-targeted bug fix that correctly addresses Reactor context loss in three fire-and-forget .subscribe() calls within ReActAgent. The bare .subscribe() calls for fireReasoningChunk, fireActingChunk, and fireSummaryChunk created independent subscription chains that did not inherit the parent Reactor context, causing downstream hooks to see an empty ContextView — notably losing access to the SubagentEventBus. The fix applies Flux.deferContextual + contextWrite to capture and propagate the parent context, matching the existing pattern already established for executeToolCalls in the same file. The approach is correct, consistent, and minimal in scope.

ctx ->
ctx.putAll(
parentCtx))
.subscribe();

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.

[minor] The .subscribe() call remains bare — no error consumer is provided. If a hook's onEvent throws (or the Mono<Void> signals an error), Reactor will invoke onErrorDropped, silently swallowing the exception. This is a pre-existing issue, not introduced by this PR, but since you're already touching this line, consider adding a minimal error handler (e.g. .subscribe(v -> {}, e -> log.warn("Reasoning chunk hook failed", e))) to surface failures. Same applies to lines 2463 and 2975.

mci.model().getModelName())
.subscribe();
}
return Flux.deferContextual(

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.

[nit] Consider adding a brief inline comment explaining why Flux.deferContextual is needed here (e.g. // Propagate parent Reactor context so chunk hooks can access SubagentEventBus), similar to the existing comment at line 2402–2406 for executeToolCalls. This helps future readers understand the non-obvious context-propagation requirement without having to trace the full call chain.

@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 is a well-targeted bug fix that correctly addresses Reactor context loss in three fire-and-forget .subscribe() calls within ReActAgent. The bare .subscribe() calls for fireReasoningChunk, fireActingChunk, and fireSummaryChunk created independent subscription chains that did not inherit the parent Reactor context, causing downstream hooks to see an empty ContextView — notably losing access to the SubagentEventBus. The fix applies Flux.deferContextual + contextWrite to capture and propagate the parent context, matching the existing pattern already established for executeToolCalls in the same file. The approach is correct, consistent, and minimal in scope.

ctx ->
ctx.putAll(
parentCtx))
.subscribe();

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.

[minor] The .subscribe() call remains bare — no error consumer is provided. If a hook's onEvent throws (or the Mono<Void> signals an error), Reactor will invoke onErrorDropped, silently swallowing the exception. This is a pre-existing issue, not introduced by this PR, but since you're already touching this line, consider adding a minimal error handler (e.g. .subscribe(v -> {}, e -> log.warn("Reasoning chunk hook failed", e))) to surface failures. Same applies to lines 2463 and 2975.

mci.model().getModelName())
.subscribe();
}
return Flux.deferContextual(

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.

[nit] Consider adding a brief inline comment explaining why Flux.deferContextual is needed here (e.g. // Propagate parent Reactor context so chunk hooks can access SubagentEventBus), similar to the existing comment at line 2402–2406 for executeToolCalls. This helps future readers understand the non-obvious context-propagation requirement without having to trace the full call chain.

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.

3 participants