Repository navigation
fix(core): deduplicate recipients of overlapping subscriptions - #8348
Open
Winoren (Winoren) wants to merge 1 commit into
Open
Winoren (Winoren) wants to merge 1 commit into
Winoren (Winoren) wants to merge 1 commit into
Conversation
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.
Why are these changes needed?
When an agent subscribes to both
eventandevent.prefixes, or to an exact topic and a matching prefix, a single publication reaches that agent twice.SubscriptionManagercurrently appends a recipient for every matching subscription, even when those subscriptions map to the sameAgentId.The topic/subscription contract specifies that each recipient receives a publication only once. Deduplicate recipients when building the per-topic cache, retaining their first-match order and allowing different agent types/keys to receive messages independently. The same logic is used when subscriptions are added or removed and cached recipients are rebuilt.
Regression tests exercise the real
SingleThreadedAgentRuntimewith overlapping prefixes and exact/prefix subscriptions, both cached and newly encountered topics, distinct recipients and source keys, and subscription removal.Related issue number
Found while inspecting the current runtime implementation; no linked issue.
Validation
On upstream
027ecf0a379bcc1d09956d46d12d44a3ad9cee14, the two new parametrized cases fail (3handler calls instead of2). With the fix:python -m pytest python/packages/autogen-core/tests/test_subscription.py python/packages/autogen-core/tests/test_runtime.py python/packages/autogen-core/tests/test_cancellation.py -q: 25 passed.mypy --config-file python/pyproject.toml --follow-imports=silenton both changed files: passed.git diff --check: passed.Used an isolated Python 3.11 environment managed with
uv, with editableautogen-coreandautogen-test-utils. Full workspace checks, documentation builds, and gRPC integration tests were not run.Checks
Prepared with Codex assistance.