Skip to content

[BUG] Request chunking in agent execute stream #4314

@jiapingzeng

Description

@jiapingzeng

What is the bug?

When running agent execute stream from browser, sometimes this error will occur. Seems to happen more when the request body is large.

[2025-10-13T17:41:47,981][WARN ][r.suppressed             ] [integTest-0] path: /_plugins/_ml/agents/TCMA4JkBsVJLH9hYpruJ/_execute/stream, params: {agent_id=TCMA4JkBsVJLH9hYpruJ}
org.opensearch.ml.common.exception.MLException: Got an exception in flux.
        at org.opensearch.ml.rest.RestMLExecuteStreamAction.lambda$prepareRequest$0(RestMLExecuteStreamAction.java:201) ~[?:?]
        at reactor.core.publisher.FluxConcatMapNoPrefetch$FluxConcatMapNoPrefetchSubscriber.onNext(FluxConcatMapNoPrefetch.java:183) ~[reactor-core-3.7.5.jar:3.7.5]
        at reactor.core.publisher.FluxMap$MapSubscriber.onNext(FluxMap.java:122) ~[reactor-core-3.7.5.jar:3.7.5]
        at reactor.core.publisher.FluxFilter$FilterSubscriber.onNext(FluxFilter.java:113) ~[reactor-core-3.7.5.jar:3.7.5]
        at reactor.core.publisher.FluxCreate$BufferAsyncSink.drain(FluxCreate.java:880) ~[reactor-core-3.7.5.jar:3.7.5]
        at reactor.core.publisher.FluxCreate$BufferAsyncSink.next(FluxCreate.java:805) ~[reactor-core-3.7.5.jar:3.7.5]
        at reactor.core.publisher.FluxCreate$SerializedFluxSink.next(FluxCreate.java:163) ~[reactor-core-3.7.5.jar:3.7.5]
        at org.opensearch.http.reactor.netty4.ReactorNetty4StreamingHttpChannel.receiveChunk(ReactorNetty4StreamingHttpChannel.java:100) ~[?:?]
...

I believe this is due to transfer encoding chunking causing chunks to not be valid json. Added some debug logs and here is a sample chunk that is not a valid json:

[2025-10-13T21:28:12,527][WARN ][stderr                   ] [integTest-0] STREAMING DEBUG: Processing chunk size=1024
[2025-10-13T21:28:12,528][WARN ][stderr                   ] [integTest-0] STREAMING DEBUG: Chunk content preview: {"threadId":"thread-1760416088911-dd1090w9v","runId":"run-1760416092669-b6s54ub12","messages":[{"id":"msg-1760416092669-d23clxlxj","role":"user","content":"hello"}],"tools":[{"name":"execute_ppl_query
[2025-10-13T21:28:12,529][WARN ][stderr                   ] [integTest-0] CHUNK DEBUG: Received chunk size=1024, total_buffer_size=0
[2025-10-13T21:28:12,530][WARN ][stderr                   ] [integTest-0] CHUNK DEBUG: Current content length=1024, content preview: {"threadId":"thread-1760416088911-dd1090w9v","runId":"run-1760416092669-b6s54ub12","messages":[{"id"
[2025-10-13T21:28:12,530][WARN ][stderr                   ] [integTest-0] CHUNK DEBUG: JSON complete check result: false
...

Metadata

Metadata

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions