Skip to content

Wear: recover lost sessions and unstick tiles after a reconnect/re-pair - #9

Merged
SiteRelEnby merged 1 commit into
mainfrom
fix/wear-session-and-tile-recovery
Jun 19, 2026
Merged

SiteRelEnby merged 1 commit into
mainfrom
fix/wear-session-and-tile-recovery

Conversation

@SiteRelEnby

Copy link
Copy Markdown
Collaborator

Fixes a cluster of watch-sync failures that show up after the watch disconnects, loses its session, or gets re-paired. All reported from real use.

1. The watch couldn't recover a lost session without re-pairing

If the watch's companion session went away while the app was open (a token refresh that failed while disconnected, a revoked session, or a stale cached credential applied on launch and then rejected by the server), the watch stranded on the signed-out screen even though the phone could mint a fresh session on demand.

  • MainActivity now watches the auth flow and, on a signed-in to signed-out transition, asks the phone to re-mint and push fresh credentials (the phone already handles /sheaf/credentials/request by force-minting). Tracked against the previous value so a normal startup doesn't trigger a redundant re-mint.
  • "Retry Sync" now calls that same phone-request path instead of re-applying the stale cached DataItem (which was the same revoked credential that signed you out).

2. Tiles/complications stayed on "Open Sheaf on phone" after creds arrived

WearDataLayerService.handleCredentials saved the pushed credentials but never refreshed tiles/complications, so they stayed on the signed-out message until their next scheduled update. It now requests tile + complication updates right after saving (matching what the front-change nudge path already does).

3. Tile avatars stuck missing / pfp-less members invisible

Root cause: the tile resources version (currentResourcesVersion, shared by all five avatar tiles) only rotated when the fronter set or tile config changed, never when the avatar PNGs were re-rendered. So after a re-pair repopulated the avatar cache, Wear kept serving the stale resource bundle (built while avatars were missing) until the tile was deleted and recreated. That's the "recreate the tile and it's fine" behaviour, and it's also why a member with no avatar rendered as an invisible gap rather than their coloured initials (the fallback PNG existed on disk but the old bundle didn't map it).

  • The resources version now folds in a signature of the cached avatar set (file names + sizes), so re-rendered avatars get re-fetched. Uses size not mtime, so an identical re-render doesn't churn the version. This single shared fix covers all five avatar tiles.
  • A transient avatar download failure no longer overwrites a good cached avatar with the initials fallback; it keeps the existing image and the next refresh re-tries. (Common right after a re-pair, before the watch network has settled.)

With these in, the existing Settings to "Refresh" chip (store.loadAll()) actually re-fetches avatars onto the tiles, so there's a working manual escape hatch too.

Verification

  • :wear:testPlayReleaseUnitTest pass; :wear:assemblePlayRelease green through R8.
  • Not exercised on a real watch/phone pair here - the failures are timing/connectivity-driven (re-pair, network-not-settled), so this wants a real-device pass: re-pair the watch and confirm the app recovers without manual sign-in, and that tile avatars (incl. a pfp-less member) appear without deleting/recreating the tile.

Three related watch-sync failures after a disconnect or re-pair:

Session recovery. When a working companion session is lost while the app
is open (a refresh that failed offline, a revoked session, or a stale
cached credential applied on launch then rejected), the watch stranded on
the signed-out screen with no way back. MainActivity now watches the auth
flow and, on a signed-in to signed-out transition, asks the phone to
re-mint and push fresh credentials; 'Retry Sync' calls the same path
instead of re-applying the stale cached DataItem.

Tile refresh on credential arrival. WearDataLayerService.handleCredentials
saved the pushed credentials but never refreshed tiles/complications, so
they stayed on 'Open Sheaf on phone' until their next scheduled update.
It now requests tile + complication updates after saving.

Tile avatars stuck/invisible. The tile resources version only rotated on
fronter-set / tile-config changes, never when avatar PNGs were re-rendered,
so refreshed avatars (and the colour-initials fallback for pfp-less
members) stayed invisible until the tile was deleted and recreated. The
version now folds in a signature of the cached avatar set. Also, a
transient avatar download failure no longer overwrites a good cached
avatar with initials.
@SiteRelEnby
SiteRelEnby merged commit f234fbf into main Jun 19, 2026
1 check passed
@SiteRelEnby
SiteRelEnby deleted the fix/wear-session-and-tile-recovery branch June 19, 2026 02:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant