Skip to content

fix(agui): cancel MVC subscription on disconnect - #2786

Open
logicwu0 wants to merge 4 commits into
agentscope-ai:mainfrom
logicwu0:fix/2782-cancel-mvc-sse-subscription
Open

fix(agui): cancel MVC subscription on disconnect#2786
logicwu0 wants to merge 4 commits into
agentscope-ai:mainfrom
logicwu0:fix/2782-cancel-mvc-sse-subscription

Conversation

@logicwu0

@logicwu0 logicwu0 commented Aug 20, 2026

Copy link
Copy Markdown
Contributor

Summary

  • cancel the MVC event subscription on SSE error or timeout when interruptOnDisconnect is enabled
  • create the subscriber before disconnect callbacks are registered, so cancellation is safe before the event stream is subscribed
  • preserve the existing behavior when automatic interruption is disabled
  • add regression tests for SSE error, timeout, and the disabled configuration

Why this is still needed

The behavior reported on 2.0.1 had more than one lifecycle problem. #2646 fixed one part by preventing the conflicting RUN_ERROR followed by RUN_FINISHED sequence.

However, that change did not cancel the MVC Reactor subscription when the SSE connection fails or times out. On the latest main (bf7b7dae), the controller only interrupts the agent. The active-run entry is still released by the event stream's doFinally, so an immediate request on the same thread can still be rejected while upstream termination is delayed.

Disposing the subscription after requesting interruption triggers the cancellation lifecycle immediately and lets doFinally release the thread.

Tests

  • SSE error cancels the active subscription and allows an immediate second run
  • SSE timeout cancels the active subscription and allows an immediate second run
  • disabling interruptOnDisconnect keeps the first run active

Fixes #2782

@codecov

codecov Bot commented Aug 20, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 85.71429% with 3 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
...tscope/spring/boot/agui/mvc/AguiMvcController.java 85.71% 3 Missing ⚠️

📢 Thoughts on this report? Let us know!

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.

[Bug]:[AGUI] Agent 完成/打断后无法立即发送新消息,需等待 doFinally 执行完毕 RUN_ERROR 状态持续

1 participant