Skip to content

Commit 807ae6a

Browse files
committed
fix(mobile): discard stale snapshots before starting Live Activities
1 parent ad0551e commit 807ae6a

2 files changed

Lines changed: 19 additions & 3 deletions

File tree

‎apps/mobile/src/features/agent-awareness/remoteRegistration.test.ts‎

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -947,6 +947,7 @@ describe("makeRelayDeviceRegistrationRequest", () => {
947947

948948
for (const transition of ["sign-out", "account-switch", "release", "newer-refresh"] as const) {
949949
it.effect(`discards a suspended widget snapshot after ${transition}`, () => {
950+
vi.mocked(loadPreferences).mockResolvedValue({ liveActivitiesEnabled: true });
950951
const started = Promise.withResolvers<void>();
951952
const response = Promise.withResolvers<Response>();
952953
let calls = 0;
@@ -968,7 +969,17 @@ describe("makeRelayDeviceRegistrationRequest", () => {
968969
if (transition === "release") releaseAgentAwarenessRelayTokenProvider();
969970
if (transition === "newer-refresh") yield* refreshActiveLiveActivityRemoteRegistration();
970971
widgetMocks.updateSnapshot.mockClear();
971-
response.resolve(Response.json({ aggregate: null }));
972+
response.resolve(
973+
Response.json({
974+
aggregate: {
975+
title: "T3 Code",
976+
subtitle: "Working",
977+
activeCount: 1,
978+
updatedAt: "2026-09-06T12:00:00.000Z",
979+
activities: [],
980+
},
981+
}),
982+
);
972983
yield* Fiber.join(refresh);
973984
expect(widgetMocks.updateSnapshot).not.toHaveBeenCalled();
974985
expect(widgetMocks.start).not.toHaveBeenCalled();

‎apps/mobile/src/features/agent-awareness/remoteRegistration.ts‎

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1163,10 +1163,15 @@ export function refreshActiveLiveActivityRemoteRegistration(): Effect.Effect<
11631163
: null;
11641164
if (accountGeneration !== deviceRegistrationGeneration || !relayTokenProvider) return;
11651165
const snapshot = yield* readAgentActivitySnapshot();
1166-
if (accountGeneration !== deviceRegistrationGeneration || !relayTokenProvider) return;
1166+
if (
1167+
accountGeneration !== deviceRegistrationGeneration ||
1168+
!relayTokenProvider ||
1169+
widgetGeneration !== widgetRefreshGeneration
1170+
)
1171+
return;
11671172
// Home-screen widgets do not depend on the Live Activities preference or
11681173
// an existing lock-screen card. Failed reads retain the last snapshot.
1169-
if (snapshot && widgetGeneration === widgetRefreshGeneration) {
1174+
if (snapshot) {
11701175
publishAgentActivityWidget(snapshot.aggregate ?? {});
11711176
}
11721177
if (activities.length === 0) {

0 commit comments

Comments
 (0)