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:
- the app starts loading a Whisper recognizer asynchronously at launch;
- PTT can call the same engine before that warm-up finishes;
ensureEngine()protects only an already-completedsttinstance and does not share an in-flight initialization promise;- warm-up and PTT can therefore call native
createSTT()concurrently on the same singleton engine; - both calls load the default Whisper Small recognizer, recorded by the project as approximately 480 MB resident;
- the final assignment overwrites the first native handle, leaving the other allocation unreachable from JavaScript;
- 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
| Field | Assessment |
|---|---|
| Severity | P0 / blocker |
| Frequency | Reported as continual |
| User impact | Core field input crashes the application |
| Data risk | The active utterance is lost; other locally committed event data should survive |
| Scope | iOS is strongly implicated by repository history; Android remains at risk because the same model-selection and initialization code is shared |
| Release recommendation | Do 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-271starts warm-up at mount and does not await it.lib/audio/warmup.ts:65-94callsengine.prepare()asynchronously.ui/voice.tsx:220-238allows PTT to callengine.isAvailable()regardless of warm-up phase.lib/audio/index.ts:65-72returns the same singleton Sherpa batch engine to both callers.lib/audio/sherpaOnDevice.ts:72-88checks onlyif (this.stt)before callingcreateSTT().- 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
- Make
ensureEngine()single-flight: - retain onePromise<SttEngine | null>for initialization; - return the same promise to every caller; - clear it after success/failure; - destroy any superseded native result defensively. - Disable or degrade PTT while warm-up is
loading, or explicitly await the shared initialization. - Add a concurrency test using a delayed
createSTT()mock: - invokeprepare()andisAvailable()concurrently; - assertcreateSTT()is called exactly once; - assert both callers receive the same readiness result. - 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-69returnsFALLBACK_CAPSrather than real device capabilities.lib/audio/deviceTier.ts:63-66defines that fallback as exactly the mid-tier threshold.lib/audio/sherpaModel.ts:132-136maps both mid and low tiers to Whisper Small.lib/audio/sherpaModel.ts:124-127estimates 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
- Obtain real physical memory/device information through a supported native/device-info seam.
- Change the low tier to Whisper Tiny until measured device data proves Small is safe.
- Include current free/available memory, not only total marketing RAM, in the decision.
- Keep a safety margin for React Native, report/photo surfaces, and inference scratch memory.
- 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
080d602states that iOS killed the app on PTT release because the streaming transducer and Whisper Small occupied approximately 600 MB together. - Commit
9b09310switched 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-72holds the engine singleton globally.lib/audio/sherpaOnDevice.ts:55holds the nativeSttEngine.- 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.tssays the open chime must complete before recording starts and the close chime must play after stop.ui/voice.tsx:238-275starts recording and then callschimeOpen()without awaiting it.chimeCloseis imported inui/voice.tsxbut 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:
- play/await open cue;
- enter record session and start capture;
- stop/unload capture;
- 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-97still describes streaming as the default.sherpaMode()at lines 99-112 actually defaults to batch.app.config.js:105-114bundles 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
- Reproduce on the affected physical handset.
- 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.
- In Xcode, use Devices and Simulators → Open Console and capture logs filtered by the bundle/process.
- 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. - Run Instruments Allocations/VM Tracker and mark: - warm-up start; - recognizer ready; - PTT press; - recording start; - PTT release; - transcription start/end.
Android capture procedure
- Run
adb logcatthrough one failing turn. - Capture the process exit reason and tombstone if present.
- Record
dumpsys meminfo <package>before warm-up, after warm-up, during recording, and during transcription. - 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:
| Case | Build settings | Purpose |
|---|---|---|
| A | Batch + Whisper Tiny + CPU | Establish safest functional baseline |
| B | Batch + Whisper Tiny + CoreML/NNAPI | Separate provider from model size |
| C | Batch + Whisper Small + CPU | Measure model-size effect |
| D | Batch + Whisper Small + CoreML/NNAPI | Reproduce current default |
| E | Current default, wait for warm-up Ready before PTT | Test warm-up race |
| F | Current default, press immediately during warm-up | Force warm-up race |
| G | Streaming + Tiny second pass | Confirm 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.
Recommended remediation order
- Collect and attach the failing native diagnostic.
- Make recognizer initialization single-flight.
- Ship a Tiny/CPU diagnostic build and prove PTT press, hold, release, transcript, second turn, and tenth turn.
- Implement real device tiering and a memory budget.
- Add lifecycle cleanup and start-failure rollback.
- Add automated concurrency/state-machine tests.
- Correct chime sequencing and configuration documentation.
- 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
| Check | Result |
|---|---|
| TypeScript | Passed |
| Jest | 8 suites passed; 78 tests passed |
| Native PTT test | Missing |
| Physical device attached | No |
| Crash/jetsam report available | No |
| Existing code changes made | None |
| Existing unrelated working-tree changes | Preserved |