I can't tell you whether this is an iOS 27 regression, and I want that out of the way before the rest of it — I only ever ran this query shape on iOS 27, so I have no earlier data point to compare against. Your symptom is also milder than mine: yours is intermittent and range-dependent, mine was every bucket, every day, deterministically.
But there is one variable in your sample code that nobody in this thread has ruled out yet, and on my device it is the difference between a correct answer and nothing at all: .strictStartDate.
Measured on iOS 27.0 (24A437), one device, one day, one quantity type (basalEnergyBurned), four combinations in a single run:
plain sum, .strictStartDate -> 2138
plain sum, no options -> 2206
hourly collection, .strictStartDate -> total=0 intervals=25
hourly collection, no options -> total=2206Same day, same type, same store. The option costs the plain query 68 calories and zeroes the collection query completely.
On the plain query that is exactly the documented behavior, and you can account for it to the calorie. The docs read "The sample’s start time must fall within the target time period.", there is one target the size of the whole range, and my probe day has exactly one sample starting before it — 04:59:15, 67 calories. 2206 - 67 = 2139, near enough the 2138 measured.
The collection query is where I stop being able to explain it, and I'd rather say so than hand you a theory that doesn't hold. If "target" means the intervals, the same rule should cost one sample per boundary — but every sample's start falls inside some hour, so it should land in that hour's bucket. Here are the first four samples of the probe day, against a day starting at 05:00:00:
04:59:15 -> 05:53:33 67 cal
05:53:33 -> 05:53:54 0
05:53:54 -> 06:13:01 23
06:13:01 -> 06:13:42 105:53:33 and 05:53:54 start inside the 05:00 hour; 06:13:01 starts inside the 06:00 hour. That reading predicts an hourly total around 2139, the same as the strict plain sum. I measured zero, across all 25 intervals. So whatever is happening is larger than the documented rule, and if anything that is evidence for your side of it — this option should not be able to empty a whole day.
Worth running before you wait on a fix: execute your descriptor twice in the same run, once with options: .strictStartDate and once with options: [], and print both. It takes one build. If the loose run is correct and the strict run is empty, it is the predicate rather than the store, and dropping the option is defensible anyway — without it HealthKit apportions a straddling sample across the intervals it overlaps, which is usually what a cumulative total wants.
On the limited-access-versus-full-access report above: I only ever measured with full access granted, so I can't tell you whether that interacts with this. If you can reproduce it under one and not the other, that is a second one-variable comparison and a more interesting one than mine.
Two caveats so this isn't taken further than it goes. .strictEndDate is not the fix — on the plain query it moves the loss to the other boundary rather than removing it. And if your samples are genuinely instantaneous (dietary energy, body mass), this isn't your cause; I measured a delta of exactly zero for those types.
One thread that may bear on the regression question, with the caveat that it may not be the same thing: 786576, June 2025, reports this option quietly losing the first interval of an hourly basalEnergyBurned collection query, with the low interval moving when the window moved. That is a partial loss and it is what the documented rule predicts. Mine is a total loss and isn't. Two mechanisms or one, I don't know.
Full write-up, with the three wrong diagnoses it took to get there: https://mcmizzle.com/blog/healthkit-collection-query-returns-zero/
Topic:
App & System Services
SubTopic:
Health & Fitness
Tags: