Cosmic Mario's first appearance was in Super Mario Galaxy. His physical characteristics resemble the same shape and size of Mario. He challenges you to a race in 4 different levels, when a blue comet is nearby. If you beat him on the race, he'll reward you with a Power Star.
Cosmic Mario's background remains a mystery, although many players have theories about who he really is, and who he was. The is a probability that Cosmic Mario may be II Piantissimo from Super Mario Sunshine, who also challenged you to race him for a Shine Sprite in 3 levels. In Super Mario Sunshine, if you completed the game with 119 or less, after the ending credits, a small preview would appear revealing that II Piantissimo found the magical paintbrush Bowser Jr. used to disguise as Shadow Mario. If II Piantissimo used the magical paint brush he would have turned into Shadow Mario, with some changes. It would turn out that II Piantissimo turned into Cosmic Mario. Besides, Cosmic Mario reveals a very quick expression of dislike when the race is about to start. This could also link that II Piantissimo recognized Mario, and remembered in Super Mario Sunshine where the player must have defeated II Piantissimo on races.
Cosmic Mario can be likened to II Piantissimo who may also be linked to the Marathon Man in The Legend of Zelda: Ocarina of Time.
Cosmic Mario shows dislike at the beginning of the race.
Cosmic Mario's squeaky voice resembles Shadow Mario's. From Super Mario Sunshine
Cosmic Mario Has A resembles Shadow Mario From Super Mario Sunshine