{"record":{"id":"03892707a4bc2a6a","repo":"microsoft/autogen","slug":"topicid-does-not-match-the-subscription-038927","errorCode":null,"errorMessage":"TopicId does not match the subscription","messagePattern":"TopicId does not match the subscription","errorType":"exception","errorClass":"CantHandleException","httpStatus":null,"severity":"warning","filePath":"python/packages/autogen-core/src/autogen_core/_type_subscription.py","lineNumber":58,"sourceCode":"\n    @property\n    def id(self) -> str:\n        return self._id\n\n    @property\n    def topic_type(self) -> str:\n        return self._topic_type\n\n    @property\n    def agent_type(self) -> str:\n        return self._agent_type\n\n    def is_match(self, topic_id: TopicId) -> bool:\n        return topic_id.type == self._topic_type\n\n    def map_to_agent(self, topic_id: TopicId) -> AgentId:\n        if not self.is_match(topic_id):\n            raise CantHandleException(\"TopicId does not match the subscription\")\n\n        return AgentId(type=self._agent_type, key=topic_id.source)\n\n    def __eq__(self, other: object) -> bool:\n        if not isinstance(other, TypeSubscription):\n            return False\n\n        return self.id == other.id or (self.agent_type == other.agent_type and self.topic_type == other.topic_type)\n","sourceCodeStart":40,"sourceCodeEnd":67,"githubUrl":"https://github.com/microsoft/autogen/blob/027ecf0a379bcc1d09956d46d12d44a3ad9cee14/python/packages/autogen-core/src/autogen_core/_type_subscription.py#L40-L67","documentation":"TypeSubscription.map_to_agent() requires the topic type to equal the subscription's topic_type exactly (is_match is `topic_id.type == self._topic_type`). A mismatch raises CantHandleException, the same skip-signal used by the subscription manager when filtering subscriptions for a published topic. Unlike TypePrefixSubscription, no partial matching is done.","triggerScenarios":"Directly calling `sub.map_to_agent(TopicId(\"events.created\", \"src\"))` on a TypeSubscription with topic_type \"events\" — 'events.created' != 'events', so it raises. Common when a topic type carries a suffix/namespace the subscription was not registered for.","commonSituations":"Custom routers iterating subscriptions manually; publishing to hierarchical topic types (\"events.created\") while subscribed to the bare type (\"events\") — for prefix behavior use TypePrefixSubscription; casing or whitespace mismatches between publisher and subscriber config.","solutions":["Gate with is_match() before mapping, or catch CantHandleException and skip.","Make the subscription's topic_type exactly equal the published topic's type string.","For hierarchical/prefixed topic types, switch to TypePrefixSubscription, whose is_match uses startswith."],"exampleFix":"# before\nsub = TypeSubscription(topic_type=\"events\", agent_type=\"handler\")\nagent_id = sub.map_to_agent(TopicId(\"events.created\", \"src\"))  # CantHandleException\n\n# after\nfrom autogen_core._type_prefix_subscription import TypePrefixSubscription\nsub = TypePrefixSubscription(topic_type_prefix=\"events\", agent_type=\"handler\")\nagent_id = sub.map_to_agent(TopicId(\"events.created\", \"src\"))  # ok","handlingStrategy":"type-guard","validationCode":"if sub.is_match(topic_id):  # exact string equality on topic type\n    agent_id = sub.map_to_agent(topic_id)","typeGuard":"def can_map_type_sub(sub: TypeSubscription, topic_id: TopicId) -> bool:\n    return topic_id.type == sub.topic_type","tryCatchPattern":"from autogen_core.exceptions import CantHandleException\n\ntry:\n    agent_id = sub.map_to_agent(topic_id)\nexcept CantHandleException:\n    ...  # topic not for this subscription; continue routing","preventionTips":["Subscribe to the exact topic type string publishers emit — remember TypeSubscription matches by equality, not prefix.","Centralize topic type constants shared by publisher and subscriber code to avoid typos."],"tags":["python","autogen-core","subscriptions","pubsub","routing"],"backgroundTag":null,"analyzedSha":"027ecf0a379bcc1d09956d46d12d44a3ad9cee14","analyzedAt":"2026-08-15T03:38:00.719Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}