Hello,
I'm seeing an inconsistency in how HKAnchoredObjectQuery applies predicates between its initial results handler and its update handler. Specifically, predicates that filter quantity samples by correlation membership - using either HKQuery.predicateForObjectsWithNoCorrelation() or NSPredicate(format: "%K == nil", HKPredicateKeyPathCorrelation) - are respected in the resultsHandler but silently ignored in the updateHandler.
Setup
I have three long-running HKAnchoredObjectQuery instances:
- One for HKCorrelationType(.bloodPressure) - no predicate
- One for HKQuantityType(.bloodPressureSystolic) - predicate:
HKQuery.predicateForObjectsWithNoCorrelation() - One for HKQuantityType(.bloodPressureDiastolic) - predicate:
HKQuery.predicateForObjectsWithNoCorrelation()
The intent of the predicate on the systolic/diastolic queries is to capture only standalone quantity samples written directly by third-party apps - not the constituent sub-samples of an HKCorrelation. The correlation query handles correlated samples.
Expected behavior
When a BloodPressure correlation is saved to the store, only the correlation query's updateHandler should fire, with 1 new sample. The systolic and diastolic updateHandlers should not fire, since those samples have correlation != nil which is excluded by the predicate.
Actual behavior
After saving one BloodPressure correlation, all three updateHandlers fire with 1 new object each. The systolic and diastolic update handlers receive the correlated sub-samples despite the predicateForObjectsWithNoCorrelation() predicate. The same predicate correctly filters those kinds of samples out of the initial resultsHandler.
Additionally, the same predicate applied in a one-shot HKSampleQuery for the systolic or diastolic type correctly returns 0 results when only correlated readings exist.
The problem is only experienced in updateHandler of a long-running HKAnchoredObjectQuery.
Tested iOS versions
- iOS 26.3
- iOS 18.7.6
Workaround
When an HKAnchoredObjectQuery updateHandler fires with systolic or diastolic samples, I fire a one-shot HKSampleQuery with a compound predicate using the sample UUIDs and predicateForObjectsWithNoCorrelation. Any samples that are part of a correlation are not returned in the HKSampleQuery resultsHandler.