Repository navigation
Conversation
…e event-bus channel map AgentProtocolTaskEventBus created a channel for every task id ever subscribed to and only removed it in complete(). A client that reconnected after completion therefore opened a fresh channel that nothing could complete and waited for the SSE timeout (three hours by default), while an id that never belonged to a real task kept a replay-buffered channel forever. Retain completed channels so a late subscriber drains the replay buffer and then completes, bound the channel map (completed channels evicted first, oldest first), and remember finished ids so a reconnect to an evicted task also terminates at once.
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.
Problem
Fixes #3785.
AgentProtocolTaskEventBuskeeps a channel for every task id ever subscribed to — including ids that do not exist — and never completes a subscriber that connects aftercomplete():subscribe()builds a channel withcomputeIfAbsent, andcomplete()is the only removal. Only real tasks ever reachcomplete(), so 2000 subscribes with 2000 distinct ids retain 2000 channels (each with a 256-event replay buffer) on currentmain.complete()removes the channel and then completes its sink, so a reconnect afterwards creates an empty channel whosefilter(seq > fromSeq)drops everything and which nothing can ever complete → the SSE stream stays open until the controller'stake(timeout), i.e.sseTimeoutMs= 3 hours by default.Changes
complete()removes the channelDEFAULT_MAX_CHANNELS = 1024; eviction prefers completed channels (oldest first) and only falls back to the oldest live channel when every channel is livepublish()andsubscribe()each calledcomputeIfAbsentchannel()lookupAgentProtocolEventBusis unchanged and the existing constructors keep their behaviour; the two-argument constructor and the package-visiblechannelCount()exist for the tests.Verification
Probe compiled against both versions (public API plus the private channel map), on current
main(16cb024ae):maincomplete()IllegalStateException: Timeout on blocking read for 2000000000 NANOSECONDS(2 s probe; 3 h in production)retained channels must be bounded, was 2000mvn -pl agentscope-extensions/agentscope-extensions-protocol/agentscope-extensions-agent-protocol test: 37 tests, 0 failures.AgentProtocolTaskEventBusTestgoes 4 → 9 cases and the four existing cases are untouched.mvn spotless:check: passes.Not addressed here
submit, so the bus cannot distinguish "a real task that has not published its first event yet" from "an id that does not exist". Closing that needs validation in the controller or the store.publish()aftercomplete()is now dropped (debug log) instead of recreating a channel. A completed task never legitimately publishes again, and recreating the channel is exactly what leaked.