fix: complete ShenyuMcpResponseDecorator future only after all chunks are received (#6640) - #7040
Open
wy471x wants to merge 9 commits into
Conversation
…uture-on-first-chunk
…uture-on-first-chunk
…uture-on-first-chunk
Contributor
There was a problem hiding this comment.
🟡 Changes recommended
One or more issues must be addressed before approval.
Get a fresh assessment by requesting another Copilot review.
Pull request overview
Fixes MCP response truncation by completing the response future only after all body chunks arrive.
Changes:
- Defers future completion until stream completion.
- Centralizes completion logic for
writeWithandsetComplete. - Adds multi-chunk and empty-response tests.
File summaries
| File | Description |
|---|---|
| shenyu-plugin/shenyu-plugin-mcp-server/src/test/java/org/apache/shenyu/plugin/mcp/server/response/ShenyuMcpResponseDecoratorTest.java | Updated as part of this pull request. |
| shenyu-plugin/shenyu-plugin-mcp-server/src/main/java/org/apache/shenyu/plugin/mcp/server/response/ShenyuMcpResponseDecorator.java | Updated as part of this pull request. |
Review details
- Files reviewed: 2/2 changed files
- Comments generated: 2
- Review effort level: Lite
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
| } | ||
| } | ||
| })); | ||
| }).doOnComplete(() -> completeFuture())); |
|
|
||
| decorator.setComplete().block(); | ||
|
|
||
| assertEquals("", future.getNow("")); |
Aias00
approved these changes
Sep 19, 2026
Aias00
left a comment
Contributor
There was a problem hiding this comment.
Approved as PMC (Aias00). Coherent, well-scoped fix with regression tests; green CI, mergeable. Reviewed the diff.
…uture-on-first-chunk
…uture-on-first-chunk
…uture-on-first-chunk
…uture-on-first-chunk
…uture-on-first-chunk
This branch has not been deployed
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.
Fixes #6640
Make sure that:
./mvnw clean install -Dmaven.javadoc.skip=true.Summary
ShenyuMcpResponseDecorator.writeWithcompleted the response future insidedoOnNext, so the very first DataBuffer determined the captured result. Any response delivered in more than one chunk was therefore truncated to the first chunk.This PR defers future completion until the whole response body stream has completed (with
setComplete()kept as the empty/no-body fallback), so tool-call results now contain the full accumulated body.Changes:
ShenyuMcpResponseDecorator.writeWith(ShenyuMcpResponseDecorator.java:57) —doOnNextnow only appends each chunk to the sharedbody; adoOnComplete(() -> completeFuture())was added so the future is completed only after all chunks have been accumulated.ShenyuMcpResponseDecorator.completeFuture()(ShenyuMcpResponseDecorator.java:87) — extracts the synchronized, duplicate-completion-safe logic shared by the stream-completion path andsetComplete().ShenyuMcpResponseDecorator.setComplete()(ShenyuMcpResponseDecorator.java:80) — now delegates tocompleteFuture()before calling the delegate, preserving the no-write/empty-response fallback.Test Cases:
ShenyuMcpResponseDecoratorTest.testWriteWithCompletesFutureWithAllChunks— feeds two DataBuffers (part-1,+part-2) throughwriteWithand asserts the future receives the fullpart-1,part-2body, not just the first chunk.ShenyuMcpResponseDecoratorTest.testSetCompleteCompletesFutureWithAccumulatedBody— verifies thesetComplete()fallback still completes the future.Verification
./mvnw -o -pl shenyu-plugin/shenyu-plugin-mcp-server verifyon JDK 21 passed: checkstyle, RAT, and all module tests (including the newShenyuMcpResponseDecoratorTest).close #6640