Skip to content

fix(core): deduplicate recipients of overlapping subscriptions - #8348

Open
Winoren (Winoren) wants to merge 1 commit into
microsoft:mainfrom
Winoren:fix/deduplicate-overlapping-subscriptions
Open

Winoren (Winoren) wants to merge 1 commit into
microsoft:mainfrom
Winoren:fix/deduplicate-overlapping-subscriptions

Conversation

@Winoren

Copy link
Copy Markdown

Why are these changes needed?

When an agent subscribes to both event and event. prefixes, or to an exact topic and a matching prefix, a single publication reaches that agent twice. SubscriptionManager currently appends a recipient for every matching subscription, even when those subscriptions map to the same AgentId.

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 SingleThreadedAgentRuntime with 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 (3 handler calls instead of 2). 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.
  • Ruff 0.4.8 lint and format checks on both changed files: passed.
  • mypy --config-file python/pyproject.toml --follow-imports=silent on both changed files: passed.
  • git diff --check: passed.

Used an isolated Python 3.11 environment managed with uv, with editable autogen-core and autogen-test-utils. Full workspace checks, documentation builds, and gRPC integration tests were not run.

Checks

  • I've included any doc changes needed for https://microsoft.github.io/autogen/. No documentation change is needed; this restores the documented delivery behavior.
  • I've added tests (if relevant) corresponding to the changes introduced in this PR.
  • I've made sure all auto checks have passed. Local checks are listed above; upstream CI is pending.

Prepared with Codex assistance.

This branch has not been deployed

No deployments
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.

1 participant