Skip to content

Commit 3890d2d

Browse files
feat(mobile): degrade the agent Live Activity once its content goes stale
expo-widgets 58 exposes ActivityKit's staleDate. Locally started activities now carry the same ten-minute window the relay already puts on every push, so a card whose registration never reaches the relay stops claiming an agent is working. The layout reads environment.isStale and turns in-flight rows into "Out of date" with the neutral clock glyph, keeping terminal rows as they were. Co-Authored-By: Claude Fable 5 <[email protected]>
1 parent e625f1e commit 3890d2d

3 files changed

Lines changed: 84 additions & 33 deletions

File tree

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

Lines changed: 39 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,11 @@ const activityPushTokenListeners = new WeakSet<LiveActivity<AgentActivityProps>>
8282
// foreground after real time away still triggers a replay. Cleared on
8383
// sign-out/identity change alongside the device registration state.
8484
const ACTIVITY_TOKEN_REREGISTER_INTERVAL_MS = 60_000;
85+
// Locally started activities carry the same stale window the relay puts on
86+
// every push (STALE_AFTER_SECONDS in ApnsClient.ts), so a card whose relay
87+
// registration never lands still degrades instead of looking alive forever.
88+
const LIVE_ACTIVITY_STALE_AFTER_MS = 10 * 60_000;
89+
const liveActivityStaleDate = () => new Date(Date.now() + LIVE_ACTIVITY_STALE_AFTER_MS);
8590
const registeredActivityPushTokens = new Map<string, number>();
8691
let androidDeviceReplayedAt: number | null = null;
8792
let pushTokenSubscription: { remove: () => void } | null = null;
@@ -526,25 +531,29 @@ function armAgentAwarenessLiveActivityForLocalWorkNow(input: {
526531
return;
527532
}
528533
const nowIso = new Date(Date.now()).toISOString();
529-
const activity = AgentActivity.start({
530-
title: "T3 Code",
531-
subtitle: "Agent work in progress",
532-
activeCount: 1,
533-
updatedAt: nowIso,
534-
activities: [
535-
{
536-
environmentId: "",
537-
threadId: "",
538-
projectTitle: input.projectTitle,
539-
threadTitle: input.threadTitle,
540-
modelTitle: "",
541-
phase: "starting",
542-
status: "Connecting",
543-
updatedAt: nowIso,
544-
deepLink: "/",
545-
},
546-
],
547-
});
534+
const activity = AgentActivity.start(
535+
{
536+
title: "T3 Code",
537+
subtitle: "Agent work in progress",
538+
activeCount: 1,
539+
updatedAt: nowIso,
540+
activities: [
541+
{
542+
environmentId: "",
543+
threadId: "",
544+
projectTitle: input.projectTitle,
545+
threadTitle: input.threadTitle,
546+
modelTitle: "",
547+
phase: "starting",
548+
status: "Connecting",
549+
updatedAt: nowIso,
550+
deepLink: "/",
551+
},
552+
],
553+
},
554+
undefined,
555+
liveActivityStaleDate(),
556+
);
548557
logRegistrationDebug("live activity card armed for local work", {
549558
threadTitle: input.threadTitle,
550559
});
@@ -1127,13 +1136,17 @@ export function refreshActiveLiveActivityRemoteRegistration(): Effect.Effect<
11271136
const aggregate = snapshot.aggregate;
11281137
const primed = yield* Effect.try({
11291138
try: () =>
1130-
AgentActivity.start({
1131-
title: aggregate.title,
1132-
subtitle: aggregate.subtitle,
1133-
activeCount: aggregate.activeCount,
1134-
updatedAt: aggregate.updatedAt,
1135-
activities: aggregate.activities,
1136-
}),
1139+
AgentActivity.start(
1140+
{
1141+
title: aggregate.title,
1142+
subtitle: aggregate.subtitle,
1143+
activeCount: aggregate.activeCount,
1144+
updatedAt: aggregate.updatedAt,
1145+
activities: aggregate.activities,
1146+
},
1147+
undefined,
1148+
liveActivityStaleDate(),
1149+
),
11371150
catch: (cause) =>
11381151
new AgentAwarenessOperationError({
11391152
operation: "prime-live-activity",

‎apps/mobile/src/widgets/AgentActivity.test.ts‎

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,26 @@ describe("AgentActivity widget layout", () => {
8282
expect(banner).toContain("#fcd34d"); // amber-300: waiting_for_approval
8383
});
8484

85+
it("degrades in-flight rows once the system marks the activity stale", () => {
86+
const layout = AgentActivity(
87+
{
88+
...props,
89+
activeCount: 2,
90+
activities: [
91+
makeRow({}),
92+
makeRow({ threadId: "thread-2", phase: "completed", status: "Done" }),
93+
],
94+
},
95+
{ ...environment, isStale: true } as never,
96+
);
97+
const banner = JSON.stringify(layout.banner);
98+
expect(banner).toContain("Agent status out of date");
99+
expect(banner).toContain("Out of date");
100+
expect(banner).not.toContain("#7dd3fc"); // sky-300: running
101+
expect(banner).toContain("Done");
102+
expect(JSON.stringify(layout.minimal)).not.toContain("2");
103+
});
104+
85105
it("switches to the web sidebar's light palette when the scheme is light", () => {
86106
// macOS (iPhone Mirroring / Mac notification center) renders the activity
87107
// on a light background; the dark-material palette is illegible there.

‎apps/mobile/src/widgets/AgentActivity.tsx‎

Lines changed: 25 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,8 @@ export function AgentActivity(
8888
return isLightScheme ? "#dc2626" : "#fca5a5"; // red-600 / red-300
8989
case "completed":
9090
return isLightScheme ? "#059669" : "#6ee7b7"; // emerald-600 / emerald-300
91+
case "stale":
92+
return secondaryForeground;
9193
case "starting":
9294
case "running":
9395
default:
@@ -103,20 +105,28 @@ export function AgentActivity(
103105
if (phase === "running" || phase === "starting") return 2;
104106
return 3;
105107
};
106-
const ordered = [...props.activities].sort(
107-
(a, b) => phasePriority(a.phase) - phasePriority(b.phase),
108-
);
108+
// Past the stale date the system stops vouching for the content, so every
109+
// in-flight row degrades to "stale" rather than claiming an agent is still
110+
// working. Terminal phases keep their own state.
111+
const activities: ReadonlyArray<AgentActivityRowProps> = environment.isStale
112+
? props.activities.map((row) =>
113+
row.phase === "completed" || row.phase === "failed"
114+
? row
115+
: { ...row, phase: "stale", status: "Out of date" },
116+
)
117+
: props.activities;
118+
const ordered = [...activities].sort((a, b) => phasePriority(a.phase) - phasePriority(b.phase));
109119
const row0 = ordered[0];
110120
const row1 = ordered[1];
111121
const row2 = ordered[2];
112122
const row3 = ordered[3];
113123
const row4 = ordered[4];
114124

115-
const attentionRows = props.activities.filter(
125+
const attentionRows = activities.filter(
116126
(row) => row.phase === "waiting_for_approval" || row.phase === "waiting_for_input",
117127
);
118128
const attentionRow = attentionRows[0];
119-
const failedRow = props.activities.find((row) => row.phase === "failed");
129+
const failedRow = activities.find((row) => row.phase === "failed");
120130
const heroRow = attentionRow ?? failedRow ?? row0;
121131
const tint = phaseTint(heroRow?.phase);
122132
// Headline count leans on the accent when a human is actually blocked.
@@ -141,12 +151,20 @@ export function AgentActivity(
141151
// the two parts in-line so the attention half can carry the accent color;
142152
// `summary` is the short form for tight spots (expanded center, watch card).
143153
const agentWord = props.activeCount === 1 ? "agent" : "agents";
144-
const agentsLabel = allDone ? outcomeLabel : `${props.activeCount} active ${agentWord}`;
154+
const agentsLabel = allDone
155+
? outcomeLabel
156+
: environment.isStale
157+
? "Agent status out of date"
158+
: `${props.activeCount} active ${agentWord}`;
145159
const attentionSuffix =
146160
attentionRows.length > 0
147161
? `${attentionRows.length} need${attentionRows.length === 1 ? "s" : ""} attention`
148162
: "";
149-
const activeLabel = allDone ? doneLabel : `${props.activeCount} active`;
163+
const activeLabel = allDone
164+
? doneLabel
165+
: environment.isStale
166+
? "Out of date"
167+
: `${props.activeCount} active`;
150168
const summary = attentionSuffix || activeLabel;
151169

152170
// Any registered scheme variant routes back to this app; taps are delivered

0 commit comments

Comments
 (0)