Cogneris
Environmental Compliance & Inspection

Intent · Every environmental obligation current and evidenced — zero reportable exceedances at Woodbine (UTS).

Operating tolerance: issues closed in ≤ 5 days · no repeat findings · every permit condition met.

← Documentsdocs/audits/2026-07-30-mobile-ptt-crash-audit.md2,257 words

Mobile Push-to-Talk Crash Audit

Date: 2026-07-30
Application: apps/esg-field
Revision inspected: b5aa49ba22a303e61af440a2def456ef6dfcafe0
Scope: Diagnostic review only; no application code was changed
Reported symptom: The mobile application continually exits/crashes when push-to-talk (PTT) is activated and used.

Executive summary

The failure is in the native on-device speech-recognition path, not the command router or ordinary React rendering.

The most likely immediate cause is native memory exhaustion caused by duplicate or oversized Sherpa/Whisper recognizer initialization:

  1. the app starts loading a Whisper recognizer asynchronously at launch;
  2. PTT can call the same engine before that warm-up finishes;
  3. ensureEngine() protects only an already-completed stt instance and does not share an in-flight initialization promise;
  4. warm-up and PTT can therefore call native createSTT() concurrently on the same singleton engine;
  5. both calls load the default Whisper Small recognizer, recorded by the project as approximately 480 MB resident;
  6. the final assignment overwrites the first native handle, leaving the other allocation unreachable from JavaScript;
  7. the process can exceed the handset's memory limit and be terminated by iOS/Android without a JavaScript error.

This fits the observed “app vanishes while using/releasing PTT” behavior and the repository's own July 30 history. Commit 080d602 documents a previous iOS memory termination at PTT release when two native speech models were resident at once. The later switch back to batch mode removed the streaming-plus-Whisper combination but did not make batch recognizer initialization concurrency-safe.

Confidence: High for a native memory termination; medium-high that the warm-up/PTT initialization race is the active trigger. A device crash report or jetsam event is required to prove the exact termination reason.

Severity and impact

FieldAssessment
SeverityP0 / blocker
FrequencyReported as continual
User impactCore field input crashes the application
Data riskThe active utterance is lost; other locally committed event data should survive
ScopeiOS is strongly implicated by repository history; Android remains at risk because the same model-selection and initialization code is shared
Release recommendationDo not represent PTT as operational until it passes the physical-device matrix in this report

System path traced

AppShell mount
  -> startWarmup()
  -> getAudioEngine("ondevice")
  -> singleton SherpaOnDeviceEngine
  -> prepare()
  -> ensureEngine()
  -> native createSTT(Whisper Small)

PTT press
  -> useHoldToTalk.onPanResponderGrant()
  -> beginCapture()
  -> same singleton SherpaOnDeviceEngine
  -> isAvailable()
  -> ensureEngine()
  -> startRecording()

PTT release
  -> endCapture()
  -> stopAndTranscribe()
  -> stop/unload expo-av recorder
  -> native stt.transcribeFile()

The JavaScript PTT handler catches normal promise rejections. A complete process exit therefore points to native termination, abort, or out-of-memory behavior outside those catches.

Findings

P0-1 — Recognizer initialization has a duplicate-load race

Evidence

  • app/index.tsx:264-271 starts warm-up at mount and does not await it.
  • lib/audio/warmup.ts:65-94 calls engine.prepare() asynchronously.
  • ui/voice.tsx:220-238 allows PTT to call engine.isAvailable() regardless of warm-up phase.
  • lib/audio/index.ts:65-72 returns the same singleton Sherpa batch engine to both callers.
  • lib/audio/sherpaOnDevice.ts:72-88 checks only if (this.stt) before calling createSTT().
  • There is no loadingPromise, mutex, or state gate around the native model load.

Failure mechanism

If PTT begins before warm-up assigns this.stt, both calls see this.stt === null and both enter createSTT(). The second completion overwrites this.stt. The native allocation represented by the first result is not destroyed.

Why this matters

The selected model is Whisper Small, estimated by the project at 480 MB resident. Two concurrent instances can approach 960 MB before React Native, Hermes, CoreML/NNAPI, audio buffers, and the application UI are counted.

Required remediation

  1. Make ensureEngine() single-flight: - retain one Promise<SttEngine | null> for initialization; - return the same promise to every caller; - clear it after success/failure; - destroy any superseded native result defensively.
  2. Disable or degrade PTT while warm-up is loading, or explicitly await the shared initialization.
  3. Add a concurrency test using a delayed createSTT() mock: - invoke prepare() and isAvailable() concurrently; - assert createSTT() is called exactly once; - assert both callers receive the same readiness result.
  4. Record model-load start/end, engine ID, model ID, provider, and resident-memory snapshots in a diagnostic build.

P0-2 — Device tiering always assumes a mid-tier device

Evidence

  • lib/audio/sherpaOnDevice.ts:67-69 returns FALLBACK_CAPS rather than real device capabilities.
  • lib/audio/deviceTier.ts:63-66 defines that fallback as exactly the mid-tier threshold.
  • lib/audio/sherpaModel.ts:132-136 maps both mid and low tiers to Whisper Small.
  • lib/audio/sherpaModel.ts:124-127 estimates Whisper Small at 480 MB resident.

Failure mechanism

Every handset is treated as mid-tier. Older or memory-constrained devices receive the same Small model as a 6 GB-class phone. Model inference can require additional temporary memory beyond the recorded resident estimate, particularly through CoreML/NNAPI.

Required remediation

  1. Obtain real physical memory/device information through a supported native/device-info seam.
  2. Change the low tier to Whisper Tiny until measured device data proves Small is safe.
  3. Include current free/available memory, not only total marketing RAM, in the decision.
  4. Keep a safety margin for React Native, report/photo surfaces, and inference scratch memory.
  5. Refuse on-device ASR gracefully when no safe tier exists; never attempt a model that may terminate the process.

P0-3 — Prior memory crash was mitigated, not closed with evidence

Evidence

  • Commit 080d602 states that iOS killed the app on PTT release because the streaming transducer and Whisper Small occupied approximately 600 MB together.
  • Commit 9b09310 switched the default back to batch and explicitly says the next step is a device crash log.
  • No crash report, jetsam report, physical-device PTT test, or native memory budget test is present in the repository.

Assessment

The previous code change reduced one known two-model combination. It did not establish a safe memory budget for the remaining Small recognizer or prevent other duplicate loads. The issue was operationally downgraded without the evidence required to close it.

Required remediation

  • Reopen the earlier crash as unresolved until the crash-log and device-matrix gates below pass.
  • Treat model or mode changes without captured diagnostics as experiments, not fixes.

P1-1 — No automated test covers PTT or the native ASR lifecycle

Evidence

  • All 8 Jest suites and 78 tests pass.
  • TypeScript passes.
  • There are no voice, audio, warmup, sherpa, or PTT-specific test files.
  • The existing app-shell test emits a React act(...) warning from asynchronous warm-up, confirming that warm-up executes during tests but is mocked past rather than validated.

Impact

CI can remain green while PTT crashes every physical device.

Required remediation

Add tests for:

  • warm-up and PTT concurrency;
  • press before warm-up, during warm-up, after success, and after failure;
  • press/release, press/cancel, termination, maximum-hold timeout, and rapid repeated turns;
  • recorder start failure after audio-session acquisition;
  • transcription failure and native rejection;
  • single recognizer instance across repeated turns;
  • model teardown/recovery after memory warnings or backgrounding.

These tests do not replace a physical-device native test.

P1-2 — Batch recognizer remains resident for the process lifetime

Evidence

  • lib/audio/index.ts:65-72 holds the engine singleton globally.
  • lib/audio/sherpaOnDevice.ts:55 holds the native SttEngine.
  • Batch cancel() stops only the recorder; it never destroys the recognizer.
  • No memory-warning, background, or explicit shutdown path destroys stt.

Impact

The application pays the model's native memory footprint for its entire lifetime. Repeated development reloads or leaked duplicate initializations can increase pressure. Heavy photo/report screens then operate with substantially less headroom.

Required remediation

  • Define an explicit recognizer lifecycle and ownership contract.
  • Retain while voice is actively used, but release on memory warning, long background, build-mode change, or initialization replacement.
  • Verify the library's destroy() semantics and call them exactly once.
  • Measure cold-load latency before choosing an aggressive unload policy.

P1-3 — Failed recorder start does not reliably clean up the audio session

Evidence

lib/audio/sherpaOnDevice.ts:116-140 enters the record session and creates/prepares a local Audio.Recording, but the catch path returns false without:

  • stopping/unloading a partially prepared recorder;
  • calling releaseRecordSession();
  • clearing callbacks.

Impact

This is unlikely to cause the process termination, but it can leave the audio route/session in a bad state and make subsequent PTT attempts less reliable.

Required remediation

Use a structured try/finally or rollback block. Assign the recorder early enough to clean it up, and always release the audio session after a failed start.

P1-4 — Chime behavior contradicts its ordering contract

Evidence

  • lib/audio/chime.ts says the open chime must complete before recording starts and the close chime must play after stop.
  • ui/voice.tsx:238-275 starts recording and then calls chimeOpen() without awaiting it.
  • chimeClose is imported in ui/voice.tsx but never called.

Impact

The opening cue may be recorded and transcribed; the user receives no closing cue. This does not explain the crash but undermines PTT reliability and can contaminate the audio.

Required remediation

Move cue sequencing into the recording state machine:

  1. play/await open cue;
  2. enter record session and start capture;
  3. stop/unload capture;
  4. play close cue.

Do not let UI gesture code independently manage audio cue order.

P2-1 — Configuration and comments disagree about the active mode

Evidence

  • lib/audio/index.ts:85-97 still describes streaming as the default.
  • sherpaMode() at lines 99-112 actually defaults to batch.
  • app.config.js:105-114 bundles the streaming model even though streaming is opt-in.
  • The asset manifest says the streaming model is excluded/not reachable by default, while the app config bundles it.

Impact

Developers can test or ship a different memory profile than they think they are testing. Build-time environment overrides are difficult to prove from an installed application.

Required remediation

  • Remove stale comments and contradictory manifest text.
  • Emit the resolved engine, mode, model, provider, and build variables on a diagnostic screen.
  • Generate a build manifest included in the app rather than relying on comments.
  • Bundle only the models required by that build profile.

Diagnostic evidence still required

No booted simulator, attached Android device, local application crash report, or jetsam diagnostic was available during this audit. The development team must collect one failing run before declaring the root cause proven.

iOS capture procedure

  1. Reproduce on the affected physical handset.
  2. Record: - device model; - iOS version; - installed app name and bundle ID; - debug/release build; - time from launch to first PTT; - whether the app exits on press, during hold, or on release.
  3. In Xcode, use Devices and Simulators → Open Console and capture logs filtered by the bundle/process.
  4. Export the device diagnostic: - look for JetsamEvent, EXC_RESOURCE, EXC_BAD_ACCESS, SIGABRT, or an ONNX/CoreML assertion; - retain the full .ips, not a screenshot.
  5. Run Instruments Allocations/VM Tracker and mark: - warm-up start; - recognizer ready; - PTT press; - recording start; - PTT release; - transcription start/end.

Android capture procedure

  1. Run adb logcat through one failing turn.
  2. Capture the process exit reason and tombstone if present.
  3. Record dumpsys meminfo <package> before warm-up, after warm-up, during recording, and during transcription.
  4. Look for OutOfMemoryError, low-memory-killer output, native abort, NNAPI/ONNX failure, or audio-recorder errors.

Isolation matrix

Run each case on the same affected handset and same utterance:

CaseBuild settingsPurpose
ABatch + Whisper Tiny + CPUEstablish safest functional baseline
BBatch + Whisper Tiny + CoreML/NNAPISeparate provider from model size
CBatch + Whisper Small + CPUMeasure model-size effect
DBatch + Whisper Small + CoreML/NNAPIReproduce current default
ECurrent default, wait for warm-up Ready before PTTTest warm-up race
FCurrent default, press immediately during warm-upForce warm-up race
GStreaming + Tiny second passConfirm prior mitigation only after A-F

Interpretation:

  • F fails and E passes: initialization race is confirmed.
  • C/D fail while A/B pass: Small exceeds the safe memory budget.
  • B/D fail while A/C pass: provider-specific native failure.
  • All batch cases pass but G fails: streaming engine remains unsafe.
  • All cases fail at recorder start: investigate audio session/native recording instead of ASR inference.
  1. Collect and attach the failing native diagnostic.
  2. Make recognizer initialization single-flight.
  3. Ship a Tiny/CPU diagnostic build and prove PTT press, hold, release, transcript, second turn, and tenth turn.
  4. Implement real device tiering and a memory budget.
  5. Add lifecycle cleanup and start-failure rollback.
  6. Add automated concurrency/state-machine tests.
  7. Correct chime sequencing and configuration documentation.
  8. Reintroduce Small, CoreML/NNAPI, or streaming only one variable at a time with measured evidence.

Acceptance gate for closure

The crash may be closed only when:

  • the failing .ips/tombstone is attached and explained;
  • warm-up plus PTT creates exactly one native recognizer;
  • the app survives 10 consecutive PTT turns;
  • the app survives PTT immediately after cold launch and after waiting for warm-up;
  • cancel, interruption, 30-second timeout, background, and permission denial are safe;
  • memory remains below a documented threshold with headroom;
  • a transcript is produced in airplane mode;
  • the same tests pass on at least one low-memory and one current iOS device plus one supported Android device;
  • CI includes the new PTT concurrency/state tests;
  • the installed build exposes its resolved engine/mode/model/provider for support.

Audit verification

CheckResult
TypeScriptPassed
Jest8 suites passed; 78 tests passed
Native PTT testMissing
Physical device attachedNo
Crash/jetsam report availableNo
Existing code changes madeNone
Existing unrelated working-tree changesPreserved