Repository navigation
imsg-read: wait for Messages to rebuild its window after opening a chat - #172
Conversation
Opening a conversation with `open imessage:` makes Messages tear its window down and build a new one. System Events counts zero windows in between. On the macOS 27.0.1 gateway the gap ran from about 0.5 s to 1.5 s after the open, and longer under load. select_chat looked once at 1.5 s, so every --chat push failed with "Messages has no accessible window; log in and open Messages on the Mac" while the Mac was unlocked and Messages was open. Read pushes failed for about 22 hours before this was found. Keep the 1.5 s settle, then look again every 0.5 s, up to 13 looks (about 7.5 s). A Mac that really has no window still gets the same message, and a locked screen is still named.
WHAT: Weekly contributor notes for the three changes landed today, with what was verified, and the open X-handle question for Nick (@k7cfo). LR-T: blip, weekly-notes, contributors LR-D: blip LR-K: w48, k7cfo, ianswope Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01BXN1v5rSKpVomPJvPhZCng
|
Merged in You did the part that is usually missing: instead of raising the sleep and hoping, you counted the windows over time after One addition from me, folded into the merge (pushes to contributor forks are blocked on this side): the loop now stops if Checked: Generated by Claude Code |
What happened
Every
--chatread push failed with exit 64:This lasted from 23 Nov 17:21 UTC until this fix, on a gateway (macOS 27.0.1) that was unlocked and logged in, with Messages open.
ioregreported no lock, andlaunchctl print gui/<uid>returned 0. Read-onlyimsg-read --statusworked through the confined key.Cause
open imessage:open?address=…makes Messages tear its window down and build a new one. Timing on the gateway, counting windows through System Events after the open:select_chatsleeps 1.5 s and then looks once. That is right at the edge of the gap. With the Mac under load (load average around 20 at the time), the single look fell inside the gap on every attempt.Fix
Keep the 1.5 s settle, then look again every 0.5 s, up to
WINDOW_TRIES = 13looks (about 7.5 s in all). A Mac with really no window still gets the same message after that, and a locked screen is still named throughscreen_locked().Tests
test_window_rebuilt_after_open_is_selection_success: zero, zero, then one window. The selection succeeds after three looks.test_window_wait_is_bounded: never a window. It gives up after exactlyWINDOW_TRIESlooks with the existing message.python3 -m unittest test_read test_read_syncpasses.Verified live: with this
imsg-readinstalled on the gateway, the queued push that had failed 13 times went through on its next retry (exit=0 marked (0 unread)), andpendingReadsemptied.