The XARecoveryModule currently assumes xids are globally unique. Sadly the real world isn't that simple...
In transaction inflow cases it's not possible to change the bqual for each RM, resulting in multiple unrelated RMs potentially having the same xid. When a subordinate transaction recovers, it must correctly match XAResourceRecords to XAResources, but can't rely on the uniqueness of the xid values to do this.
I placed a reproducer for the issue in my own git repo (I'll convert it to a git patch later so that you can test it against an upstream branch):
git clone https://github.com/mmusgrov/narayana
git co 4.17-
./build.sh clean install -DskipTests -Pall
./build.sh test -f ArjunaJTA/jta/pom.xml -Dtest=ImportNonUniqueBranchTest#testNotWrapped