Skip to content

fix(app) fix LateInitializationError crash in BackgroundService when mic was never started#8058

Merged
mdmohsin7 merged 2 commits into
mainfrom
fix/background-service-late-init-crash
Jun 21, 2026
Merged

fix(app) fix LateInitializationError crash in BackgroundService when mic was never started#8058
mdmohsin7 merged 2 commits into
mainfrom
fix/background-service-late-init-crash

Conversation

@krushnarout

@krushnarout krushnarout commented Jun 20, 2026

Copy link
Copy Markdown
Member

Summary

  • BackgroundService declares _service as a late field, initialized only inside init() / ensureRunning().
  • When a user taps close/skip during onboarding before the mic was ever started, SpeechProfileProvider.close()_stopPhoneMicStreaming()MicRecorderBackgroundService.stop()BackgroundService.stopRecorder() is called while _service is still uninitialized — producing a LateInitializationError.
  • Fix: guard stop() and stopRecorder() with if (_status == null) return;. _status is null iff init() was never called, so this is a reliable sentinel without changing the existing API.
  • Also removes an unused package:omi/backend/http/shared.dart import from the same file.

Crash

Fatal Exception: FlutterError
LateInitializationError: Field '_service@1489031061' has not been initialized.
package:omi/services/services.dart

0  BackgroundService.stopRecorder               (services.dart)
1  MicRecorderBackgroundService.stop + 280      (services.dart:280)
2  SpeechProfileProvider._stopPhoneMicStreaming  (speech_profile_provider.dart:222)
3  SpeechProfileProvider.close                  (speech_profile_provider.dart:413)
4  _OnboardingWrapperState.build.<fn>           (wrapper.dart:473)

Crashlytics: https://console.firebase.google.com/u/0/project/based-hardware/crashlytics/app/ios:com.friend-app-with-wearable.ios12/issues/d55812826a4ed2693249a434a764a7f3

Test plan

  • Start the speech profile onboarding flow with phone mic enabled, then immediately tap close/skip before the mic starts recording — verify no crash

🤖 Generated with Claude Code

Review in cubic

krushnarout and others added 2 commits June 20, 2026 22:25
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
…mic was never started

Guard stop() and stopRecorder() with a null _status check so calling
them before init() is a no-op instead of a LateInitializationError on _service

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

No issues found across 1 file

Re-trigger cubic

@mdmohsin7 mdmohsin7 merged commit abab535 into main Jun 21, 2026
3 checks passed
@mdmohsin7 mdmohsin7 deleted the fix/background-service-late-init-crash branch June 21, 2026 09:19
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