graph: make ahead_behind() detect and return a common ancestor