github/copilot-sdk · error

Failed to delete session

Error message

Failed to delete session ${sessionId}: ${error || "Unknown error"}

What it means

The session.delete RPC completed but returned success: false — the runtime acknowledged the request yet refused/failed to delete the session, and the message embeds the runtime's own error string (or 'Unknown error' when the response carried none). Common causes: the session is still active/foreground, or server-side cleanup failed.

Solutions

  1. Inspect the embedded error string — it comes from the runtime and names the actual failure reason
  2. Disconnect or stop the session before deleting it
  3. Verify the sessionId exists and is not protected (e.g. the foreground session)
  4. Retry once after addressing the reported cause; transient server-side cleanup failures do occur
Defensive patterns

Strategy: retry

When it happens

Trigger: Thrown at nodejs/src/client.ts:2297 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of github/copilot-sdk@cd8cf15dc3 (2026-09-09). Data as JSON: /api/errors/a036ad5d914c8ec7. Report an issue: GitHub.

Appendix: source

Thrown at nodejs/src/client.ts:2297

     * @throws Error if the session does not exist or deletion fails
     *
     * @example
     * ```typescript
     * await client.deleteSession("session-123");
     * ```
     */
    async deleteSession(sessionId: string): Promise<void> {
        if (!this.connection) {
            throw new Error("Client not connected");
        }

        const response = await this.connection.sendRequest("session.delete", {
            sessionId,
        });

        const { success, error } = response as { success: boolean; error?: string };
        if (!success) {
            throw new Error(`Failed to delete session ${sessionId}: ${error || "Unknown error"}`);
        }

        const session = this.sessions.get(sessionId);
        this.sessions.delete(sessionId);
        session?._runOnDisconnected();
    }

    /**
     * List all available sessions.
     *
     * @param filter - Optional filter to limit returned sessions by context fields
     *
     * @example
     * // List all sessions
     * const sessions = await client.listSessions();
     *
     * @example
     * // List sessions for a specific repository

View on GitHub (pinned to cd8cf15dc3)