scroll_region_{upper,lower} are only modified by the DECSTBM escape
sequence:
> This control function sets the top and bottom margins for the current
> page. You cannot perform scrolling outside the margins.
And are 0 and pane_height - 1 otherwise. Tmux implements these such that
command output can't be displayed outside these margins, but the cursor
in copy-mode can. This means that using them to check if the cursor is
at the very top or bottom can break in certain situation (even those
seem extremely rare since I have never heard of this escape sequence).
Get rid of them and just use 0 and the pane height.
[1]: https://vt100.net/docs/vt510-rm/DECSTBM.html