Skip to content

fix(ios): preserve Apple speech runtime errors and enter safe recovery - #22549

Merged
kodjima33 merged 2 commits into
mainfrom
fix/20484-apple-speech-recovery
Oct 20, 2026
Merged

kodjima33 merged 2 commits into
mainfrom
fix/20484-apple-speech-recovery

Conversation

@aryanorastar

@aryanorastar aryanorastar commented Oct 19, 2026 •

Copy link
Copy Markdown
Collaborator

Apple speech can pass its readiness probe and then fail on the real recording. The legacy callback currently strips the native error, so missing/unavailable assets can keep retrying as a generic recognition failure instead of entering local recovery.

Recheck the actual legacy recognizer after a runtime failure. If it is unavailable, use the existing local setup/retry state; if it is healthy, preserve the original error for normal retry. Keep native domain/code in diagnostics, preserve recognition timeouts, and retain the existing silence/partial-result behavior. No localized-message matching, automatic paid/cloud fallback, setting reset, or original-audio deletion.

Refs #20484. This addresses an app-side recovery gap; it does not establish that the reported cloud, voice-chat, and photo failures share that cause.

Validation

  • ruby app/ios/test/speech_deadline_test.rb — 3 native behavioral harnesses pass, including runtime readiness loss, analyzer fallback/rollback, original errors and silence. Removing the readiness recheck in an isolated negative control makes the regression fail.
  • bash app/test.sh test/unit/local_stt_recovery_test.dart test/unit/pure_polling_test.dart test/unit/on_device_transcription_upgrade_test.dart test/unit/composite_transcription_socket_test.dart — all 138 protected spine checks and all 35 focused tests pass; pinned native cleanup exercises 600 error/exception paths. The runtime asset-failure case verifies exact retained PCM retry, actionable/gated recovery, native diagnostics, disposable WAV cleanup and original saved file preservation.
  • make preflight — all 31 selected local checks pass. Normal committed-source pre-push gate also passes (metadata, native Swift checks and Dart format). Targeted Dart analysis is clean.
  • Focused native iOS SDK typecheck passes (Xcode 27.1, iOS simulator target, real Flutter framework): exact production SpeechAnalyzer/SpeechRecognitionHandler block plus SpeechDeadline and SafeFoundationSinks; no API stubs.
  • Full iPhone simulator dev build passes: bash scripts/validate_mobile_build_config.sh --flavor dev --profile local_dev then flutter build ios --simulator --debug --flavor dev --no-codesign --no-pub --dart-define=OMI_APP_PROFILE=local_dev -d <available-iPhone-simulator> from app/. Xcode 27.1; Runner.app produced. Existing companion LLDB/SPM adoption warnings are non-fatal. GitHub CI remains queued; physical device validation remains outstanding.

Release and customer verification

  • Requires merge and an iOS app release; no backend deployment for this PR.
  • Physical iPhone/CV1 testing remains: actual asset and permission failures, same-session recovery, restart/background, phone mic versus pendant, each affected transcription mode, and voice chat.
  • Firmware AAD/wake work in fix(firmware): restore VAD pre-roll and skip AAD sleep when connected #14156 is still open and requires hardware/battery qualification and a firmware release. This PR cannot recover audio the device never delivered.
  • Need private app/iOS/firmware versions and a failed recording time, plus the photo source/accessory and transfer behavior. Keep iOS/CV1: capture and voice chat fail after reported 3.0.21 update; Apple speech asset error #20484 open until those symptoms are verified; preserve apps and recordings.
  • Architecture and implementation/release checklist: .github/agent-docs/on-device-speech.md.

Product invariants affected

none

Failure-Class: none

The gap is point-in-time local speech readiness followed by loss of native failure semantics. Existing protocol-status and backend privacy-denial classes describe different boundaries. The shared coordinator and executable native/provider regressions own this fix.

UI-Evidence: none -- No UI source changed; existing local speech recovery states are reused.

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 19, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-20T02:42:13.669100Z eba3e9d New commits
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@cubic-dev-ai

cubic-dev-ai Bot commented Oct 19, 2026

Copy link
Copy Markdown

Auto-fix isn't included in your plan ↗

Upgrade to Team

@Git-on-my-level

Copy link
Copy Markdown
Member

Verdict: the production change is correct and nicely scoped, and the two red checks are not from this diff — they are inherited from the merge base; the branch just needs a main update before merge.

What I verified, file by file:

  • app/ios/Runner/SpeechDeadline.swift — the new recheck in SpeechFallbackCoordinator.transcribe is the heart of the fix and is right: after a legacy failure that is not already LocalSpeechUnavailable, it re-probes the real recognizer; an unavailable probe becomes LocalSpeechUnavailable with the original NSError attached as cause (domain/code surface in wire), and a healthy probe rethrows the original error so ordinary retry semantics are unchanged. No localized-message parsing, as promised.
  • app/ios/Runner/AppDelegate.swift — switching the internal transcribe completion from FlutterResult to a typed Result<String, Error> removes the old lossy NSError(domain: error.code, code: 1) re-wrap that destroyed the native domain/code and made recovery classification impossible. RECOGNITION_ERROR now carries nativeErrorDomain/nativeErrorCode in details; SpeechRecognitionFailure.timedOut preserves RECOGNITION_TIMEOUT; permission and missing-recognizer paths become typed LocalSpeechUnavailable. One minor diagnostic trade-off: the recognizer locale identifier that used to be embedded in the RECOGNITION_ERROR message string is gone (domain/code in details is the better channel, just noting the change).
  • app/lib/services/sockets/on_device_apple_provider.dart — moving CustomSttLogService.error ahead of the LocalSttFailure translation means native diagnostics are logged even when the exception is translated for the recovery UI; the rethrow still keeps failed frames in the polling buffer. Behavior otherwise unchanged.
  • app/test/unit/local_stt_recovery_test.dart — strong regression coverage: exact retained PCM retried after recovery, no repeated recognition while unavailable, recovery gated on readiness, temp recognition WAV cleaned up, saved recording untouched.
  • app/ios/test/speech_fallback_coordinator_test.rb — hermetic harness exercising the recheck, cause preservation (error.cause === native), and the healthy-probe passthrough across engine/status combinations.
  • .github/agent-docs/on-device-speech.md — I checked the new section against the code; it accurately describes the implemented behavior, and the rollout checklist honestly leaves the physical-device items unchecked.
  • app/changelog/unreleased/20261019-apple-speech-runtime-recovery.json — correct fragment.

CI: "Dart Analyze & Tests" fails on an unused_import in app/test/widgets/home_ask_anything_button_test.dart — a file this PR does not touch. That import landed on main in #22505 after your branch point and was already fixed on main (8b65fde). "Mobile Release Eligibility" is red only because it gates on the same Dart job. Merging current main into the branch (or rebasing) should turn both green without any code change.

Performance: each legacy-path failure now triggers one additional 0.6s silent-clip readiness probe; failure-path only, bounded. Blast radius: the iOS on-device SFSpeech path only; no cloud/paid fallback, no settings or recording deletion.

USER IMPACT: if Apple's on-device speech engine becomes unavailable mid-recording (assets, permissions, or Dictation changing), the app now pauses recognition, keeps your recorded audio, and shows the existing local-speech recovery state instead of silently retrying a broken engine; once speech works again it resumes automatically from the retained audio.

Action items: (1) merge/rebase current main so CI reruns green; (2) complete the doc checklist's physical-device verification (missing assets mid-capture, CV1 pendant capture) per the rollout plan before closing the loop on #20484.

This review was produced by an automated maintainer assistant acting on behalf of the Omi maintainers.


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

@aryanorastar

aryanorastar commented Oct 20, 2026 •

Copy link
Copy Markdown
Collaborator Author

Pushed eba3e9d: merged current main (8edd56d). No code changes.

  • Why: Dart Analyze & Tests and Mobile Release Eligibility failed on the analyzer ratchet (unused_import: 1 found, baseline 0). With current main merged, app/scripts/analyze_ratchet.sh passes locally. I could not pin which file produced that one import: the previous head analyzes clean here, so the difference is probably in CI's generated code. Its source is unconfirmed, not shown to come from main.
  • Scope: the merge is clean, with no conflicts; the diff against main is exactly this PR's files.
  • Checks: this PR's tests, 11 passed.

@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.

Scoped iOS bug fix (258 lines) preserving Apple speech runtime errors for safe recovery, with native + Dart regression tests; 5/5 confidence, CI green.

@kodjima33
kodjima33 merged commit 8eac468 into main Oct 20, 2026
44 checks passed
@kodjima33
kodjima33 deleted the fix/20484-apple-speech-recovery branch October 20, 2026 14:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants