{"record":{"id":"7c316cec3c3456e9","repo":"microsoft/semantic-kernel","slug":"topicid-does-not-match-the-subscription-7c316c","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/semantic_kernel/agents/runtime/in_process/type_subscription.py","lineNumber":58,"sourceCode":"\n    @property\n    def topic_type(self) -> str:\n        \"\"\"Get the topic type of the subscription.\"\"\"\n        return self._topic_type\n\n    @property\n    def agent_type(self) -> str:\n        \"\"\"Get the agent type of the subscription.\"\"\"\n        return self._agent_type\n\n    def is_match(self, topic_id: TopicId) -> bool:\n        \"\"\"Check if the topic_id matches the subscription.\"\"\"\n        return topic_id.type == self._topic_type\n\n    def map_to_agent(self, topic_id: TopicId) -> AgentId:\n        \"\"\"Map the topic_id to an agent_id.\"\"\"\n        if not self.is_match(topic_id):\n            raise CantHandleException(\"TopicId does not match the subscription\")\n\n        return CoreAgentId(type=self._agent_type, key=topic_id.source)\n\n    def __eq__(self, other: object) -> bool:\n        \"\"\"Check if two subscriptions are equal.\"\"\"\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":68,"githubUrl":"https://github.com/microsoft/semantic-kernel/blob/c028a0c7dc4f0814cdcbaba9d998f187a41197bf/python/semantic_kernel/agents/runtime/in_process/type_subscription.py#L40-L68","documentation":"TypeSubscription.map_to_agent first calls is_match, which requires topic_id.type to exactly equal the subscription's topic_type. On a miss it raises CantHandleException before building the AgentId.","triggerScenarios":"A message published to a topic whose `type` is not exactly equal to the registered topic_type, or map_to_agent called with a mismatched topic (fails `topic_id.type == self._topic_type`).","commonSituations":"Exact string mismatch (extra segment, casing, trailing whitespace) between the published topic type and the subscription topic_type; using TypeSubscription where prefix matching was intended (use TypePrefixSubscription instead).","solutions":["Make the published topic type exactly equal the subscription's topic_type string.","If you need partial/flexible matching, switch to TypePrefixSubscription.","Guard with `sub.is_match(topic_id)` before mapping."],"exampleFix":"// before\nsub = TypeSubscription(id=\"s\", topic_type=\"chat\", agent_type=\"Bot\")\ntopic = TopicId(type=\"chat.user\", source=\"s1\")  # not exactly 'chat'\nagent_id = sub.map_to_agent(topic)  # CantHandleException\n\n// after\ntopic = TopicId(type=\"chat\", source=\"s1\")  # exact match\nagent_id = sub.map_to_agent(topic)","handlingStrategy":"type-guard","validationCode":"if not sub.is_match(topic_id):\n    raise ValueError(f\"topic {topic_id.type} != {sub.topic_type}; skipping\")\nagent_id = sub.map_to_agent(topic_id)","typeGuard":"def can_route_exact(sub: TypeSubscription, topic_id: TopicId) -> bool:\n    return topic_id.type == sub.topic_type","tryCatchPattern":"from semantic_kernel.exceptions import CantHandleException\ntry:\n    agent_id = sub.map_to_agent(topic_id)\nexcept CantHandleException:\n    continue","preventionTips":["Use exact string equality between published topic type and topic_type","Switch to TypePrefixSubscription when partial matching is needed","Validate is_match before mapping"],"tags":["subscriptions","agent-runtime","messaging","routing"],"backgroundTag":null,"analyzedSha":"c028a0c7dc4f0814cdcbaba9d998f187a41197bf","analyzedAt":"2026-08-13T13:48:05.040Z","schemaVersion":2},"datasetVersion":"2026-08-13T14:17:21.547Z"}