Api4 passes GroupContact the correct way
The code here: https://lab.civicrm.org/extensions/civirules/-/blob/master/CRM/CivirulesPostTrigger/GroupContact.php#L42 assumes that $objectRef and $objectId will be passed in the idiosyncratic way that is explained in the inline comments.
But when using Api4, $objectRef and $objectId are passed much more sanely, as one would expect. Hence any GroupContact CiviRules will cause a fatal error when triggered by an API4 action.
One approach to solving it is to do something similar to this code (I did not patch CiviRules myself):
if (is_array($objectRef)) {
$contactId = $objectRef[0];
$groupId = $objectId;
}
elseif (is_object($objectRef)) {
$contactId = $objectRef->contact_id;
$groupId = $objectRef->group_id;
}
Also, for what it is worth, if you are refactoring, even though objectRef is 'an array of contact ids', I have never come across a situation where that array is longer than a single element