chenhg5/cc-connect · error

copilot: session.delete failed: %s

Error message

copilot: session.delete failed: %s

What it means

The session/delete RPC succeeded at the transport level and its result parsed, but the result payload reports success=false with a non-nil Error string. This is an application-level failure reported inside a well-formed JSON-RPC result, surfaced with the CLI's error text. Callers should treat it as the delete not having happened.

Source

Thrown at agent/copilot/copilot.go:409

		return nil
	}

	if delResp.Error != nil {
		// method-not-found or invalid-request means unsupported
		if delResp.Error.Code == -32601 || delResp.Error.Code == -32600 {
			return nil
		}
		return fmt.Errorf("copilot: session.delete: %s", delResp.Error.Message)
	}

	var result copilotDeleteSessionResponse
	if err := json.Unmarshal(delResp.Result, &result); err != nil {
		// Ignore parse errors - treat as success
		return nil
	}
	if !result.Success {
		if result.Error != nil {
			return fmt.Errorf("copilot: session.delete failed: %s", *result.Error)
		}
		return fmt.Errorf("copilot: session.delete failed: unknown error")
	}
	slog.Info("copilot: session deleted", "sessionId", sessionID)
	return nil
}

// GetSessionHistory implements core.HistoryProvider.
// Copilot does not expose a history RPC; return empty gracefully.
func (a *Agent) GetSessionHistory(_ context.Context, _ string, _ int) ([]core.HistoryEntry, error) {
	return nil, nil
}

// CompressCommand implements core.ContextCompressor.
// Copilot has no built-in compact/compress command.
func (a *Agent) CompressCommand() string { return "" }

// ── ProviderSwitcher implementation ──────────────────────────

View on GitHub (pinned to 4000b2338a)

Solutions

  1. Read the *result.Error text in the message for the CLI's specific reason and act on it (e.g. stop the session first)
  2. Refresh via ListSessions to confirm the session ID is still valid before deleting
  3. Stop/terminate the running session before attempting delete
  4. Upgrade the copilot CLI if the refusal looks like a protocol/feature mismatch

Example fix

// before
err := a.DeleteSession(ctx, sessionID) // returns 'copilot: session.delete failed: session is running'
// after
if err := a.StopSession(ctx, sessionID); err != nil { ... } // ensure not active
if err := a.DeleteSession(ctx, sessionID); err != nil { ... }
Defensive patterns

Strategy: try-catch

Validate before calling

sessions, _ := a.ListSessions(ctx)
for _, s := range sessions {
    if s.ID == sessionID {
        // ensure session is idle/stopped before deleting
        _ = a.StopSession(ctx, sessionID)
    }
}

Try / catch

if err := a.DeleteSession(ctx, id); err != nil {
    if strings.Contains(err.Error(), "session.delete failed") {
        slog.Error("copilot refused delete", "id", id, "reason", err)
        // surface reason to user; do not retry blindly
    }
}

Prevention

When it happens

Trigger: DeleteSession receiving copilotDeleteSessionResponse{Success:false, Error:&msg} — e.g. the target session does not exist in the CLI, is still running/attached, or the backend refuses removal.

Common situations: Deleting an active/attached copilot session; stale session ID after copilot restart; backend-side deletion restrictions in the copilot service.

Related errors


AI-assisted analysis of chenhg5/cc-connect@4000b2338a (2026-09-06). Data as JSON: /api/errors/c8a5eefc14069eed. Report an issue: GitHub.