The AI Coding Agent Passed the Build. The App Still Crashed on Launch
Описание и применение
Код, сгенерированный AI, компилировался и проходил тесты, но при запуске приложения вызывал сбой из‑за нарушения изоляции акторов в колбэке Core Audio. Перемещение создания колбэка в не изолированный контекст и добавление @Sendable исправили проблему, а 60‑секундный тест в симуляторе теперь служит защитой от подобных ошибок.
Задача
An AI‑generated Swift audio feature compiled and passed tests but crashed at runtime due to actor isolation violations in a Core Audio callback.
Результат
The refactor resolved the runtime crash by ensuring the audio callback ran on the correct thread and met Swift 6's actor isolation rules. A simple 60‑second smoke test now guards against similar runtime boundary failures.
Рабочий процесс
- 1. Use Claude to generate the adaptive audio feature code.
- 2. Build the app and run unit tests.
- 3. Observe that the app crashes on launch with SIGTRAP when the audio engine calls the render block.
- 4. Identify that the closure was created inside a @MainActor context, causing a runtime actor isolation trap.
- 5. Refactor by moving the callback creation to a nonisolated static function and marking the closure @Sendable.
- 6. Add a runtime smoke test: launch the app in the simulator, exercise the callback path, keep it running for 60 seconds, then install or ship the build.
Доказательства
The code compiled. The tests passed. The app installed. Then it crashed as soon as the audio engine called its render block.
The problem was where the closure had been created. The audio class was @MainActor, so Swift 6 treated the render closure as main-actor isolated too.
That closure does not run on the main actor. Core Audio calls it from a real-time audio thread. The compiler accepted the handoff, but the runtime actor check trapped the first time Core Audio invoked it.
The fix was small: form the callback outside the actor-isolated context and make the threading contract explicit.
Now any AI-assisted change that hands a closure to a system framework gets a tiny runtime gate: launch the app in the simulator, exercise the callback path, leave it running for 60 seconds, only then install or ship the build.
- Дата записи: 2026-10-24T13:26:31.184Z