Fix broken logic for before_exec_invalidate_opt