Whose sides were Guilty Spark and Gravemind on anyway?
Name your enemies in Halo 3. The Covenant? Well, partially, but don't forget that the Arbiter and his entire faction of Covenant Elites are now mankind's strongest allies. 343 Guilty Spark? While Master Chief and the orb do end up trying to murder each other in the end, they spend two-thirds of the game (and large portions of the other two games) as best buddies. Gravemind and the Flood? This one would seem obvious if the army of zombies didn't fight alongside you for an entire mission.
For what's been labeled a simple and straightforward shooter, picking out the bad guys is a lot tougher than you'd expect.
Our best guess: Although Guilty Spark and Gravemind's allegiances shift constantly during the Halo trilogy, their singular purposes do not. Let's tackle them one by one.
Guilty Spark was designed and programmed by the Forerunners to activate and protect Halo structures when necessary, i.e. when the Flood is loose. Therefore, when Master Chief decides to fire the new Halo to destroy the Flood, that action fits right into Guilty Spark's protocol. However, when Master Chief decides to fire the Halo before it is fully constructed, an action that would destroy the ring itself in the process, Guilty Spark must turn against him.
Gravemind, intelligent as he sounds, is still a Flood entity. His goal, therefore, is to consume all other life in the universe. Anytime he assists you in any of the three games, it is only because he needs you to further his aims. You are his puppet.
To summarize: Guilty Spark is on the side of his ancient Forerunner programming and Gravemind is on his own side. They are only on your side when your objectives happen, coincidentally, to match theirs.