The problem is that in direct_link_id_restore_recalc, id_current->recalc_undo_accumulated should contain the changes from the target state to the current state. However it has already been cleared at this point, to start accumulating changes up to the next undo push.
Delaying the clear of this flag seems like the obvious solution, but it's hard to find the right place for that (if there is one). Instead this splits up the flag into two separate variables.