fix(#2279): use tryEmitComplete in buildAgentStream to prevent 30s sink.complete delay [FaaFyfxR9WAQrL7FcAgEHJvztd8cVMxvjHRS55rw1nwH] - #2431
Open
waterWang wants to merge 1 commit into
Conversation
…revent 30s sink.complete delay [FaaFyfxR9WAQrL7FcAgEHJvztd8cVMxvjHRS55rw1nwH]
|
Caution The consumer version of Gemini Code Assist on GitHub has been sunset. All code review activity has officially ceased. |
Collaborator
|
CI Failure — Compilation error Build fails in
// Replace:
sink.tryEmitComplete();
// With:
sink.complete(); |
oss-maintainer
requested changes
Jul 28, 2026
oss-maintainer
left a comment
Collaborator
There was a problem hiding this comment.
Review: fix(#2279): use tryEmitComplete in buildAgentStream
CI is failing with a compilation error:
cannot find symbol
symbol: class EmitResult
location: interface reactor.core.publisher.FluxSink
cannot find symbol
symbol: method tryEmitComplete()
location: variable sink of type reactor.core.publisher.FluxSink
The issue is that FluxSink does not have a tryEmitComplete() method. That API belongs to reactor.core.publisher.Sinks.Empty / Sinks.Many, not FluxSink.
FluxSink only exposes:
complete()— void, non-blocking in most operators but can block withOverflowStrategy.BUFFERwhen downstream is slowerror(Throwable)— void
Suggested fix
The root cause (30s delay with OverflowStrategy.BUFFER) is real, but the fix needs a different approach. Options:
- Switch to
OverflowStrategy.DROP_OLDESTorOverflowStrategy.LATESTif event loss is acceptable - Use
sink.onDispose()to ensure cleanup without blocking - Move the
complete()call outside thedoFinallyand useFlux.doOnComplete()/Flux.doOnError()operators instead - Wrap the sink completion in a separate scheduler:
Schedulers.parallel().schedule(sink::complete)
Please revise the approach and verify it compiles.
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.
Summary
When
HarnessAgent.streamEvents()is used for streaming conversations withenable_thinking=true, thesink.complete()call inReActAgent.buildAgentStream()can be delayed by 30+ seconds underOverflowStrategy.BUFFER. This causes the frontend to show "Generating..." for 30 seconds after the model has already finished outputting.Root Cause
Flux.create(sink -> { ... }, OverflowStrategy.BUFFER)inbuildAgentStream()queues thesink.complete()signal behind buffered events. When the downstream consumer is slow (e.g., SSE serialization + HTTP write-back), the buffer accumulates and the completion signal is delayed.The
doFinallycallback callssink.complete()which is a blocking serialization call — it waits for the buffer to drain before the completion signal propagates downstream.Fix
Replace
sink.complete()withsink.tryEmitComplete()in thedoFinallycallback.tryEmitComplete()is a non-blocking API that returns immediately with anEmitResultindicating success or failure. If it fails (e.g., the sink is already terminated), the failure is logged at WARN level for diagnostics.Testing
HarnessAgent.streamEvents()withenable_thinking=true— no 30s delay betweenPOST_REASONINGandPOST_CALLeventsCloses #2279