Skip to content

fix: keep notification clearance from freezing the bar - #129

Merged
Seb-GRAF merged 1 commit into
stablebox:mainfrom
alexandrebucci:fix/notification-clearance-freeze
Oct 21, 2026
Merged

Seb-GRAF merged 1 commit into
stablebox:mainfrom
alexandrebucci:fix/notification-clearance-freeze

Conversation

@alexandrebucci

Copy link
Copy Markdown
Contributor

Problem

With bar.keepNotificationsClear on, StableBar stops responding after a while and has to be force-quit. Its main thread never leaves WindowClearance.moveBanners(), CPU stays between 50% and 75%, and memory keeps growing.

On 0.5.0-beta.123 and 0.5.0-beta.20261020113356.133 (macOS 26.6.2, M4 Pro, keepWindowsClear and keepNotificationsClear on), macOS wrote four cpu_resource reports in one day, for four separate processes. Each was force-quit, and each report has the same heaviest stack:

@objc closure #1 in WindowClearance.watchNotificationCenter()
  WindowClearance.moveBanners() + 536
    specialized WindowClearance.banner(in:) + 448
      _platform_memmove
CPU:           90 seconds cpu time over 175 seconds (51% cpu average), exceeding limit of 50% cpu over 180 seconds
Footprint:     196.81 MB -> 339.70 MB (+142.89 MB)
User Activity: 21 samples Idle, 15 samples Active
On Behalf Of:  NotificationCenter

A 3-second sample of a frozen bar put all 2255 main-thread samples in moveBanners(): 1586 in _platform_memmove, the rest in AXUIElementCopyAttributeValue calls to Notification Center. Its physical footprint was 825 MB. In the release binary, banner(in:) + 444 calls replaceSubrange(0..<1, with: EmptyCollection), so the memmove is elements.removeFirst().

banner(in:) walks Notification Center's Accessibility tree breadth-first, with no record of visited elements and no bound. Shifting the queue only outweighs the three Accessibility round trips made for each element when the queue holds hundreds of thousands of elements. That is far more than Notification Center shows, so the children it reads either lead back to elements already queued or keep producing new ones, and the walk never finishes. Memory grows with the queue.

Changes

  • Move the walk into firstBanner(in:limit:kind:children:). It looks at each element once, stops after 200 elements, and reads its queue by index instead of removeFirst().
  • banner(in:) keeps its checks: the notification list ends the search, and the first AXNotificationCenter* subrole is the banner.

Testing

  • swift test (Xcode 26.1.1, Swift 6.2.1): 245 XCTest tests and 355 Swift Testing tests passed.
  • New tests cover the breadth-first order and the notification list, a cyclic tree and an endless tree. With the previous loop, the cyclic test looked at elements 0, 1 and 2 over and over until the test's own guard stopped it, and the endless tree looked at 2001 elements instead of 50.
  • Not checked: the branch build against Notification Center on macOS 26. The Accessibility tree couldn't be read here, so which elements repeat is unconfirmed. Banners still moving below the bar, and the 200-element limit leaving enough room to reach them, both need a live check.

Merging

Rebase or squash merge; this is one Conventional Commit.

Claude Opus 5.5 via Claude Code

banner(in:) walked Notification Center's Accessibility tree breadth-first
without remembering visited elements or bounding the walk. On macOS 26 the
walk never finished: the main thread stayed in moveBanners(), most of it
shifting the queue in removeFirst(), and memory grew until the bar was
force-quit. The walk now looks at each element once, stops after 200
elements and reads its queue by index.
@Seb-GRAF
Seb-GRAF merged commit 5eacb5e into stablebox:main Oct 21, 2026
4 checks passed
@stablebar-releases

Copy link
Copy Markdown

🎉 This PR is included in version 0.5.0 🎉

The release is available on GitHub release

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants