Error: Cannot merge ObjectCoordinates

We’re trying to use /crm/v3/objects/companies/merge to merge multiple companies into a single one.
The merge of the first company into the primary company succeeds:

curl --request POST \
 --url https://api.hubapi.com/crm/v3/objects/companies/merge \
 --header 'authorization: Bearer YOUR_ACCESS_TOKEN' \
 --header 'content-type: application/json' \
 --data '{
 "objectIdToMerge": "111111",
 "primaryObjectId": "123456"
}'

However, we then try to merge the second company into the primary company as well:

curl --request POST \
 --url https://api.hubapi.com/crm/v3/objects/companies/merge \
 --header 'authorization: Bearer YOUR_ACCESS_TOKEN' \
 --header 'content-type: application/json' \
 --data '{
 "objectIdToMerge": "222222",
 "primaryObjectId": "123456"
}'

This is when we receive an error code 400 response:

{"status":"error","message":"Cannot merge ObjectCoordinates{portalId=xxxxxxx, objectTypeId=ObjectTypeId{legacyObjectType (truncated...)

Is there a restriction regarding the number of companies that can be merged into a single one? I couldn’t find any information regarding such limitations and the error message is not exactly explanatory. I tried switching around the primary and secondary id, as well as using the last secondary id as the new primary id on each iteration, with no success.

I found this bit after creating the original post:
You cannot merge records if they’ve been included in a combined total of 250+ merges (e.g, Contact A and Contact B have been involved in 130 merges each).
However neither of our companies have been involved in as many merges. In fact the error can be reproduced with freshly created companies.

Here is a full dump of the error response contents:

array(4) {
 ["status"]=>
 string(5) "error"
 ["message"]=>
 string(212) "Cannot merge ObjectCoordinates{portalId=xxxxxxx, objectTypeId=ObjectTypeId{legacyObjectType=COMPANY}, objectId=31467161499} because it has a forward reference to 31477630289. Only canonical objects can be merged."
 ["correlationId"]=>
 string(36) "aa7ec39f-acaf-4cbf-a764-491a4c5aedd7"
 ["category"]=>
 string(16) "VALIDATION_ERROR"
}

HubSpot recently changed the way it treats merged records. Now, when two records are merged, a new third record with a new hs_object_id is created. You now need to use that new record id when you’re merging the second record, and repeat for each additional record to merge.

All other endpoints have forwarding so if you call the old id, they will forward to the new record, but the merge endpoint does not have this. You have to use the new record id.

And yes, you can only merge 250 records together.

That’s it. Thank you so much.