---
title: Keep lifecycle controls outside the Core Motion callback queue
date: 2026-10-01
category: runtime
tags: [ios, core-motion, concurrency, calibration, persistence]
---

# Keep lifecycle controls outside the Core Motion callback queue

Core Motion's installed `CMMotionManager.h` states that stopping updates cancels every operation in the supplied callback OperationQueue. Putting stop completion, restart or snapshot operations into that same queue can cancel the operations needed to finish saving or resume capture. Use the callback queue only for copying immutable sensor values and receipt timestamps. A separate serial dispatch queue owns capture state, lifecycle controls, generation checks and accepted-record delivery. Persistence has its own serial writer queue.

Define the cutoff as execution of the stop control block: earlier accepted records reach the writer before its drain; later callbacks are suppressed. A callback receipt before the cutoff can still arrive at the control queue afterward, so distinguish accepted-record reconciliation from hardware delivery-loss claims. Increment a capture generation at stop/start so a stale copied callback cannot enter a later recording or alter its clock/convention. Never make the sensor callback synchronously wait for the control queue while stop may wait for callback cancellation.

Evidence: `docs/validation/u2-fix-evidence.md` records RED/GREEN lifecycle regressions for cancellation and stale generations. The platform queue contract was confirmed in the installed SDK; no hardware reproduction is claimed.

Calibration introduces another lifetime invariant: an arbitrary Core Motion reference may change when capture restarts. Preserve the same capture from neutral/axis calibration through Ready and recording. Install the recording writer dynamically instead of stopping and restarting sensors at Start. A real stop, mode change or interruption invalidates calibration authorization for the next recording while preserving its saved evidence. The simulator fixture intentionally changes its reference on each generation so this error is observable in workflow tests. Physical rigid mounting/sign checks remain necessary.

Reuse these boundaries in the Watch adapter; do not assume callback cancellation, reference continuity or background runtime are identical without checking that SDK/runtime.
