{"record":{"id":"c8a5eefc14069eed","repo":"chenhg5/cc-connect","slug":"copilot-session-delete-failed-s","errorCode":null,"errorMessage":"copilot: session.delete failed: %s","messagePattern":"copilot: session\\.delete failed: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"agent/copilot/copilot.go","lineNumber":409,"sourceCode":"\t\treturn nil\n\t}\n\n\tif delResp.Error != nil {\n\t\t// method-not-found or invalid-request means unsupported\n\t\tif delResp.Error.Code == -32601 || delResp.Error.Code == -32600 {\n\t\t\treturn nil\n\t\t}\n\t\treturn fmt.Errorf(\"copilot: session.delete: %s\", delResp.Error.Message)\n\t}\n\n\tvar result copilotDeleteSessionResponse\n\tif err := json.Unmarshal(delResp.Result, &result); err != nil {\n\t\t// Ignore parse errors - treat as success\n\t\treturn nil\n\t}\n\tif !result.Success {\n\t\tif result.Error != nil {\n\t\t\treturn fmt.Errorf(\"copilot: session.delete failed: %s\", *result.Error)\n\t\t}\n\t\treturn fmt.Errorf(\"copilot: session.delete failed: unknown error\")\n\t}\n\tslog.Info(\"copilot: session deleted\", \"sessionId\", sessionID)\n\treturn nil\n}\n\n// GetSessionHistory implements core.HistoryProvider.\n// Copilot does not expose a history RPC; return empty gracefully.\nfunc (a *Agent) GetSessionHistory(_ context.Context, _ string, _ int) ([]core.HistoryEntry, error) {\n\treturn nil, nil\n}\n\n// CompressCommand implements core.ContextCompressor.\n// Copilot has no built-in compact/compress command.\nfunc (a *Agent) CompressCommand() string { return \"\" }\n\n// ── ProviderSwitcher implementation ──────────────────────────","sourceCodeStart":391,"sourceCodeEnd":427,"githubUrl":"https://github.com/chenhg5/cc-connect/blob/4000b2338aa6e850c99df54f8b0ed6ed7460b401/agent/copilot/copilot.go#L391-L427","documentation":"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.","triggerScenarios":"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.","commonSituations":"Deleting an active/attached copilot session; stale session ID after copilot restart; backend-side deletion restrictions in the copilot service.","solutions":["Read the *result.Error text in the message for the CLI's specific reason and act on it (e.g. stop the session first)","Refresh via ListSessions to confirm the session ID is still valid before deleting","Stop/terminate the running session before attempting delete","Upgrade the copilot CLI if the refusal looks like a protocol/feature mismatch"],"exampleFix":"// before\nerr := a.DeleteSession(ctx, sessionID) // returns 'copilot: session.delete failed: session is running'\n// after\nif err := a.StopSession(ctx, sessionID); err != nil { ... } // ensure not active\nif err := a.DeleteSession(ctx, sessionID); err != nil { ... }","handlingStrategy":"try-catch","validationCode":"sessions, _ := a.ListSessions(ctx)\nfor _, s := range sessions {\n    if s.ID == sessionID {\n        // ensure session is idle/stopped before deleting\n        _ = a.StopSession(ctx, sessionID)\n    }\n}","typeGuard":null,"tryCatchPattern":"if err := a.DeleteSession(ctx, id); err != nil {\n    if strings.Contains(err.Error(), \"session.delete failed\") {\n        slog.Error(\"copilot refused delete\", \"id\", id, \"reason\", err)\n        // surface reason to user; do not retry blindly\n    }\n}","preventionTips":["Stop/terminate the session before delete","Log the *result.Error detail included in the message","Re-list sessions afterwards to confirm actual state"],"tags":["jsonrpc","copilot","session","application-error"],"backgroundTag":"api-error-response","analyzedSha":"4000b2338aa6e850c99df54f8b0ed6ed7460b401","analyzedAt":"2026-09-06T11:45:09.575Z","contentChangedAt":"2026-09-06T11:45:09.575Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}