Skip to content

Apple Watch sync: a set's identity across watch edits (four edge cases from #1139) #1162

Open

Description

@cubetes

Suggested labels: bug, mobile · Suggested milestone: v1.4.6: Wear OS & Health Connect
(I can't set these myself: my account has no triage rights on this repo.)

Why

The set-type menu on the Apple Watch (#1139) lets you mark, add and remove sets from the wrist while the phone keeps its own copy of the workout. CodeRabbit found four edge cases where the two copies can briefly disagree. None loses a logged set, and each is rare. But they all come from the same root: the watch and the phone name a set by its position, and positions move when sets are added or removed. Fixing them properly means giving sets a stable identity across the sync, which is too big for a review fix on #1139. This issue keeps them together so #1139 can merge.

The four cases

  1. A tick after a refused Remove can land on a shifted row. If the phone refuses a removal from the watch, a tick queued after it is applied by position and can mark the neighbouring set. The code already says so (lean: comment in lib/watch-sync.js, setDone after a refused structural event). (comment)
  2. Any phone update ends the 4 s Undo early. SessionStore.apply(json:) sends a held removal as soon as any valid snapshot arrives, on purpose: Undo would otherwise overwrite a newer snapshot. An echo of your own tick can therefore hide Undo after a second. (comment)
  3. One exercise twice in a workout shares its marks. Keys are exerciseId#setIndex with no entry, so moving a warm-up or removing a set in one entry also moves the other entry's pending ticks, skips and efforts. The key format predates Watch: mark Warm-up, Failure and Drop sets, and add or remove sets, from the wrist #1139; the remap that spreads it is new. (comment)
  4. A mark made before a tick can vanish for one sync. When an older snapshot lands, the tick is merged before the pending edits replay, so a mark captured before the tick is dropped until the next snapshot. Nothing is lost: the phone applies both in watch order. (comment)

What a fix looks like

  • A stable id per set row, carried in snapshots and events (the phone already has one per logged set in history).
  • Ticks, marks, Undo and pending keys keyed by that id instead of exId#index, with a one-time migration of stored keys.
  • Undo that drops the held removal from the current state instead of restoring the old state.

Until then, (3) could be avoided by turning off Warm-up and Remove in the watch menu for an exercise that appears twice.

Related: #1139.

🤖 Generated with Claude Code

https://claude.ai/code/session_01LXHs9Pg1EhvFPo2LUFWwrp

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions