After a bit of chat i thought maybe it is a good idea to make an experiment.
I found that this patch seems to work. Although this is not a proof
that it works always and in any case.
However this commit (found by angavrilov) looks like we can now safely
call calchandles_fcurve() once at the end of the keyframe insertion:
https://developer.blender.org/rB68677734017ea97781e94e56d9a3eaa4f96e1338