#9926: fix(macos): guard UNUserNotificationCenter when no bundle identifier
app: macos
size: XS
Cluster:
macOS Notification and Menu Fixes
## Summary
- `UNUserNotificationCenter.current()` crashes when the process lacks a bundle identifier (e.g. `swift run`)
- Add `notificationCenterIfAvailable()` helper that returns `nil` when `Bundle.main.bundleIdentifier` is absent
- Update all three call sites to bail out gracefully instead of crashing
## Test plan
- [x] Run macOS app normally — notifications work as before
- [x] Run via `swift run` — no crash, notifications silently skipped
<!-- greptile_comment -->
<h2>Greptile Overview</h2>
<h3>Greptile Summary</h3>
This PR adds a small macOS-only guard around `UNUserNotificationCenter.current()` by introducing `notificationCenterIfAvailable()`, which returns `nil` when `Bundle.main.bundleIdentifier` is missing (e.g. `swift run`). It then updates the notification-related call sites in `NotificationManager`, `PermissionManager`, and `NodePairingApprovalPrompter` to bail out instead of crashing when notifications are unavailable.
<h3>Confidence Score: 3/5</h3>
- This PR is likely safe, but verify it builds across all macOS targets.
- Change is small and localized, but the new file-scope helper must be visible to every call site in the target; if any file is compiled in a different target/module, this will fail to compile. Once confirmed, behavior change is straightforward (skip notifications when no bundle id).
- apps/macos/Sources/OpenClaw/NotificationManager.swift (helper placement/visibility), apps/macos/Sources/OpenClaw/NodePairingApprovalPrompter.swift (call site compile/link visibility)
<!-- greptile_other_comments_section -->
<!-- /greptile_comment -->
Most Similar PRs
#15909: Guard notifications on macOS; fix focus issue and build fixes
by jasonkneen · 2026-02-14
79.1%
#3337: fix(macos-app): patch SwiftPM Bundle.module accessor for app bundle
by skymoore · 2026-01-28
72.3%
#19828: feat: reply notifications for macOS and web UI
by fal3 · 2026-02-18
72.3%
#5656: fix(macos): prevent crash on launch when no microphone available
by sfo2001 · 2026-01-31
70.5%
#14666: fix(macos): align minimum Node.js version with runtime guard (22.12.0)
by sumleo · 2026-02-12
68.7%
#3474: fix(macos): menu bar activity badge not showing during agent work
by elektricM · 2026-01-28
67.5%
#23636: iOS: normalize watch quick actions and fix test signing
by mbelinky · 2026-02-22
67.5%
#14458: fix(voicewake): avoid crash on foreign transcript ranges
by guchang · 2026-02-12
67.3%
#18235: macOS: prevent Voice Wake crash when no input device is available
by agisilaos · 2026-02-16
66.7%
#8260: fix(macOS): gateway readiness detection + reversible Configure later
by xksteven · 2026-02-03
66.5%