Skip to content

Commit 978fbcb

Browse files
committed
fix(android): preserve disabled environment history when activity cards are off
1 parent 2346eca commit 978fbcb

2 files changed

Lines changed: 27 additions & 4 deletions

File tree

‎infra/relay/src/agentActivity/FcmDeliveries.test.ts‎

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -395,6 +395,22 @@ describe("Android delivery routing", () => {
395395
h.current.target.preferences_json = encodeJson(preferences);
396396
yield* delivery.process(otherJob);
397397
expect(h.sent.filter((message) => message.alert)).toHaveLength(1);
398+
399+
h.current.target.preferences_json = encodeJson({
400+
...preferences,
401+
liveActivitiesEnabled: false,
402+
disabledEnvironmentIds: [state.environmentId, other.environmentId],
403+
});
404+
yield* delivery.process({ ...h.job, state: null, replay: true });
405+
h.current.target.preferences_json = encodeJson({
406+
...preferences,
407+
liveActivitiesEnabled: false,
408+
});
409+
yield* delivery.process(otherJob);
410+
expect(h.sent.filter((message) => message.alert)).toHaveLength(1);
411+
h.current.otherStates = [{ ...other, phase: "completed" }];
412+
yield* delivery.process({ ...otherJob, state: h.current.otherStates[0]! });
413+
expect(h.sent.filter((message) => message.alert)).toHaveLength(2);
398414
}).pipe(Effect.provide(h.layer));
399415
});
400416

‎infra/relay/src/agentActivity/FcmDeliveries.ts‎

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ import {
2929
alertForActivityRows,
3030
attentionTransitionRows,
3131
hiddenEnvironmentIds,
32+
sameEnvironmentIds,
3233
terminalTransitionRows,
3334
shouldAlertForActivity,
3435
} from "./agentActivityAlerts.ts";
@@ -200,6 +201,7 @@ const make = Effect.gen(function* () {
200201
if (!target) return;
201202
const preferences = decodePreferences(target.preferences_json);
202203
if (Option.isNone(preferences)) return;
204+
const currentHiddenEnvironmentIds = hiddenEnvironmentIds(preferences.value);
203205

204206
// Re-read at consumption to honor current links, tokens, preferences, and thread states.
205207
const states = preferences.value.liveActivitiesEnabled
@@ -288,7 +290,14 @@ const make = Effect.gen(function* () {
288290
}
289291
const displayedAggregate = preferences.value.liveActivitiesEnabled ? aggregate : null;
290292
const active = (displayedAggregate?.activeCount ?? 0) > 0;
291-
if (!displayedAggregate && !alert && !previousAggregate && job.state !== null) return;
293+
if (
294+
!displayedAggregate &&
295+
!alert &&
296+
!previousAggregate &&
297+
job.state !== null &&
298+
sameEnvironmentIds(target.last_hidden_environment_ids, currentHiddenEnvironmentIds)
299+
)
300+
return;
292301
const data: Record<string, string> = {
293302
t3_kind: "agent_activity",
294303
device_id: job.deviceId,
@@ -334,9 +343,7 @@ const make = Effect.gen(function* () {
334343
kind: active ? "live_activity_update" : "live_activity_end",
335344
// Retain terminal rows as the baseline so finished-card replays cannot alert again.
336345
aggregate: preferences.value.liveActivitiesEnabled ? aggregate : null,
337-
hiddenEnvironmentIds: preferences.value.liveActivitiesEnabled
338-
? hiddenEnvironmentIds(preferences.value)
339-
: null,
346+
hiddenEnvironmentIds: currentHiddenEnvironmentIds,
340347
deliveredAt: DateTime.formatIso(now),
341348
});
342349
}

0 commit comments

Comments
 (0)