HKWorkoutSession distance tracking using HKAnchoredObjectQuery will sometimes stop working

I'm looking for some help with a radar I filed: rdar://39621240


I have a fitness tracking app for the Apple Watch that's used by runners. It uses an HKAnchoredObjectQuery to report distance as they run. I've have reports from at least 6 users distance tracking will stop working partway through the workout. The symptoms are always the same. Typically distance samples are reported every few seconds. What happens is that is that distance samples will stop being reported for a long period of time and then a single distance sample will arrive with all the accumulated distance. Then typically no further distance samples are reported.


Here's an example. You can see distance samples being reported every few seconds, but then a period of 10 minutes elapses before the next distance sample is reported. Then no further samples are reported for the rest of the workout.

{

"endDate": "2018-04-21T09:53:15+01:00",

"quantity": 9.981867978582159,

"startDate": "2018-04-21T09:53:12+01:00"

},

{

"endDate": "2018-04-21T09:53:17+01:00",

"quantity": 8.883641727734357,

"startDate": "2018-04-21T09:53:15+01:00"

},

{

"endDate": "2018-04-21T09:53:20+01:00",

"quantity": 6.127249873476103,

"startDate": "2018-04-21T09:53:17+01:00"

},

{

"endDate": "2018-04-21T10:03:18+01:00",

"quantity": 1945.8662778341677, <--- Large distance sample after 10 minutes

"startDate": "2018-04-21T09:53:20+01:00"

}


In the above JSON dump of distance samples, the last distance sample was sent 10 minutes after the previous one.


This users are running with Series 2 or Series 3 watchs (without iPhone). The app also tracks the workout route using core location and the workout route map also stops at the same point, indicating the location updates also stopped being reported.


Steps to Reproduce:

The app tracks distance the same way was the Apple SpeedySloth example. However, the problem only occurs occasionally.


Expected Results:

Distance samples should be reported every few seconds


Actual Results:

Distance sample are sometimes not reported for minutes, followed by no further samples.


Version/Build:

watchOS 4