I poked at this until I found a small modification of the existing regression tests that would reach the problematic path with lastTuple true. That confirmed that there's a problem, because it gave a flat-out wrong answer. I'm not really familiar enough with this code to be sure if this is a complete fix, but it fixes the cases we have and it doesn't break anything else in our regression tests. So, in view of the fact that we have 13.2 release deadline on Monday, I went ahead and pushed it. (I did rewrite your comment.)
That's great, I will also continue to try to check if it is a complete fix.