Field notes
Deletion Records Expire: Why a Log Should Keep Its Own Change History
HealthKit may remove its record of a deleted entry at any time. If you want a log you can audit months later, keep your own history of edits and removals.
Short answer#
If you want a log you can audit months later, keep your own edit history. Apple's record that an entry was deleted is temporary by design, and an edit can overwrite the earlier value. Nothing in the platform promises to remember what changed. Your log has to.
This page is about record-keeping, not about what to log or take. It covers what Apple documents, what that implies for an audit trail, and what a change history should hold.
What a deletion record holds#
When a sample is deleted from the HealthKit store, apps can learn about it through an object called HKDeletedObject. Apple describes it as an object that represents a sample that has been deleted from the store. It carries two things: the identifier (a UUID) of the object that was deleted, and the metadata that object had.
That is a thin record. It doesn't carry the old value, the unit or the time of the change. It tells an app only that something with a given identifier is gone.
The same page is direct about how long it lasts: "Deleted objects are temporary; the system may remove them from the HealthKit store at any time to free up space." Apple gives no retention period. There is no number of days you can plan around.
We covered the mechanics in how an app finds out about a deletion. The point here is the consequence. A deletion record is a notice, not an archive.
A missed sync can mean a missed deletion#
Apps read changes through an anchored query. According to Apple's HKAnchoredObjectQuery documentation, the query returns an anchor that corresponds to the last sample or deleted object it received, and later queries can use that anchor to get only newer saved or deleted objects. The results include both new samples and an array of deleted objects.
Apple also notes that to be sure you hear about every deletion, you register an observer query for background delivery. The observer signals that something changed, but it does not list the deleted objects. You follow it with an anchored query to get the list.
Put those two facts together with the temporary records. An app that does not run its anchored query before the system clears a record has no way to see that deletion. Apple does not document that scenario in those words, so read this as a reasoned consequence rather than a stated rule. It is still the reason not to depend on the platform for your history. An entry can be gone from the store while your own copy still shows it, or the reverse, and nothing flags the difference.
For more on how anchors work, see anchors in incremental sync.
An edit can overwrite the old value#
Deletions are not the only change you lose. Apple documents a way for an app to update a piece of data. The sync identifier key is a unique string that identifies data so it can be updated and synced, and it must be paired with a sync version.
Apple's description of the behavior: when you save an object with a sync identifier, the system looks for existing objects with the same identifier. If it finds a match and the new object has a greater sync version, "the system replaces the old object with the new one."
Replaced is the operative word. The page describes replacement. It says nothing about keeping the earlier value for you to read back. If a reading was logged as 5.2 and later corrected, the store's job is to hold the current version. Whether you can still see 5.2 is up to whatever you kept.
The related post on replaced instead of duplicated walks through the identifier and version pairing.
What your own change history should record#
A change history does not need to be elaborate. It needs one row per change, written at the time of the change, never rewritten afterward. These fields cover most audit questions:
| Field | Why it earns its place | | --- | --- | | Entry identifier | Ties the change to one entry, even after it is edited or removed | | Change type | Added, edited or removed | | Old value and unit | The part the store may not keep | | New value and unit | Lets you rebuild any past version | | Time of the change | When you made it, separate from when the event happened | | Short reason note | A few words, such as "typo" or "wrong unit" |
A short example shows the idea. Say an entry for a lab value was first saved with the wrong unit. The history row records the entry identifier, "edited", the old value with its unit, the corrected value with its unit, the date you fixed it and the note "wrong unit". Months later, anyone reading the log can see both versions and when the correction happened, with no guesswork.
Two habits matter more than the field list.
Keep removals as rows. When you remove an entry, add a "removed" row and mark the entry as removed. Do not erase it. A log that silently loses rows cannot show a gap from a deletion, so you cannot tell a forgotten day from a deleted one.
Never edit history rows. If a history row is wrong, add a new row that corrects it. The value of the trail comes from it being append-only.
Recording the time of the change separately from the event time also pays off later. A related idea is covered in what a logged entry can and cannot prove: a record is only as strong as what it can show about itself.
None of this changes what you log. It changes whether a reader, including you in six months, can trust how the log got to its current state.
The takeaway#
Apple's deletion records are temporary and may be removed at any time. Edits can replace the earlier value. Both are reasonable design choices for a health store. Both also mean the store is not your audit trail. Keep your own append-only history of edits and removals, with the old value, the new value and the time of each change, and your log can answer the question "what did this say before?" long after the platform has forgotten.
Share
Related
01
