popupabove() took the stacking order from XQueryTree and then the map
state of each child from a round trip of its own. The daemon raises and
maps between those, in that order and in one flush, so the loop could pair
a stale order -- popup still below the client, where it was created -- with
a fresh IsViewable, and report the raise that had already happened as a
popup stacked below the client. 1 run in 25 under load, which is the worst
kind: often enough to teach you to re-run a red instead of reading it.
Widening the gap to 300ms shows it with no load at all, and shows the fix
is the right one. Same test, same widener, 15 runs each:
before pass=11 fail=4
after pass=15 fail=0
XGrabServer is what makes the two one observation, and the widener is then
harmless because nothing can raise inside it. Unwidened, 20 runs clean.
Nothing about win.c was wrong: the popup does go above, and the test now
only says so when it is looking at a single moment.
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>