Skip to content

test(mcp): cover last-event-id 404 guard; remove dead replay code - #3253

Open
arimu1 wants to merge 1 commit into
alibaba:masterfrom
arimu1:fix/mcp-last-event-id-404-3118
Open

test(mcp): cover last-event-id 404 guard; remove dead replay code#3253
arimu1 wants to merge 1 commit into
alibaba:masterfrom
arimu1:fix/mcp-last-event-id-404-3118

Conversation

@arimu1

@arimu1 arimu1 commented Aug 1, 2026

Copy link
Copy Markdown

Summary

The immediate 404 when last-event-id is present on GET SSE requests was already fixed in c8c585d0d (#3118). This PR does not re-fix that behavior.

This change:

  • Adds EmbeddedChannel regression tests for the existing last-event-id / Last-Event-ID guard (runs before session lookup, so tests use an arbitrary session id)
  • Removes the unreachable replay branch that remained after that early reject

Relates-to #3118

Verification

./mvnw -pl arthas-mcp-server test

Result: 15 tests passed (including 2 new handler tests).

@hengyunabc
hengyunabc requested a balanced review from Copilot August 12, 2026 03:45

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

Warning

Copilot couldn't run its full agentic review because it didn't start before the timeout. Make sure your repository has a runner available, or add a copilot-code-review.yml file specifying one with the runs-on attribute. See the docs for more details.

Adjusts MCP SSE GET handling to explicitly reject unsupported SSE resume via last-event-id, preventing hanging connections and ensuring clients re-initialize properly.

Changes:

  • Return 404 immediately when last-event-id is present on GET SSE requests.
  • Remove the unreachable/hang-prone replay branch in GET handling.
  • Add EmbeddedChannel regression tests covering last-event-id and Last-Event-ID header behavior.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.

File Description
arthas-mcp-server/src/main/java/com/taobao/arthas/mcp/server/protocol/server/handler/McpStreamableHttpRequestHandler.java Rejects unsupported last-event-id resume up-front and simplifies GET SSE handling by removing replay logic.
arthas-mcp-server/src/test/java/com/taobao/arthas/mcp/server/protocol/server/handler/McpStreamableHttpRequestHandlerTest.java Adds regression tests to ensure last-event-id triggers immediate 404 and the connection doesn’t hang.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment on lines +131 to +138
private static EmbeddedChannel newChannel(McpStreamableHttpRequestHandler handler) {
return new EmbeddedChannel(new SimpleChannelInboundHandler<FullHttpRequest>(false) {
@Override
protected void channelRead0(ChannelHandlerContext ctx, FullHttpRequest request) throws Exception {
handler.handle(ctx, request);
}
});
}
Comment on lines +61 to +64
// Must not leave a hanging SSE stream open for the client to time out on.
assertThat((Object) channel.readOutbound()).isNull();
assertThat(channel.isActive()).isFalse();
channel.finishAndReleaseAll();
Comment on lines +200 to +205
* Handles GET requests to establish SSE listening streams.
* <p>
* Resume via {@code last-event-id} is not supported. Clients such as Cherry Studio may
* reconnect with that header after the server closes a completed streamable response;
* answering immediately with 404 lets them re-initialize instead of hanging until timeout
* (see #3118).

@hengyunabc hengyunabc 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.

这里的回归测试在 PR 父提交 a960592c7 上也会通过,因此目前无法证明这个 PR 修复了 #3118

handleGetRequestlast-event-id 直接返回 404 的 guard 已由 c8c585d0d 引入,并且在本 PR 的 merge-base 中已经存在;本 PR 的生产代码实际只删除了该 guard 之后不可达的 replay 分支。两个新增测试也都只验证这个既有 guard。

如果 #3118 目前仍可复现,请先补充一个在父提交上失败、覆盖真实 Netty 请求入口的回归测试,再修复实际未返回 404 的请求链路。如果问题已经由 c8c585d0d 修复,请将本 PR 明确调整为既有修复的测试补充和死代码清理(例如 test/refactor(mcp)),不要再声明由此 PR 修复 #3118

另外,目标分支位于 session 查找之前,测试可以直接使用任意 session ID,无需搭建完整初始化流程和 StubCommandExecutor

本地在最新 master 合并结果上执行 ./mvnw -pl arthas-mcp-server test,15 个测试全部通过。

@arimu1 arimu1 changed the title fix(mcp): return 404 for unsupported last-event-id resume test(mcp): cover last-event-id 404 guard; remove dead replay code Aug 12, 2026
@arimu1
arimu1 force-pushed the fix/mcp-last-event-id-404-3118 branch from 16226c0 to 1f78131 Compare August 12, 2026 23:49
@arimu1

arimu1 commented Aug 12, 2026

Copy link
Copy Markdown
Author

Thanks for the review — agreed.

I confirmed the last-event-id → 404 guard is already present on master from c8c585d0d, and the new tests pass on parent a960592c7 as well, so this PR is not a bugfix for #3118.

Updated accordingly:

  • Reframed as test supplementation + dead-code cleanup (test(mcp): …)
  • Removed Fixes #3118; linked with Relates-to #3118
  • Simplified tests: arbitrary session id via EmbeddedChannel, no init flow / StubCommandExecutor
  • Kept removal of the unreachable replay branch after the early guard

./mvnw -pl arthas-mcp-server test — 15 tests green locally.

Please take another look when you have time.

The immediate 404 for unsupported last-event-id resume was already added
in c8c585d (alibaba#3118). This change adds EmbeddedChannel regression tests
for that guard and removes the unreachable replay branch after it.

Relates-to alibaba#3118
@arimu1
arimu1 force-pushed the fix/mcp-last-event-id-404-3118 branch from 1f78131 to 85f1c52 Compare August 12, 2026 23:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants