Skip to content

fix(capture): handle async capture failures in quick actions mute/unmute and home record button (#19245) - #21303

Closed
Dragonire9 wants to merge 6 commits into
BasedHardware:mainfrom
Dragonire9:fix/capture-failure-feedback-quick-actions
Closed

Dragonire9 wants to merge 6 commits into
BasedHardware:mainfrom
Dragonire9:fix/capture-failure-feedback-quick-actions

Conversation

@Dragonire9

@Dragonire9 Dragonire9 commented Oct 12, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Resolves #19245

Addresses unhandled async capture command errors when pausing/resuming capture via Quick Actions or stopping recording via the Home record button. Previously, failures in coordinator dispatches (outcome.throwIfFailed()) caused unhandled async exceptions in the zone error handler with no visual feedback.

Key Changes

  1. Quick Actions Service (app/lib/services/quick_actions_service.dart):

    • Converted _toggleMute to async and awaited captureProvider.pauseCapture() / resumeCapture() inside try/catch.
    • On error, safely surfaces user-facing feedback with OmiFeedback.error(context, context.l10n.somethingWentWrong) when context.mounted.
    • Wrapped _handleShortcut and _toggleMute dispatches with unawaited.
    • Added test helpers handleShortcutForTesting and toggleMuteForTesting.
  2. Home Record Button (app/lib/pages/home/widgets/battery_info_widget.dart):

    • Wrapped await captureProvider.finishCapture() in try/catch within _startPhoneRecording, ensuring that stop errors display OmiFeedback.error(context, context.l10n.somethingWentWrong) and return gracefully.
    • Wrapped await _startPhoneRecording(context) in _startRecording with try/catch and OmiFeedback.error fallback.
    • Wrapped gesture callbacks with unawaited.
  3. Automated Regression Tests:

    • app/test/widgets/capture_home_ui_test.dart: Added test assertions verifying that tapping the button while recording invokes finishCapture(), and that an error from finishCapture() displays en.somethingWentWrong without unhandled errors.
    • app/test/services/quick_actions_service_test.dart: Added hermetic unit/widget tests verifying that QuickActionsService mute/unmute commands call pauseCapture and resumeCapture, and catch failures to show en.somethingWentWrong.

View guided diff

Failure-Class: none
UI-Evidence: none

@Git-on-my-level

Copy link
Copy Markdown
Member

Thanks for this — the direction is right and the tests are a welcome addition. I reviewed all four changed files; notes below.

app/lib/services/quick_actions_service.dart

  • Making _toggleMute async and awaiting pauseCapture()/resumeCapture() inside try/catch is the correct fix: both are Future<void> on the capture controller and their dispatch outcomes call throwIfFailed(), which is exactly where the unhandled async errors from Quick Actions Mute/Unmute and the Home record button drop capture failures silently #19245 originated. Showing OmiFeedback.error with l10n.somethingWentWrong on failure (guarded by context.mounted) is the right user-facing recovery, and the unawaited() wrappers at the _handleShortcut call sites make the fire-and-forget intent explicit instead of relying on implicit Future ignoring.
  • One design question: handleShortcutForTesting duplicates the entire _handleShortcut switch (~30 lines). That means the production dispatch path stays untested while the tests exercise a parallel copy that can drift from it — e.g. a future shortcut added to _handleShortcut but not the testing twin would silently pass tests. Extracting a shared dispatch method that both the real callback and tests call would remove the duplication. Non-blocking, but worth considering.
  • Minor: when a quick action fires from the home-screen shortcut, a toast may never be visible (the app may not be foregrounded). Not a blocker for this PR, but something to keep in mind for the mute/unmute UX.

app/lib/pages/home/widgets/battery_info_widget.dart

  • Wrapping the finishCapture() await in try/catch with early return, and the OmiFeedback.error + context.mounted guard, are correct and match the existing style.
  • The outer try/catch in _startRecording around _startPhoneRecording is the one place I'd ask for clarification: _startPhoneRecording already handles its own failures internally (the finishCapture catch, and the start path), so which failures still escape to the outer catch? And in that outer catch, if the widget is unmounted the error is silently discarded — no feedback and no log. If the intent is a belt-and-braces fallback, an error log (or rethrow) alongside the mounted-guarded toast would make the failure debuggable in the field.
  • The unawaited() wrappers on the sheet callbacks and the two onTap handlers are fine and consistent.

app/test/services/quick_actions_service_test.dart

  • Good hermetic setup: _MockCapture implements just pause/resume with injectable failures, localizations wired through AppLocalizations delegates so somethingWentWrong resolves, and both success and failure paths asserted (call counts + toast presence/absence).

app/test/widgets/capture_home_ui_test.dart

  • The two new cases (stop tap invokes finishCapture; a failing stop shows somethingWentWrong without unhandled errors) directly cover the regression in question. The mock additions (finishCaptures counter, finishCaptureFailure) are minimal and don't disturb existing tests.

One caveat for the maintainer merging this: the checks on this PR haven't run a test suite (only the AI reviewer, status neutral), so these new tests haven't been executed by CI yet — worth a local flutter test run before merge.

No security, privacy, workflow, or dependency surfaces touched. Leaving for human maintainer review before merge.


by AI on behalf of David — if you need David’s attention urgently, please @Git-on-my-level and escalate with need human response.

@Git-on-my-level Git-on-my-level added the flutter flutter work label Oct 12, 2026
@Dragonire9

Copy link
Copy Markdown
Contributor Author

@Git-on-my-level Thank you for the thorough review and helpful design notes!

Addressed both items up to commit 8542554:

  1. app/lib/services/quick_actions_service.dart: Made _handleShortcut return Future<void> directly and unified handleShortcutForTesting(shortcutType) => _handleShortcut(shortcutType); so tests exercise the exact production dispatch switch without any duplication.
  2. app/lib/pages/home/widgets/battery_info_widget.dart: Removed the redundant outer try/catch in _startRecording since _startPhoneRecording already catches both finishCapture() and streamRecording() errors internally.

Ready for merge whenever convenient!

@Git-on-my-level

Copy link
Copy Markdown
Member

Follow-up review on 8542554 — both items from my earlier review are verified resolved:

  • app/lib/services/quick_actions_service.dart: handleShortcutForTesting is now a thin delegate to _handleShortcut, so the tests exercise the exact production dispatch switch — the duplication/drift concern is gone.
  • app/lib/pages/home/widgets/battery_info_widget.dart: the redundant outer try/catch in _startRecording is removed; it is now a plain guard sequence delegating to _startPhoneRecording, which already catches both finishCapture() and streamRecording() failures with mounted-guarded feedback.

The widget tests in app/test/widgets/capture_home_ui_test.dart (stop invokes finishCapture; a failing stop shows somethingWentWrong) and the hermetic service tests in app/test/services/quick_actions_service_test.dart still cover the #19245 regression well.

One caveat unchanged from my earlier review: no CI test suite has run on this head, so please run the app tests (flutter test) before merging.

Thanks for the quick turnaround — this looks good from my side pending CI and maintainer merge.


by AI on behalf of David — if a human maintainer response is needed, please @Git-on-my-level.

@Git-on-my-level Git-on-my-level added the positive-signal Automation verified a genuine fix/quality contribution label Oct 13, 2026

@kodjima33 kodjima33 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Mobile bug fix for #19245 (unhandled async capture failures in quick actions / home record button); good scoped diff with tests, but the required 'PR Metadata Preflight' check is currently failing, so holding at approve-only per the hard floor until it's green.

@Git-on-my-level

Copy link
Copy Markdown
Member

Thanks @Dragonire9 — the code change itself looks good, and the regression tests are a nice touch. Notes per file:

  • app/lib/services/quick_actions_service.dart: _toggleMute now awaits pauseCapture()/resumeCapture() inside a try/catch with a context.mounted-guarded OmiFeedback.error, _handleShortcut is fully async with unawaited at the quick_actions.initialize callback, and the new @visibleForTesting hooks don't leak into production behavior. This closes the unhandled-async-exception path from Quick Actions Mute/Unmute and the Home record button drop capture failures silently #19245 cleanly.
  • app/lib/pages/home/widgets/battery_info_widget.dart: both the finishCapture() (stop) and streamRecording() (start) awaits are wrapped in try/catch with an early return on failure, and all gesture/sheet callbacks now use unawaited correctly.
  • app/test/services/quick_actions_service_test.dart: hermetic widget tests exercising only the mute/unmute path — good isolation, no plugin surface touched.
  • app/test/widgets/capture_home_ui_test.dart: both the happy-path stop (finishCapture invoked once) and the failure-toast case are covered.

One thing blocking the PR Metadata Preflight check — the PR body needs two small additions (the diff itself is fine):

  1. A Failure-Class: declaration line (accepted forms include Failure-Class: new or Failure-Class: FC-<lower-kebab-slug>) — required for fix: commit subjects.
  2. A UI-evidence line — since this is error handling with no layout/design change, an exact UI-Evidence: none line (optionally UI-Evidence: none -- error handling only, no UI layout change) satisfies the rule.

Minor description nit: the summary says _startRecording wraps _startPhoneRecording in try/catch — the try/catch actually lives inside _startPhoneRecording around finishCapture() and streamRecording(). Behavior is correct either way; just the described placement is off.

This head already has maintainer approval; adding the two body lines should turn the preflight green and clear the path to merge.


by AI on behalf of David — if you need David’s attention urgently, please @Git-on-my-level and escalate with need human response.

@Dragonire9

Copy link
Copy Markdown
Contributor Author

@kodjima33 @Git-on-my-level Updated the PR metadata trailers and PR Metadata Preflight is now 100% green and passing. Ready for merge! Thank you!

@Git-on-my-level

Copy link
Copy Markdown
Member

Confirmed — the PR body now carries Failure-Class: none and UI-Evidence: none, and PR Metadata Preflight is green on this head. That was the last open item from my review.

Everything flagged across the four changed files has been addressed: the @visibleForTesting hooks in quick_actions_service.dart are now thin delegates to the production _handleShortcut switch (no duplicated dispatch to drift), and _startPhoneRecording handles both finishCapture() and streamRecording() failures with mounted-guarded OmiFeedback.error + early return.

One caveat, unchanged from my earlier reviews: CI on this PR doesn't run the app test suite, so a local flutter test over app/test/services/quick_actions_service_test.dart and app/test/widgets/capture_home_ui_test.dart before merging is still worthwhile.

With maintainer approval already on this head and metadata now green, this is ready for merge from my side.


by AI on behalf of David — if you need David’s attention urgently, please @Git-on-my-level and escalate with need human response.

@Dragonire9

Copy link
Copy Markdown
Contributor Author

Withdrawing this pull request and closing it. For the record: I committed and engineered these fixes under the expectation of the repository's paid bug bounty program, not as unpaid open-source charity. All unmerged contributions are permanently withdrawn.

@Dragonire9 Dragonire9 closed this Oct 26, 2026
@github-actions

Copy link
Copy Markdown
Contributor

Hey @Dragonire9 👋

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 product principles and locked invariants

Before your next PR, please skim:

  • PRODUCT.md — product north star
  • Product invariants — locked rules (shared chat, memory tiers, agent control plane, integrations, brand)

If this was declined for direction or taste, maintainers should cite an invariant ID or open a proposed one — ask if that citation is missing.

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

flutter flutter work positive-signal Automation verified a genuine fix/quality contribution

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Quick Actions Mute/Unmute and the Home record button drop capture failures silently

3 participants