{"record":{"id":"7cc989702b95f632","repo":"github/copilot-sdk","slug":"failed-to-delete-session-sessionid-response","errorCode":null,"errorMessage":"Failed to delete session ${sessionId}: ${response.error()}","messagePattern":"Failed to delete session (.+?): (.+?)","errorType":"exception","errorClass":"RuntimeException","httpStatus":null,"severity":"error","filePath":"java/sdk/src/main/java/com/github/copilot/CopilotClient.java","lineNumber":1589,"sourceCode":"     * Permanently deletes a session and all its data from disk, including\n     * conversation history, planning state, and artifacts.\n     * <p>\n     * Unlike {@link CopilotSession#close()}, which only releases in-memory\n     * resources and preserves session data for later resumption, this method is\n     * irreversible. The session cannot be resumed after deletion.\n     *\n     * @param sessionId\n     *            the ID of the session to delete\n     * @return a future that completes when the session is deleted\n     * @throws RuntimeException\n     *             if the deletion fails\n     */\n    public CompletableFuture<Void> deleteSession(String sessionId) {\n        return ensureConnected().thenCompose(connection -> connection.rpc\n                .invoke(\"session.delete\", Map.of(\"sessionId\", sessionId), DeleteSessionResponse.class)\n                .thenAccept(response -> {\n                    if (!response.success()) {\n                        throw new RuntimeException(\"Failed to delete session \" + sessionId + \": \" + response.error());\n                    }\n                    CopilotSession session = sessions.remove(sessionId);\n                    if (session != null) {\n                        session.releaseGitHubTokenProviderRegistration();\n                    }\n                }));\n    }\n\n    /**\n     * Lists all available sessions.\n     * <p>\n     * Returns metadata about all sessions that can be resumed, including their IDs,\n     * start times, and summaries.\n     *\n     * @return a future that resolves with a list of session metadata\n     * @see SessionMetadata\n     * @see #resumeSession(String, com.github.copilot.rpc.ResumeSessionConfig)\n     */","sourceCodeStart":1571,"sourceCodeEnd":1607,"githubUrl":"https://github.com/github/copilot-sdk/blob/cd8cf15dc3f9e762615790aaed0a771a0f392755/java/sdk/src/main/java/com/github/copilot/CopilotClient.java#L1571-L1607","documentation":"deleteSession invokes the session.delete RPC; the server replies with success=false plus an error detail when it cannot delete the session. The client surfaces that as a RuntimeException inside the returned CompletableFuture, so it arrives as a failed future (or unwrapped at join).","triggerScenarios":"Calling deleteSession(sessionId) where the server rejects deletion — unknown/expired sessionId, session still active, or server-side lock — and response.success() is false.","commonSituations":"Deleting a session that already terminated server-side; double-delete after a timeout; id mismatch after reconnect; server crash recovery leaving orphan ids.","solutions":["Log response.error() from the failed future to learn the server's reason","Treat unknown-session errors as idempotent success in cleanup code","Check session state (is it still running?) before deleting; stop it first","Regenerate the session if the id no longer exists on the server"],"exampleFix":"// before\nclient.deleteSession(id).join(); // throws\n// after\nclient.deleteSession(id)\n    .exceptionally(ex -> { log.warn(\"delete failed (ignoring): {}\", ex.getMessage()); return null; })\n    .join();","handlingStrategy":"try-catch","validationCode":"if (!client.sessions.containsKey(sessionId) /* or equivalent liveness check */) {\n    // treat as already-deleted; skip RPC\n}","typeGuard":null,"tryCatchPattern":"client.deleteSession(id)\n    .exceptionally(ex -> {\n        log.warn(\"Failed to delete session {}: {}\", id, ex.getMessage());\n        return null; // idempotent cleanup\n    });","preventionTips":["Make delete idempotent in cleanup/shutdown paths","Log response.error() to distinguish unknown-session from server-lock errors","Stop sessions before deleting them"],"tags":["rpc","session","delete"],"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"}