Summary
The macOS frontend does not respond to system sleep/wake or screen sleep/wake events. This can cause stale state after wake (files changed on disk, LSP connections dropped, git status outdated) and wasted GPU rendering while screens are asleep.
Motivation
- After waking from sleep, open files may have been modified externally — the editor should detect and handle this
- LSP connections may have timed out during sleep and need reconnection
- Git status is likely stale after wake
- Metal rendering should pause when screens sleep to avoid unnecessary GPU work
- BEAM heartbeat/timers should be paused during sleep to prevent false timeout detection
Notifications to Handle
| Notification |
Action |
NSWorkspace.willSleepNotification |
Flush unsaved state, pause BEAM heartbeat/timers, notify BEAM of impending sleep |
NSWorkspace.didWakeNotification |
Trigger file staleness checks, reconnect LSP, refresh git status, resume timers |
NSWorkspace.screensDidSleepNotification |
Pause Metal rendering loop (stop setNeedsDisplay / display link) |
NSWorkspace.screensDidWakeNotification |
Resume Metal rendering, force a full re-render |
Implementation Notes
- Register observers on
NSWorkspace.shared.notificationCenter (not the default center)
willSleep fires before the system actually sleeps — use this window to flush
didWake may fire before network is fully available — LSP reconnection should retry with backoff
- Screen sleep/wake is independent of system sleep — screens can sleep on idle timeout while the system stays awake
- Consider sending a protocol message to BEAM on sleep/wake so it can pause/resume its own background work
Acceptance Criteria
🤖 Generated with Claude Code
Summary
The macOS frontend does not respond to system sleep/wake or screen sleep/wake events. This can cause stale state after wake (files changed on disk, LSP connections dropped, git status outdated) and wasted GPU rendering while screens are asleep.
Motivation
Notifications to Handle
NSWorkspace.willSleepNotificationNSWorkspace.didWakeNotificationNSWorkspace.screensDidSleepNotificationsetNeedsDisplay/ display link)NSWorkspace.screensDidWakeNotificationImplementation Notes
NSWorkspace.shared.notificationCenter(not the default center)willSleepfires before the system actually sleeps — use this window to flushdidWakemay fire before network is fully available — LSP reconnection should retry with backoffAcceptance Criteria
🤖 Generated with Claude Code