← Back to PRs

#5656: fix(macos): prevent crash on launch when no microphone available

by sfo2001 open 2026-01-31 19:54 View on GitHub →
app: macos size: XS trusted-contributor
## Summary Prevents macOS app crash on launch when no audio input device is available (e.g., Mac mini without external microphone). Fixes #5529 ## Root Cause On macOS, accessing `AVAudioEngine.inputNode` when no audio input device exists triggers a SIGABRT crash instead of failing gracefully. The existing guard for `format.channelCount > 0` (line 171) is never reached because the crash occurs earlier when accessing `inputNode`. ## Fix Added a guard checking `AVCaptureDevice.default(for: .audio) != nil` before accessing `inputNode`. This pattern is already used elsewhere in the codebase (`CameraCaptureService.swift:149`). ## Test plan **Requires hardware testing** - I don't have access to a Mac without built-in microphone. To test: 1. Use a Mac mini (or similar) with no external microphone connected 2. Launch OpenClaw.app 3. Verify app launches without crashing 4. Verify voice wake feature shows appropriate "no microphone" state instead of crashing **With microphone connected:** 1. Connect an external microphone 2. Launch OpenClaw.app 3. Verify voice wake works normally <!-- greptile_comment --> <h2>Greptile Overview</h2> <h3>Greptile Summary</h3> This PR adds an early guard in `VoiceWakeRuntime.start(with:)` to avoid a macOS crash when accessing `AVAudioEngine.inputNode` on machines with no audio input device (e.g., Mac mini without an external mic). The change checks for the presence of an audio capture device before touching `inputNode`, and throws a descriptive error that gets logged and causes the voice-wake runtime to stop cleanly. <h3>Confidence Score: 4/5</h3> - This PR is likely safe to merge and should prevent the reported crash, with some caveats around how reliably the new guard reflects audio-input availability. - The change is small and localized, and it adds an early-exit before the known-crashing access. Main concern is that `AVCaptureDevice.default(for: .audio)` may not precisely match the conditions under which `AVAudioEngine.inputNode` crashes, so it may not cover all edge cases (permissions/routing). - apps/macos/Sources/OpenClaw/VoiceWakeRuntime.swift <!-- greptile_other_comments_section --> **Context used:** - Context from `dashboard` - CLAUDE.md ([source](https://app.greptile.com/review/custom-context?memory=fd949e91-5c3a-4ab5-90a1-cbe184fd6ce8)) - Context from `dashboard` - AGENTS.md ([source](https://app.greptile.com/review/custom-context?memory=0d0c8278-ef8e-4d6c-ab21-f5527e322f13)) <!-- /greptile_comment -->

Most Similar PRs