{"record":{"id":"d2348bc077d0f944","repo":"microsoft/semantic-kernel","slug":"subscription-with-id-subscriptionid-does-not-exi","errorCode":null,"errorMessage":"Subscription with id {subscriptionId} does not exist.","messagePattern":"Subscription with id (.+?) does not exist\\.","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"dotnet/src/Agents/Runtime/InProcess/InProcessRuntime.cs","lineNumber":222,"sourceCode":"        {\n            throw new InvalidOperationException($\"Subscription with id {subscription.Id} already exists.\");\n        }\n\n        this._subscriptions.Add(subscription.Id, subscription);\n\n#if !NETCOREAPP\n        return Task.CompletedTask.AsValueTask();\n#else\n        return ValueTask.CompletedTask;\n#endif\n    }\n\n    /// <inheritdoc/>\n    public ValueTask RemoveSubscriptionAsync(string subscriptionId)\n    {\n        if (!this._subscriptions.ContainsKey(subscriptionId))\n        {\n            throw new InvalidOperationException($\"Subscription with id {subscriptionId} does not exist.\");\n        }\n\n        this._subscriptions.Remove(subscriptionId);\n\n#if !NETCOREAPP\n        return Task.CompletedTask.AsValueTask();\n#else\n        return ValueTask.CompletedTask;\n#endif\n    }\n\n    /// <inheritdoc/>\n    public async ValueTask LoadStateAsync(JsonElement state)\n    {\n        foreach (JsonProperty agentIdStr in state.EnumerateObject())\n        {\n            AgentId agentId = AgentId.FromStr(agentIdStr.Name);\n","sourceCodeStart":204,"sourceCodeEnd":240,"githubUrl":"https://github.com/microsoft/semantic-kernel/blob/c028a0c7dc4f0814cdcbaba9d998f187a41197bf/dotnet/src/Agents/Runtime/InProcess/InProcessRuntime.cs#L204-L240","documentation":"RemoveSubscriptionAsync throws InvalidOperationException when subscriptionId is not present in the subscriptions dictionary. Removal is strict: you can only remove a subscription that was previously added and not yet removed.","triggerScenarios":"Removing an ID that was never added; removing an already-removed ID; a typo or mismatch in the ID string; attempting to remove during/after DisposeAsync drained state.","commonSituations":"Cleanup code referencing stale IDs; double-remove from concurrent teardown; ID obtained from a different runtime instance.","solutions":["Track which subscription IDs you actually added and only remove those.","Make removal tolerant: check existence (or iterate _subscriptions via the public API) before calling RemoveSubscriptionAsync.","Swallow InvalidOperationException in best-effort cleanup if a missing removal is acceptable."],"exampleFix":"// before\nawait runtime.RemoveSubscriptionAsync(maybeStaleId); // throws if absent\n\n// after\ntry { await runtime.RemoveSubscriptionAsync(maybeStaleId); }\ncatch (InvalidOperationException) { /* already removed */ }","handlingStrategy":"validation","validationCode":"// Track added subscription ids and only remove known ones.\nif (addedIds.Contains(subscriptionId))\n{\n    await runtime.RemoveSubscriptionAsync(subscriptionId);\n    addedIds.Remove(subscriptionId);\n}","typeGuard":null,"tryCatchPattern":"try { await runtime.RemoveSubscriptionAsync(subscriptionId); }\ncatch (InvalidOperationException) { /* not present; nothing to remove */ }","preventionTips":["Only remove ids you previously added.","Make removal tolerant of missing entries in cleanup paths.","Avoid concurrent double-remove of the same id."],"tags":["inprocess-runtime","subscription","removal","runtime","dotnet"],"backgroundTag":null,"analyzedSha":"c028a0c7dc4f0814cdcbaba9d998f187a41197bf","analyzedAt":"2026-08-13T13:48:05.040Z","schemaVersion":2},"datasetVersion":"2026-08-13T14:17:21.547Z"}