{"record":{"id":"020c479f0eb1ba5a","repo":"github/copilot-sdk","slug":"failed-to-delete-session-sessionid-response-er","errorCode":null,"errorMessage":"Failed to delete session {sessionId}: {response.Error}","messagePattern":"Failed to delete session (.+?): (.+?)","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"dotnet/src/Client.cs","lineNumber":1753,"sourceCode":"    /// irreversible. The session cannot be resumed after deletion.\n    /// </remarks>\n    /// <example>\n    /// <code>\n    /// await client.DeleteSessionAsync(\"session-123\");\n    /// </code>\n    /// </example>\n    public async Task DeleteSessionAsync(string sessionId, CancellationToken cancellationToken = default)\n    {\n        ArgumentNullException.ThrowIfNull(sessionId);\n\n        var connection = await EnsureConnectedAsync(cancellationToken);\n\n        var response = await InvokeRpcAsync<DeleteSessionResponse>(\n            connection.Rpc, \"session.delete\", [new DeleteSessionRequest(sessionId)], cancellationToken);\n\n        if (!response.Success)\n        {\n            throw new InvalidOperationException($\"Failed to delete session {sessionId}: {response.Error}\");\n        }\n\n        if (_sessions.TryRemove(sessionId, out var session))\n        {\n            session.ReleaseGitHubTokenProviderRegistration();\n        }\n    }\n\n    /// <summary>\n    /// Lists all sessions known to the Copilot server.\n    /// </summary>\n    /// <param name=\"filter\">Optional filter to narrow down the session list by cwd, git root, repository, or branch.</param>\n    /// <param name=\"cancellationToken\">A <see cref=\"CancellationToken\"/> that can be used to cancel the operation.</param>\n    /// <returns>A task that resolves with a list of <see cref=\"SessionMetadata\"/> for all available sessions.</returns>\n    /// <exception cref=\"InvalidOperationException\">Thrown when the client is not connected.</exception>\n    /// <example>\n    /// <code>\n    /// var sessions = await client.ListSessionsAsync();","sourceCodeStart":1735,"sourceCodeEnd":1771,"githubUrl":"https://github.com/github/copilot-sdk/blob/cd8cf15dc3f9e762615790aaed0a771a0f392755/dotnet/src/Client.cs#L1735-L1771","documentation":"Thrown when the session.delete RPC completes but the CLI responds with Success=false, with response.Error carrying the server-side reason. The library surfaces that server message verbatim so the developer knows why deletion failed. The local session cache is only cleaned up when deletion succeeds.","triggerScenarios":"Calling DeleteSessionAsync (or disposing a session that deletes on close) for a sessionId the server rejects: already deleted, unknown to the server, or the server reports an internal error deleting it.","commonSituations":"Double-dispose / deleting the same session twice; deleting a session created on a different connection; CLI crash or restart that invalidated the session; server-side permission or lifecycle errors.","solutions":["Read response.Error embedded in the message for the server-side cause and fix accordingly (e.g. unknown session = already deleted)","Guard against double deletion: track whether the session was already deleted before calling DeleteSessionAsync again","Verify the sessionId matches one created on the same connection/client instance","If the session is already gone, treat this as idempotent: catch InvalidOperationException and continue cleanup"],"exampleFix":"// before\nawait client.DeleteSessionAsync(sessionId);\n// after\ntry { await client.DeleteSessionAsync(sessionId); }\ncatch (InvalidOperationException) { /* already deleted on server; ignore */ }","handlingStrategy":"try-catch","validationCode":"if (_deletedSessions.Contains(sessionId)) return; // skip duplicate delete","typeGuard":null,"tryCatchPattern":"try { await client.DeleteSessionAsync(sessionId); }\ncatch (InvalidOperationException ex) when (ex.Message.StartsWith(\"Failed to delete session\"))\n{ logger.LogWarning(ex, \"session delete rejected (possibly already gone)\"); }","preventionTips":["Track deleted session IDs to avoid double deletes","Only delete sessions created on the same client/connection","Treat delete as best-effort during teardown","Surface response.Error text in your logs"],"tags":["session","rpc","session-delete","dotnet"],"backgroundTag":"api-error-response","analyzedSha":"cd8cf15dc3f9e762615790aaed0a771a0f392755","analyzedAt":"2026-09-09T18:32:31.973Z","contentChangedAt":"2026-09-09T18:32:31.973Z","schemaVersion":2},"datasetVersion":"2026-09-15T23:17:13.987Z"}