This also happened to me locally, and I came up with the same fix, it
looks good to me.
I attached a tap test I used fo reliable local reproduction, as in was
a very unlikely failure in the existing test cases (~0.1% chance). We
probably don't want to include it in the normal test suite because it
is quite specific, but it is useful to verify that the issue/fix
exists and works.