Fix assertion failures reported in #16533