I should have tried this sooner, but this was all running under xwayland. Running under plain X11 makes this problem totally disappear. So it seems to be an XWayland bug, I'll file an appropriate bug.
Bug 1592786 Comment 8 Edit History
Note: The actual edited comment in the bug view page will always show the original commenter’s name and original timestamp.
I should have tried this sooner, but this was all running under xwayland. Running under plain X11 makes this problem totally disappear. So it seems to be an XWayland bug, so I filed https://gitlab.freedesktop.org/xorg/xserver/-/issues/1025