microsoft/autogen · error · Exception

Subscription with id {subscriptionId} does not exist.

Error message

Subscription with id {subscriptionId} does not exist.

What it means

GrpcAgentTypesHost.RemoveSubscriptionAsync throws when removing a subscription id that is not in the Subscriptions dictionary. Despite the name (and bool return), it fails fast on unknown ids instead of returning false — the guard precedes the Remove call.

Source

Thrown at dotnet/src/Microsoft.AutoGen/Core.Grpc/GrpcAgentRuntime.cs:78

        this.agentFactories.Add(type, factoryFunc);
        return type;
    }

    public void AddSubscription(ISubscriptionDefinition subscription)
    {
        if (this.Subscriptions.ContainsKey(subscription.Id))
        {
            throw new Exception($"Subscription with id {subscription.Id} already exists.");
        }

        this.Subscriptions.Add(subscription.Id, subscription);
    }

    public bool RemoveSubscriptionAsync(string subscriptionId)
    {
        if (!this.Subscriptions.ContainsKey(subscriptionId))
        {
            throw new Exception($"Subscription with id {subscriptionId} does not exist.");
        }

        return this.Subscriptions.Remove(subscriptionId);
    }

    public HashSet<AgentType> RegisteredAgentTypes => this.agentFactories.Keys.ToHashSet();
    public IEnumerable<IHostableAgent> LiveAgents => this.agentInstances.Values;
}

public sealed class GrpcAgentRuntime : IHostedService, IAgentRuntime, IMessageSink<Message>, IDisposable
{
    public GrpcAgentRuntime(AgentRpc.AgentRpcClient client,
                            IHostApplicationLifetime hostApplicationLifetime,
                            IServiceProvider serviceProvider,
                            ILogger<GrpcAgentRuntime> logger,
                            bool strictMessageDeserialization = false)
    {
        this._client = client;

View on GitHub (pinned to 027ecf0a37)

Solutions

  1. Guard with host.Subscriptions.ContainsKey(id) before removal.
  2. Track which ids you actually added (add/remove symmetrically in the same component).
  3. Normalize id strings (trim, exact casing) at both registration and removal sites.

Example fix

// before
host.RemoveSubscriptionAsync("sub1"); // throws if never added / already removed

// after
if (host.Subscriptions.ContainsKey("sub1"))
{
    host.RemoveSubscriptionAsync("sub1");
}
Defensive patterns

Strategy: validation

Validate before calling

if (host.Subscriptions.ContainsKey(subscriptionId))
{
    host.RemoveSubscriptionAsync(subscriptionId);
}

Type guard

static bool CanRemoveSubscription(GrpcAgentTypesHost host, string id) =>
    host.Subscriptions.ContainsKey(id);

Prevention

When it happens

Trigger: Calling RemoveSubscriptionAsync(id) after the subscription was already removed, was never added on this host instance, or when the id string does not exactly match (case/whitespace/encoding differences).

Common situations: Cleanup/teardown code paired with startup that partially failed; duplicate disposal paths (Dispose plus explicit teardown); passing a subscription id obtained from a different host/process; re-creating hosts across reconnects while tracking ids externally.

Related errors


AI-assisted analysis of microsoft/autogen@027ecf0a37 (2026-08-15). Data as JSON: /api/errors/aa2ca0c050883ee3. Report an issue: GitHub.