We have some logic to detect when a projection underneath a $group stage is not needed and optimize it away. This analysis has some code that appears to be trying to check for a case like this and avoid removing the projection since it would impact the query results:
coll.aggregate([ {$project: {_id: 0, a: 1 /* NO b field output */}}, {$group: {_id: {a: "$a", b: "$b"}}} ]
Unfortunately it looks like that analysis was implemented incorrectly and instead of checking if the projection provides all the fields that the $group needs, it appears to be checking something different. I think it's whether none of the projection fields are needed by the $group? In any case, there is a demonstrable bug around this optimization that should be fixed. I'll attach a patch to demonstrate.