Skip to content

Commit 2085ea3

Browse files
authored
fix(mobile): thread rows show wake status and elapsed time (pingdotgg#21394)
1 parent 05696c6 commit 2085ea3

10 files changed

Lines changed: 231 additions & 20 deletions

File tree

‎apps/mobile/src/features/home/HomeScreen.tsx‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -636,6 +636,7 @@ export function HomeScreen(props: HomeScreenProps) {
636636
hasQueuedMessages={item.hasQueuedMessages}
637637
snoozed={item.item.snoozed}
638638
pinned={item.item.pinned}
639+
wokeAt={item.item.wokeAt}
639640
snoozePresetMinute={item.snoozePresetMinute ?? ""}
640641
snoozeWakeLabelText={item.snoozeWakeLabelText}
641642
timeLabel={item.timeLabel}

‎apps/mobile/src/features/threads/ThreadDetailScreen.tsx‎

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -357,7 +357,25 @@ function ThreadVisitWatermark(props: {
357357
const lastDispatchedVisitRef = useRef<string | null>(null);
358358
const lastVisitDispatchRef = useRef({ threadKey: selectedThreadKey, at: 0 });
359359
const selectedThreadId = thread.id;
360-
const selectedThreadUpdatedAt = thread.updatedAt;
360+
const snoozedUntil = thread.snoozedUntil;
361+
// Keep the clock in state so React Compiler invalidates the wake calculation.
362+
const [wakeNow, setWakeNow] = useState(() => new Date().toISOString());
363+
useEffect(() => {
364+
if (!showContent || snoozedUntil == null) return;
365+
const delay = Date.parse(snoozedUntil) - Date.now();
366+
if (!Number.isFinite(delay)) return;
367+
const timer = setTimeout(() => setWakeNow(new Date().toISOString()), Math.max(0, delay) + 50);
368+
return () => clearTimeout(timer);
369+
}, [showContent, snoozedUntil]);
370+
const selectedThreadWokeAt = threadWokeAt(thread, {
371+
now: wakeNow,
372+
});
373+
// A scheduled wake can happen without a newer server update.
374+
const selectedThreadUpdatedAt =
375+
selectedThreadWokeAt !== null && Date.parse(selectedThreadWokeAt) > Date.parse(thread.updatedAt)
376+
? selectedThreadWokeAt
377+
: thread.updatedAt;
378+
const wakeIsLatestUpdate = selectedThreadUpdatedAt === selectedThreadWokeAt;
361379
const selectedThreadLastVisitedAt = thread.lastVisitedAt;
362380
const selectedThreadCompletedAt = thread.latestRun?.completedAt;
363381
useEffect(() => {
@@ -384,7 +402,14 @@ function ThreadVisitWatermark(props: {
384402
(Number.isNaN(lastVisitedAtMs) || completedAtMs > lastVisitedAtMs);
385403
const previous = lastVisitDispatchRef.current;
386404
const elapsed = Date.now() - previous.at;
387-
if (previous.threadKey !== selectedThreadKey || hasUnseenCompletion || elapsed >= 10_000) {
405+
// Like a completion, a wake the user is looking at must not wait out the throttle:
406+
// leaving within it would cancel the dispatch and keep Woke in the list.
407+
if (
408+
previous.threadKey !== selectedThreadKey ||
409+
hasUnseenCompletion ||
410+
wakeIsLatestUpdate ||
411+
elapsed >= 10_000
412+
) {
388413
dispatch();
389414
return;
390415
}
@@ -399,6 +424,7 @@ function ThreadVisitWatermark(props: {
399424
selectedThreadUpdatedAt,
400425
showContent,
401426
visitThread,
427+
wakeIsLatestUpdate,
402428
]);
403429
return null;
404430
}

‎apps/mobile/src/features/threads/ThreadNavigationSidebar.tsx‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -599,6 +599,7 @@ function ThreadNavigationSidebarPane(
599599
hasQueuedMessages={item.hasQueuedMessages}
600600
snoozed={item.item.snoozed}
601601
pinned={item.item.pinned}
602+
wokeAt={item.item.wokeAt}
602603
snoozePresetMinute={item.snoozePresetMinute ?? ""}
603604
snoozeWakeLabelText={item.snoozeWakeLabelText}
604605
timeLabel={item.timeLabel}

‎apps/mobile/src/features/threads/thread-list-v2-items.tsx‎

Lines changed: 68 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,19 @@ import { RowPressable } from "../../components/ui/RowPressable";
1212
import { CustomSnoozeSheet } from "./CustomSnoozeSheet";
1313
import { appAtomRegistry } from "../../state/atom-registry";
1414
import { threadArrangementOpenAtom } from "../../state/thread-order";
15+
import { threadEnvironment } from "../../state/threads";
16+
import { useAtomCommand } from "../../state/use-atom-command";
17+
import { useVisibleSecondClock } from "./use-visible-second-clock";
1518
import type { ThreadMoveDestination } from "./threadOrder";
1619
import type {
1720
EnvironmentProject,
1821
EnvironmentThreadShell,
1922
} from "@t3tools/client-runtime/state/shell";
2023
import type { EnvironmentThreadSearchMatch } from "@t3tools/client-runtime/state/thread-search";
24+
import {
25+
formatWorkingDurationLabel,
26+
resolveThreadWorkingStartedAt,
27+
} from "@t3tools/client-runtime/state/models";
2128
import { AuthOrchestrationOperateScope, type EnvironmentMachineKind } from "@t3tools/contracts";
2229
import { canSnooze, resolveSnoozePresets } from "@t3tools/client-runtime/state/thread-settled";
2330
import type { MenuAction } from "@react-native-menu/menu";
@@ -112,6 +119,13 @@ const DONE_STATUS_LABEL: StatusLabel = {
112119
iconTintClassName: "accent-adaptive-emerald-700-300",
113120
};
114121

122+
function ThreadListV2Duration(props: { readonly startedAt: string | null }) {
123+
const startedAtMs = Date.parse(props.startedAt ?? "");
124+
const nowMs = useVisibleSecondClock(Number.isFinite(startedAtMs));
125+
if (!Number.isFinite(startedAtMs)) return null;
126+
return ` ${formatWorkingDurationLabel(nowMs - startedAtMs)}`;
127+
}
128+
115129
const CARD_MENU_ACTIONS: MenuAction[] = [
116130
{ id: "settle", title: "Settle", image: "checkmark" },
117131
{ id: "delete", title: "Delete", image: "trash", attributes: { destructive: true } },
@@ -477,6 +491,7 @@ export const ThreadListV2Row = memo(function ThreadListV2Row(props: {
477491
readonly hasQueuedMessages?: boolean;
478492
readonly snoozed?: boolean;
479493
readonly pinned?: boolean;
494+
readonly wokeAt: string | null;
480495
readonly snoozeWakeLabelText?: string;
481496
readonly timeLabel: string;
482497
readonly snoozePresetMinute: string;
@@ -568,12 +583,6 @@ export const ThreadListV2Row = memo(function ThreadListV2Row(props: {
568583
const handleOpenPullRequests = useCallback(() => {
569584
if (pr) onOpenThreadPullRequests(thread, pr);
570585
}, [onOpenThreadPullRequests, pr, thread]);
571-
// VoiceOver cannot focus the badge inside the accessible row, so the row
572-
// exposes the same action.
573-
const rowAccessibilityActions = useMemo(
574-
() => (prBadgeLabel ? [{ name: "openPullRequests", label: prBadgeLabel }] : undefined),
575-
[prBadgeLabel],
576-
);
577586

578587
const theme = useUniwindTheme();
579588
const sidebarPane = props.pane === "sidebar";
@@ -583,13 +592,31 @@ export const ThreadListV2Row = memo(function ThreadListV2Row(props: {
583592
const status = resolveThreadListV2Status(thread);
584593
const isUnread = status === "ready" && threadHasUnseenCompletion(thread);
585594
const workingLabel = STATUS_LABEL_BY_STATUS[status];
595+
const showsWoke = status === "ready" && props.wokeAt !== null;
586596
const statusLabel =
587597
(status === "working" && workingLabel !== undefined && thread.goal?.status === "active"
588598
? { ...workingLabel, label: "Goal" }
589599
: workingLabel) ?? (isUnread ? DONE_STATUS_LABEL : undefined);
590600
const recede = shouldRecedeThreadRow({ status, selected });
591601
const timeLabel = props.timeLabel;
592602

603+
const visitThread = useAtomCommand(threadEnvironment.visit, { reportFailure: false });
604+
const handleAcknowledgeWoke = useCallback(() => {
605+
if (props.wokeAt === null) return;
606+
void visitThread({
607+
environmentId: thread.environmentId,
608+
input: { threadId: thread.id, visitedAt: props.wokeAt },
609+
});
610+
}, [props.wokeAt, thread.environmentId, thread.id, visitThread]);
611+
// VoiceOver cannot focus buttons inside the accessible row.
612+
const rowAccessibilityActions = useMemo(
613+
() => [
614+
...(prBadgeLabel ? [{ name: "openPullRequests", label: prBadgeLabel }] : []),
615+
...(showsWoke ? [{ name: "dismissWoke", label: "Dismiss Woke notification" }] : []),
616+
],
617+
[prBadgeLabel, showsWoke],
618+
);
619+
593620
const handleDelete = useCallback(() => onDeleteThread(thread), [onDeleteThread, thread]);
594621
const handleRename = useCallback(() => onRenameThread(thread), [onRenameThread, thread]);
595622
const canOperateThread = useEnvironmentScope(thread.environmentId, AuthOrchestrationOperateScope);
@@ -948,7 +975,34 @@ export const ThreadListV2Row = memo(function ThreadListV2Row(props: {
948975
type="monochrome"
949976
/>
950977
) : null}
951-
{statusLabel ? (
978+
{showsWoke ? (
979+
<Pressable
980+
className="-m-2.5 flex-row items-center gap-1 p-2.5"
981+
accessibilityRole="button"
982+
accessibilityLabel="Dismiss Woke notification"
983+
onPress={handleAcknowledgeWoke}
984+
onLongPress={() => undefined}
985+
style={({ pressed }) => ({ opacity: pressed ? 0.6 : 1 })}
986+
>
987+
<SymbolView
988+
name="bell.badge"
989+
size={13}
990+
tintColorClassName={
991+
selected ? selectedThreadRowColors.iconTintClassName : "accent-warning-foreground"
992+
}
993+
type="monochrome"
994+
weight="semibold"
995+
/>
996+
<Text
997+
className={cn(
998+
"text-xs font-t3-bold",
999+
selected ? selectedThreadRowColors.foregroundClassName : "text-warning-foreground",
1000+
)}
1001+
>
1002+
Woke
1003+
</Text>
1004+
</Pressable>
1005+
) : statusLabel ? (
9521006
<View className="flex-row items-center gap-1">
9531007
<SymbolView
9541008
name={statusLabel.icon}
@@ -962,10 +1016,16 @@ export const ThreadListV2Row = memo(function ThreadListV2Row(props: {
9621016
<Text
9631017
className={cn(
9641018
"text-xs font-t3-bold",
1019+
(status === "working" || status === "waiting") && "tabular-nums",
9651020
selected ? selectedThreadRowColors.foregroundClassName : statusLabel.className,
9661021
)}
9671022
>
9681023
{statusLabel.label}
1024+
{status === "working" ? (
1025+
<ThreadListV2Duration startedAt={resolveThreadWorkingStartedAt(thread)} />
1026+
) : status === "waiting" ? (
1027+
<ThreadListV2Duration startedAt={thread.latestRun?.completedAt ?? null} />
1028+
) : null}
9691029
</Text>
9701030
</View>
9711031
) : (
@@ -1156,6 +1216,7 @@ export const ThreadListV2Row = memo(function ThreadListV2Row(props: {
11561216
accessibilityActions={rowAccessibilityActions}
11571217
onAccessibilityAction={(event) => {
11581218
if (event.nativeEvent.actionName === "openPullRequests") handleOpenPullRequests();
1219+
if (event.nativeEvent.actionName === "dismissWoke") handleAcknowledgeWoke();
11591220
}}
11601221
onPress={() => {
11611222
close();

‎apps/mobile/src/features/threads/threadListV2.test.ts‎

Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ import {
3535
getThreadListV2OrderedSection,
3636
resolveThreadListV2SnoozeMenuSelection,
3737
resolveThreadListV2Status,
38+
resolveThreadListV2WokeAt,
3839
resolveThreadListV2SwipeActions,
3940
sortThreadsForListV2,
4041
threadListV2ListItemsAreEqual,
@@ -1426,6 +1427,100 @@ describe("threadListV2ListItemsAreEqual", () => {
14261427
});
14271428
});
14281429

1430+
describe("thread list Woke marker", () => {
1431+
const wokeAt = isoAt(BASE_MS - MINUTE_MS);
1432+
const thread = makeThread({
1433+
id: ThreadId.make("woke"),
1434+
title: "Woke",
1435+
latestUserMessageAt: isoAt(BASE_MS - 90 * MINUTE_MS),
1436+
snoozedAt: isoAt(BASE_MS - 60 * MINUTE_MS),
1437+
snoozedUntil: wokeAt,
1438+
lastVisitedAt: null,
1439+
});
1440+
1441+
it("keeps a timer wake through a plain visit until acknowledgement reaches its timestamp", () => {
1442+
expect(resolveThreadListV2WokeAt(thread, { now: NOW })).toBe(wokeAt);
1443+
expect(
1444+
resolveThreadListV2WokeAt(
1445+
{ ...thread, lastVisitedAt: isoAt(BASE_MS - 30 * MINUTE_MS) },
1446+
{ now: NOW },
1447+
),
1448+
).toBe(wokeAt);
1449+
expect(
1450+
resolveThreadListV2WokeAt({ ...thread, lastVisitedAt: wokeAt }, { now: NOW }),
1451+
).toBeNull();
1452+
expect(resolveThreadListV2WokeAt({ ...thread, lastVisitedAt: "invalid" }, { now: NOW })).toBe(
1453+
wokeAt,
1454+
);
1455+
});
1456+
1457+
it("stays hidden while snoozed, after settling, and on servers without visited tracking", () => {
1458+
expect(resolveThreadListV2WokeAt(thread, { now: isoAt(BASE_MS - 2 * MINUTE_MS) })).toBeNull();
1459+
expect(
1460+
resolveThreadListV2WokeAt({ ...thread, settledOverride: "settled" }, { now: NOW }),
1461+
).toBeNull();
1462+
expect(
1463+
resolveThreadListV2WokeAt({ ...thread, lastVisitedAt: undefined }, { now: NOW }),
1464+
).toBeNull();
1465+
expect(resolveThreadListV2WokeAt({ ...thread, snoozedUntil: null }, { now: NOW })).toBeNull();
1466+
});
1467+
1468+
it("keeps an early failure wake acknowledged after the scheduled time passes", () => {
1469+
const completedAt = isoAt(BASE_MS - 2 * MINUTE_MS);
1470+
const failed = makeThread({
1471+
...thread,
1472+
snoozedUntil: isoAt(BASE_MS + MINUTE_MS),
1473+
runtime: {
1474+
status: "failed",
1475+
activeRunId: null,
1476+
providerInstanceId: ProviderInstanceId.make("codex"),
1477+
providerName: "Codex",
1478+
lastError: "Run failed",
1479+
updatedAt: completedAt,
1480+
},
1481+
latestRun: {
1482+
runId: RunId.make("woke-run"),
1483+
status: "failed",
1484+
requestedAt: isoAt(BASE_MS - 3 * MINUTE_MS),
1485+
startedAt: isoAt(BASE_MS - 3 * MINUTE_MS),
1486+
completedAt,
1487+
assistantMessageId: null,
1488+
},
1489+
});
1490+
expect(resolveThreadListV2WokeAt(failed, { now: NOW })).toBe(completedAt);
1491+
expect(
1492+
resolveThreadListV2WokeAt(
1493+
{ ...failed, lastVisitedAt: completedAt },
1494+
{ now: isoAt(BASE_MS + 2 * MINUTE_MS) },
1495+
),
1496+
).toBeNull();
1497+
});
1498+
1499+
it("updates a recycled row at the wake boundary even without a new shell or minute tick", () => {
1500+
const waking = { ...thread, snoozedUntil: isoAt(BASE_MS + 30_000) };
1501+
const layout = (now: string) =>
1502+
buildThreadListV2Items({
1503+
threads: [waking],
1504+
environmentId: null,
1505+
searchQuery: "",
1506+
now,
1507+
snoozeEnvironmentIds: new Set<EnvironmentId>(),
1508+
});
1509+
const list = (now: string) =>
1510+
buildThreadListV2ListItems({
1511+
items: layout(now).items,
1512+
pendingTasks: [],
1513+
snoozeLabelNow: isoAt(BASE_MS),
1514+
});
1515+
const before = list(NOW)[0]!;
1516+
const after = list(isoAt(BASE_MS + 37_500))[0]!;
1517+
expect(before.type === "v2-thread" && before.item.wokeAt).toBeNull();
1518+
expect(after.type === "v2-thread" && after.item.wokeAt).toBe(waking.snoozedUntil);
1519+
expect(after.type === "v2-thread" && after.timeLabel).toBe("");
1520+
expect(threadListV2ListItemsAreEqual(before, after)).toBe(false);
1521+
});
1522+
});
1523+
14291524
describe("buildThreadListV2ListItems row-state stamps", () => {
14301525
const readyThread = makeThread({
14311526
id: ThreadId.make("stamp-ready"),

0 commit comments

Comments
 (0)