I caught this while working on another bug. But I won't have opportunity to work on it during this project. I think these queries that trxfr records from ah to a will only transfer one contribution/membership/etc. per contact due to the grouping.
INSERT INTO civicrm_activity (`source_contact_id`, `source_record_id`, `activity_type_id`, `subject`, `activity_date_time`, `due_date_time`, `duration`, `location`, `phone_id`, `phone_number`, `details`, `status_id`, `priority_id`, `parent_id`, `is_test`)
SELECT ah.entity_id, ah.activity_id, @ov_id_contribute, ah.activity_summary,
ah.activity_date, NULL, NULL, NULL, NULL, NULL,
ah.activity_summary, @ov_id_completed, NULL, NULL, ah.is_test
FROM civicrm_activity_history ah
WHERE ah.module IN ('CiviContribute')
GROUP BY ah.module, ah.entity_id;
multiple contributions/memeberships/etc. will be lost because it only groups on the first column. The other columns will be whats randomly in one of the matching rows but there's no way to know which row. I tested my theory by running the select query on an existing db (not the one I'm currently upgrading because it has no contributions/memberships).
The sollution might be just to remove the GROUP BY