Hi all
There's a bug (mine) in logical decoding timeline following where reading the first page from the segment containing a timeline switch fails to read from the most recent timeline in that segment. This is harmless if the old timeline's copy of the segment is present - but if it's been renamed to .partial, deleted or never copied over to a replica then decoding will complain that the required segment has already been removed. Just like without timeline following.
The underlying problem is that timeline calculations used the record's start pointer and didn't properly consider continuations; they were record-based, not page-based like they should be.
A corrected and handily much, much simpler patch is attached. The logic for finding the last timeline on a segment was massively more complex than it needed to be, and that wasn't the only thing.