Skip to content

CaptureProvider._processVoiceCommandBytes - Null check crash#4532

Closed
aaravgarg wants to merge 2 commits intomainfrom
fix/ios-crash-capture-provider-null-check
Closed

CaptureProvider._processVoiceCommandBytes - Null check crash#4532
aaravgarg wants to merge 2 commits intomainfrom
fix/ios-crash-capture-provider-null-check

Conversation

@aaravgarg
Copy link
Collaborator

Summary

  • Add null check for _recordingDevice before accessing .id in _processVoiceCommandBytes
  • Prevents crash when device disconnects during voice command processing

Crash Stats

Test plan

  • Verify voice commands still work when device is connected
  • Test disconnecting device during voice command (should log warning, not crash)

🤖 Generated with Claude Code

Prevent null check crash when _recordingDevice is null during voice
command processing (e.g. device disconnected mid-session).

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
@aaravgarg aaravgarg requested a review from mdmohsin7 February 1, 2026 23:16
Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request addresses a crash in _processVoiceCommandBytes by adding a null check for _recordingDevice before it's accessed. This is a good and necessary fix. I've suggested a small improvement to make the code even more robust by capturing _recordingDevice in a local variable. This avoids using the null-assertion operator (!) and makes the code safer against potential race conditions.

Comment on lines 472 to 477
if (_recordingDevice == null) {
Logger.debug("_processVoiceCommandBytes: recording device is null, skipping");
return;
}

BleAudioCodec codec = await _getAudioCodec(_recordingDevice!.id);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

While adding the null check is a good fix for the crash, it's better to avoid using the null-assertion operator (!) on _recordingDevice. Since _recordingDevice is a mutable class field, the compiler can't guarantee it won't be null after the check, especially with await calls.

A safer approach is to capture _recordingDevice in a local variable. This allows for type promotion and removes the need for the ! operator, making the code more robust against potential race conditions.

    final recordingDevice = _recordingDevice;
    if (recordingDevice == null) {
      Logger.debug("_processVoiceCommandBytes: recording device is null, skipping");
      return;
    }

    BleAudioCodec codec = await _getAudioCodec(recordingDevice.id);

Prevents potential null dereference if _recordingDevice becomes null
between the null check and the await _getAudioCodec call.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
@mdmohsin7
Copy link
Member

closed in #4628

@mdmohsin7 mdmohsin7 closed this Feb 5, 2026
@github-actions
Copy link
Contributor

github-actions bot commented Feb 5, 2026

Hey @aaravgarg 👋

Thank you so much for taking the time to contribute to Omi! We truly appreciate you putting in the effort to submit this pull request.

After careful review, we've decided not to merge this particular PR. Please don't take this personally — we genuinely try to merge as many contributions as possible, but sometimes we have to make tough calls based on:

  • Project standards — Ensuring consistency across the codebase
  • User needs — Making sure changes align with what our users need
  • Code best practices — Maintaining code quality and maintainability
  • Project direction — Keeping aligned with our roadmap and vision

Your contribution is still valuable to us, and we'd love to see you contribute again in the future! If you'd like feedback on how to improve this PR or want to discuss alternative approaches, please don't hesitate to reach out.

Thank you for being part of the Omi community! 💜

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants