microsoft/semantic-kernel · error · ValueError
Subscription does not exist
Error message
Subscription does not exist
What it means
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.
Source
Thrown at python/semantic_kernel/agents/runtime/in_process/runtime_impl_helpers.py:66
@property
def subscriptions(self) -> Sequence[Subscription]:
"""Get the list of subscriptions."""
return self._subscriptions
async def add_subscription(self, subscription: Subscription) -> None:
"""Add a subscription to the manager."""
# Check if the subscription already exists
if any(sub == subscription for sub in self._subscriptions):
raise ValueError("Subscription already exists")
self._subscriptions.append(subscription)
self._rebuild_subscriptions(self._seen_topics)
async def remove_subscription(self, id: str) -> None:
"""Remove a subscription from the manager."""
# Check if the subscription exists
if not any(sub.id == id for sub in self._subscriptions):
raise ValueError("Subscription does not exist")
def is_not_sub(x: Subscription) -> bool:
return x.id != id
self._subscriptions = list(filter(is_not_sub, self._subscriptions))
# Rebuild the subscriptions
self._rebuild_subscriptions(self._seen_topics)
async def get_subscribed_recipients(self, topic: TopicId) -> list[AgentId]:
"""Get the list of recipients subscribed to a topic."""
if topic not in self._seen_topics:
self._build_for_new_topic(topic)
return self._subscribed_recipients[topic]
# TODO(evmattso): optimize this...
def _rebuild_subscriptions(self, topics: set[TopicId]) -> None:
"""Rebuild the subscriptions for the given topics."""View on GitHub (pinned to c028a0c7dc)
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.
Example fix
// before
await runtime.remove_subscription("my-topic") # wrong: that's a topic type, not an id
// after
sub = TypeSubscription(id="sub-1", topic_type="my-topic", agent_type="MyAgent")
await runtime.add_subscription(sub)
await runtime.remove_subscription(sub.id) # correct: the subscription id Defensive patterns
Strategy: try-catch
Validate before calling
ids = {s.id for s in await runtime.get_subscriptions()} # if a listing API exists
if sub_id not in ids:
raise KeyError(f"subscription {sub_id} not present; will not call remove")
await runtime.remove_subscription(sub_id) Try / catch
try:
await runtime.remove_subscription(sub.id)
except ValueError:
pass # already absent; treat removal as idempotent Prevention
- 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
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- Invalid AgentId key: '{key}'. Must only contain ASCII charac
- Invalid AgentId type: '{type}'. Must be alphanumeric (a-z, 0
- Invalid response from DirectLine Bot.\n{response_data}
- Invalid agent type: {type}. Allowed values MUST match the re
- Invalid agent id: {agent_id}
AI-assisted analysis of microsoft/semantic-kernel@c028a0c7dc (2026-08-13).
Data as JSON: /api/errors/340d4df60f8bcf06.
Report an issue: GitHub.