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