{"record":{"id":"340d4df60f8bcf06","repo":"microsoft/semantic-kernel","slug":"subscription-does-not-exist","errorCode":null,"errorMessage":"Subscription does not exist","messagePattern":"Subscription does not exist","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"python/semantic_kernel/agents/runtime/in_process/runtime_impl_helpers.py","lineNumber":66,"sourceCode":"    @property\n    def subscriptions(self) -> Sequence[Subscription]:\n        \"\"\"Get the list of subscriptions.\"\"\"\n        return self._subscriptions\n\n    async def add_subscription(self, subscription: Subscription) -> None:\n        \"\"\"Add a subscription to the manager.\"\"\"\n        # Check if the subscription already exists\n        if any(sub == subscription for sub in self._subscriptions):\n            raise ValueError(\"Subscription already exists\")\n\n        self._subscriptions.append(subscription)\n        self._rebuild_subscriptions(self._seen_topics)\n\n    async def remove_subscription(self, id: str) -> None:\n        \"\"\"Remove a subscription from the manager.\"\"\"\n        # Check if the subscription exists\n        if not any(sub.id == id for sub in self._subscriptions):\n            raise ValueError(\"Subscription does not exist\")\n\n        def is_not_sub(x: Subscription) -> bool:\n            return x.id != id\n\n        self._subscriptions = list(filter(is_not_sub, self._subscriptions))\n\n        # Rebuild the subscriptions\n        self._rebuild_subscriptions(self._seen_topics)\n\n    async def get_subscribed_recipients(self, topic: TopicId) -> list[AgentId]:\n        \"\"\"Get the list of recipients subscribed to a topic.\"\"\"\n        if topic not in self._seen_topics:\n            self._build_for_new_topic(topic)\n        return self._subscribed_recipients[topic]\n\n    # TODO(evmattso): optimize this...\n    def _rebuild_subscriptions(self, topics: set[TopicId]) -> None:\n        \"\"\"Rebuild the subscriptions for the given topics.\"\"\"","sourceCodeStart":48,"sourceCodeEnd":84,"githubUrl":"https://github.com/microsoft/semantic-kernel/blob/c028a0c7dc4f0814cdcbaba9d998f187a41197bf/python/semantic_kernel/agents/runtime/in_process/runtime_impl_helpers.py#L48-L84","documentation":"Thrown by the in-process runtime's subscription manager in remove_subscription(id) when no registered subscription has a matching .id. The check is `any(sub.id == id for sub in self._subscriptions)`; the comparison is against the Subscription object's id field, not the topic type or agent type. It is a plain ValueError and leaves the subscription set unchanged.","triggerScenarios":"Calling `await runtime.remove_subscription(\"some-id\")` where \"some-id\" was never added, was already removed in a prior call, or belongs to a different runtime instance. The argument must equal the .id of a Subscription previously passed to add_subscription.","commonSituations":"Passing the topic name or agent_type string instead of the subscription id; calling remove twice; subscriptions added on one InProcessRuntime but removed on another; assuming the id is auto-generated when you actually set it yourself on TypeSubscription/TypePrefixSubscription.","solutions":["Capture and reuse the exact Subscription.id you added: `sub = TypeSubscription(id='sub-1', ...); await runtime.add_subscription(sub); ...; await runtime.remove_subscription(sub.id)`","Before removing, confirm the id exists in the runtime's current subscription list (get_subscriptions / internal listing) and handle a miss explicitly.","Wrap the call in try/except ValueError to make removal idempotent if the id may already be gone."],"exampleFix":"// before\nawait runtime.remove_subscription(\"my-topic\")  # wrong: that's a topic type, not an id\n\n// after\nsub = TypeSubscription(id=\"sub-1\", topic_type=\"my-topic\", agent_type=\"MyAgent\")\nawait runtime.add_subscription(sub)\nawait runtime.remove_subscription(sub.id)  # correct: the subscription id","handlingStrategy":"try-catch","validationCode":"ids = {s.id for s in await runtime.get_subscriptions()}  # if a listing API exists\nif sub_id not in ids:\n    raise KeyError(f\"subscription {sub_id} not present; will not call remove\")\nawait runtime.remove_subscription(sub_id)","typeGuard":null,"tryCatchPattern":"try:\n    await runtime.remove_subscription(sub.id)\nexcept ValueError:\n    pass  # already absent; treat removal as idempotent","preventionTips":["Store the Subscription.id you add and reuse it for removal","Use a single runtime instance as the source of truth for subscriptions","Never pass topic type or agent_type where an id is expected"],"tags":["runtime","subscriptions","agent-runtime","validation"],"backgroundTag":null,"analyzedSha":"c028a0c7dc4f0814cdcbaba9d998f187a41197bf","analyzedAt":"2026-08-13T13:48:05.040Z","schemaVersion":2},"datasetVersion":"2026-08-13T14:17:21.547Z"}