Fix to-device messages, including room keys, sometimes being lost before delivery. Contributed by @eleboucher.