Skip to content

fix(app): gate on-device transcription hallucinations - #9312

Merged
kodjima33 merged 4 commits into
BasedHardware:mainfrom
moni11811:agent/omi4meta-on-device-transcription
Aug 22, 2026
Merged

kodjima33 merged 4 commits into
BasedHardware:mainfrom
moni11811:agent/omi4meta-on-device-transcription

Conversation

@moni11811

@moni11811 moni11811 commented Jul 9, 2026 •

Copy link
Copy Markdown
Contributor

Theory
On-device transcription accepted low-quality local Whisper/Speech output as final text. Short hallucinations, repeated filler, and weak local transcripts could leak into conversations instead of being rejected or falling back.

Scope

  • Adds on-device transcript quality gate.
  • Applies gate in socket transcription flow.
  • Tightens on-device provider handling.
  • Sets iOS speech request dictation hint and punctuation.

Cut from #9084

  • Meta glasses runtime/UI.
  • Multi-device saved-device work.
  • Native BLE/device integration churn.
  • Docs/plugin examples/auth changes.

Tests

  • Red first: flutter test test/unit/on_device_transcription_upgrade_test.dart failed on missing OnDeviceTranscriptQualityGate.
  • Green: flutter test test/unit/on_device_transcription_upgrade_test.dart passed 5 tests.

Notes

Failure-Class: none

Review in cubic

@Git-on-my-level

Copy link
Copy Markdown
Member

Thanks for extracting this into a focused draft — the scope is much easier to reason about than the larger branch, and the local Whisper quality gate is a useful direction.

A couple of things I think should be addressed before this is ready for maintainer review:

  • The new gate is only wired into OnDeviceWhisperProvider. On iOS, SttProvider.onDeviceWhisper returns OnDeviceAppleProvider, so the native Apple/Speech path still accepts short/filler results as final text. The PR description says it gates on-device Whisper/Speech output, but the iOS change currently only sets dictation/punctuation hints. Please either apply the same quality gate to OnDeviceAppleProvider too, or narrow the PR description/tests to make it clear this only gates the non-iOS local Whisper path.
  • The regression tests are mostly static string checks for the iOS path. It would be stronger to add behavior-level coverage for the provider path that should be gated, especially the iOS/native path if that remains in scope.

Not approving because this is still a draft and there is no passing check summary available. Once the iOS path/scope mismatch is resolved and checks are available, this should be a good candidate for another pass.

@Git-on-my-level Git-on-my-level added needs-tests PR introduces logic that should be covered by tests needs-maintainer-review Needs a human maintainer to sign off before merge labels Jul 9, 2026
@moni11811

Copy link
Copy Markdown
Contributor Author

Addressed draft review in 160d818.

Changes:

  • Wired OnDeviceTranscriptQualityGate into OnDeviceAppleProvider, not only local Whisper.
  • Apple/native iOS path now drops low-energy filler transcripts before returning final STT text.
  • Added behavior-level mocked iOS speech-channel test for Apple provider.
  • Cleaned analyzer warnings in the on-device provider files.

Local checks:

  • flutter test test/unit/on_device_transcription_upgrade_test.dart
  • dart analyze lib/services/sockets/on_device_apple_provider.dart lib/services/sockets/on_device_whisper_provider.dart lib/services/sockets/on_device_transcript_quality_gate.dart test/unit/on_device_transcription_upgrade_test.dart

@Git-on-my-level

Copy link
Copy Markdown
Member

Good progress since the last pass — the quality gate is now wired into OnDeviceAppleProvider (not just local Whisper), and the new mocked iOS speech-channel test gives much better confidence than the earlier static-string checks.

A few observations for the next iteration or for the human maintainer:

  1. Dead parameter: OnDeviceTranscriptQualityGate.filter() accepts duration but never uses it. Either add a TODO for future duration-based heuristics or remove it.
  2. Magic thresholds: The low-energy threshold (avg |sample| < 180) and the six-token filler list are uncalibrated. They're reasonable starting points, but real-device audio validation would strengthen confidence that legitimate short utterances aren't dropped.
  3. State lifecycle: _lastAcceptedFiller is per-provider-instance. If providers are short-lived the duplicate-filler suppression won't persist across polling cycles; if long-lived it may suppress fillers across unrelated conversation contexts. Worth a comment documenting the expected lifecycle.
  4. Polling window change: The iOS buffer change (5s → 3s, minBufferSizeBytes doubled) affects the transcription latency/quality tradeoff. Real-device testing would help confirm shorter windows don't regress accuracy.

Not approving: still a draft with no CI checks available. Once CI confirms the new test suite passes, the needs-tests label can be lifted. Keeping needs-maintainer-review — the thresholds and polling-window changes warrant human judgment before merge.

Thanks for the focused extraction from the larger branch — the scope is clean and the quality gate direction is valuable for Omi's transcription reliability.

@moni11811

Copy link
Copy Markdown
Contributor Author

Addressed review follow-up in 44dc9aba4:

  • Removed the unused duration parameter from the quality gate and both provider call sites.
  • Documented that duplicate-filler state is provider-session scoped and reset by real speech.
  • Reverted the unvalidated iOS polling delta to the existing 5-second buffer and one-second minimum.
  • Kept the threshold as a named constant; calibration still needs real-device evidence.
  • Re-ran all 6 focused tests, including the mocked Apple speech-channel path; all pass.

PR stays draft pending CI and human threshold review.

@Git-on-my-level

Copy link
Copy Markdown
Member

Thanks for the follow-up — this addresses the concrete issues from the last pass.

What looks improved now:

  • OnDeviceTranscriptQualityGate is wired into both the Apple native provider and local Whisper path.
  • The unused duration parameter was removed.
  • The iOS polling-window change was reverted, so this stays focused on transcript filtering rather than changing the latency/quality tradeoff at the same time.
  • The mocked Apple speech-channel test gives behavior-level coverage for dropping low-energy filler output.

I’m not approving because this is still a draft and there’s no CI/check summary available here. I’d keep needs-maintainer-review until a human maintainer is comfortable with the real-device threshold/filler-token tradeoff, since false positives on short legitimate utterances are a product-quality call. Once CI is visible/passing, this looks like a clean focused candidate for maintainer review.

@undivisible undivisible added human Human-authored pull request app flutter flutter work mobile privacy-review Touches user-data persistence, permissions, or privacy-sensitive surfaces labels Aug 10, 2026

@Git-on-my-level Git-on-my-level left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thanks for this — the quality gate is a sensible, well-scoped approach to a real on-device hallucination problem, and the tests are solid (good coverage of the filler/dedup/low-energy branches). A few per-file notes from static review:

on_device_transcript_quality_gate.dart (new)

  • _lowEnergyAverageAbsThreshold = 180 is ~0.55% of the int16 max (32767). For 16-bit PCM, silent/near-silent room noise can sit in the low hundreds, but a softly-spoken "no" from a mic at arm's length might also average below 180 and get silently dropped. This is the highest-stakes constant in the PR — worth validating against a few real captured clips before merge, or exposing it for tuning.
  • _lastAcceptedFiller persists for the provider's lifetime. After a filler is accepted once, the next identical filler is dropped regardless of how much time elapsed. For a long-running session with a long gap, a legitimate repeated "no" could be suppressed. A bounded TTL (or resetting on a N-second gap) would be more robust. The comment acknowledges it only spans adjacent results; the code doesn't actually enforce adjacency-by-time.
  • _wavDataOffset falls back to offset 0 when no data chunk is found, which correctly handles raw PCM; good.

on_device_apple_provider.dart

  • Gate is applied to the returned result before building SttSegment, and both segments and rawText use filteredText — consistent. The dropped transcript is logged at warning, which is the right level. duration is now computed from audioData.lengthInBytes / 32000.0 (16kHz/16-bit/mono); the old explanatory comment was removed but the math is unchanged.

on_device_whisper_provider.dart

  • The res.text == null || res.text!.isEmpty → res.text.isEmpty change is correct. WhisperTranscribeResponse.text is declared required String text (non-nullable) in the upstream whisper_flutter_new package, so the old null-check was dead code against the actual type. Good cleanup.
  • The braces added to the if/else if chain are a harmless style pass (no behavior change).

AppDelegate.swift

  • request.addsPunctuation = true is iOS 16+ (SFSpeechRecognitionRequest). If Omi still targets iOS 15, this needs an if #available(iOS 16, *) guard; on iOS 15 it would crash at runtime. Worth confirming the deployment target.

on_device_transcription_upgrade_test.dart

  • Good unit coverage of the gate in isolation. The two source-parsing tests (polling window + dictation hint) are string-assertion tests against source files — they're brittle to refactors but do lock in the intended config. The mocked Apple provider test correctly verifies null return on silent audio.

CI

  • PR Metadata Preflight is failing on failure-class-protocol: the fix: commit subject requires a Failure-Class: FC-<slug> | new | none trailer. Adding Failure-Class: new (or an existing FC slug) to the commit will clear it. This is the merge blocker, not the code.

Overall this is a clean, focused transcription-quality slice. Leaving for human maintainer review on the energy-threshold calibration and the iOS 16 availability question before this comes out of draft.


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 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Follow-up on the same head (44dc9ab) — I was able to resolve the deployment-target question I'd left open in my earlier review, and it turns into one blocking issue.

Blocking: AppDelegate.swift — addsPunctuation needs an availability guard
request.addsPunctuation = true is an iOS 16.0+ API (introduced in iOS 16 / macOS 13 per Apple's documentation). The Runner target builds with IPHONEOS_DEPLOYMENT_TARGET = 15.0 in every configuration of Runner.xcodeproj (Debug/Release/Profile x standard/-prod/-dev), and Podfile pins platform :ios, '15.0' (the post_install hook only mutates pod targets, not the app target). With no #available check around it (none on SpeechRecognitionHandler or transcribe), this is a Swift compile error for the iOS app target, not just a runtime risk:

if #available(iOS 16, *) {
    request.addsPunctuation = true
}

request.taskHint = .dictation is fine unguarded (available since iOS 10).

Other notes (all non-blocking)

  • on_device_transcript_quality_gate.dart — unchanged since the last pass. The named _lowEnergyAverageAbsThreshold = 180 constant is reasonable as a default, but real-device calibration evidence is still the main thing keeping this in human review: a softly-spoken short utterance could average below 180 and be dropped.
  • on_device_apple_provider.dart — gate wiring is clean: filteredText flows into both segments and rawText, drops are logged at warning, and returning null propagates as no-transcript for the poll.
  • on_device_whisper_provider.dart — verified the res.text == null || res.text!.isEmpty → res.text.isEmpty change against the pinned whisper_flutter_new fork (af6b457): WhisperTranscribeResponse.text is required String text, so the old null-check was dead code. Correct cleanup, and the gate application mirrors the Apple path symmetrically.
  • on_device_transcription_upgrade_test.dart — good coverage; the mocked com.omi.ios/speech channel test asserting null on silent audio is a real behavior-level check. The two source-string assertion tests (polling window, dictation hint) are brittle to refactors but acceptable as config locks.

Also noting progress since last pass: PR Metadata Preflight now passes (the Failure-Class trailer is present), and the focused unit tests cover the new gate logic, so I'm dropping needs-tests. Keeping needs-maintainer-review: once the availability guard lands, the remaining merge question is the real-device threshold/filler-token tradeoff, which is a product-quality call (false positives on short legitimate utterances like a quiet "no"), not something I can validate statically.


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 removed the needs-tests PR introduces logic that should be covered by tests label Aug 19, 2026
@moni11811
moni11811 marked this pull request as ready for review August 21, 2026 07:12
@Git-on-my-level
Git-on-my-level dismissed their stale review August 21, 2026 10:21

Resolved in cb1830c: request.addsPunctuation = true in AppDelegate.swift is now guarded by if #available(iOS 16, *), which was the blocking concern of this review. Checks are green at the new head; remaining open item (real-device threshold calibration) is tracked for human maintainer review.

@Git-on-my-level

Copy link
Copy Markdown
Member

Verified on cb1830c: request.addsPunctuation = true is now wrapped in if #available(iOS 16, *) in AppDelegate.swift, exactly matching the blocking item from the previous review — with the Runner target still on deployment target 15.0, that resolves the compile-level availability problem, and taskHint correctly stays unguarded (available since iOS 10). The focused suite, including the updated dictation-lock test, is green in CI.

Per-file pass on this head for the record:

  • app/ios/Runner/AppDelegate.swift — availability guard verified; no other behavior change.
  • app/lib/services/sockets/on_device_transcript_quality_gate.dart — unchanged since the last pass; clean → normalize → filler/low-energy gating with session-scoped duplicate suppression still looks sound. (Minor nit, non-blocking: the WAV data chunk scan starts at byte 12 and could in principle match bytes inside the payload; standard 44-byte headers work fine.)
  • app/lib/services/sockets/on_device_apple_provider.dart — unchanged; gate output flows into both segments and rawText, and drops are logged at warning before returning null.
  • app/lib/services/sockets/on_device_whisper_provider.dart — only brace-style cleanup around the model-selection chain; gate application mirrors the Apple path.
  • app/test/unit/on_device_transcription_upgrade_test.dart — updated to lock the guarded punctuation call, and the mocked com.omi.ios/speech test still covers the low-energy drop end-to-end.

With the blocker fixed and checks green, this is ready for maintainer sign-off. The one thing automation can't settle is real-device calibration of the gate: whether avg |sample| < 180 plus the six English filler tokens is safe against quiet-but-real short utterances (non-English filler is unaffected, since only exact English tokens are gated). That product-quality tradeoff is the crux being left with the human maintainer under the existing labels.


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 positive-signal Automation verified a genuine fix/quality contribution label Aug 21, 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.

fix(app): on-device transcription hallucination gate — bug fix, confidence 5/5 (stated root cause, fix(app) title on concrete defect, scoped diff 257 lines/5 files, CI green, red-then-green test added). Not already fixed on main. Merging.

@kodjima33
kodjima33 merged commit e8d5f6e into BasedHardware:main Aug 22, 2026
30 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

app flutter flutter work human Human-authored pull request mobile needs-maintainer-review Needs a human maintainer to sign off before merge positive-signal Automation verified a genuine fix/quality contribution privacy-review Touches user-data persistence, permissions, or privacy-sensitive surfaces

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants