Back to the playbook
Chapter 01 · 7 min read

The cold-start silence

When PushKit wakes your app but the call connects mute.

WebRTCAVAudioSessionPushKitCallKit

The bug, in one sentence.

VoIP push arrives, CallKit presents the call UI, the user picks up — and the first two seconds of audio are gone. Then it recovers. Sometimes.

I spent a week chasing this at YEO Messaging. The symptom came and went based on whether the app had been in memory or launched cold. Users on long sessions never saw it. Users receiving the first call of the day always did.

Why it happens.

When your app is terminated and a VoIP push wakes it, iOS gives you a strict budget — about 20 seconds — to report the incoming call to CallKit via reportNewIncomingCall. Miss that, and the system kills you. So the reflex is to race to report: the first thing your PKPushRegistryDelegate does is call CallKit.

That's correct for CallKit. It's wrong for audio.

Audio on iOS is governed by AVAudioSession. Before anyRTCPeerConnection can push PCM frames into the output mixer, you must have set a category that permits playback and recording (usually .playAndRecord with mode .voiceChat), and you must have set the session active. Both of those are synchronous — but “active” triggers a hardware route negotiation that can take 50-150ms, and during that window, any media the peer sends you is dropped on the floor.

In the cold-start path, here's the race in slow motion:

  1. t=0ms: VoIP push wakes the process.
  2. t=5ms: You report to CallKit. ✅
  3. t=10ms: Signaling connects. SDP offer is sent to the server.
  4. t=80ms: Peer receives the offer, answers immediately. Media starts flowing.
  5. t=120ms: You remember to activate the audio session.
  6. t=250ms: Audio hardware actually ready. Media from the last 170ms is already gone.

The fix.

Activate AVAudioSession before the first SDP offer leaves the device. Not before CallKit — CallKit must still be first for the OS-kill budget. But between CallKit and the peer: activate the session, synchronously, with the voice chat category.

ColdStartAudio.swift
1// Order matters.
2// 1. Report to CallKit (OS-kill budget)
3// 2. Activate audio (so media has somewhere to go)
4// 3. Send the offer (so the peer can start sending)
5 
6provider.reportNewIncomingCall(with: uuid, update: update) { reportError in
7 guard reportError == nil else { return }
8 
9 let session = AVAudioSession.sharedInstance()
10 try? session.setCategory(.playAndRecord,
11 mode: .voiceChat,
12 options: [.allowBluetooth, .allowBluetoothA2DP])
13 try? session.setActive(true, options: [.notifyOthersOnDeactivation])
14 
15 // Only now — once media I/O is live — send the offer.
16 Task {
17 let sdp = try await peer.offer()
18 try await peer.setLocalDescription(sdp)
19 signaling.send(.offer(sdp))
20 }
21}

Three things matter in that snippet:

How to make it stay fixed.

The hard part of this bug isn't writing the fix — it's preventing it from regressing. The ordering constraint lives in your head, not in the type system. Here's the regression test harness I'd set up:

Related chapters.

If you're working on the same stack, the next two bugs you'll hit are the CallKit + FaceID race (locked-device audio gap) and the SDP offer/answer race under reconnect. Both are in this playbook.

Everything in this chapter is drawn from production work at YEO Messaging (UK). The code is simplified from the real patch — the real patch has three more branches for AirPods vs CarPlay vs built-in receiver, which I'll cover in the Bluetooth chapter.