The best way to control Claude Code, Codex and more from any computer or phone
Mirrored from https://github.com/Camo67/t3code.git
Synced Nov 22, 20:45 UTC
fix(mobile): expose background work and thread status actions (#21395)
maria committed
Oct 21, 2026 at 00:05 UTC
fe414ebdd3cb883436803d49672cbc4cf080bafa
8 files changed
+395
-23
apps/mobile/src/Stack.tsx
+11
@@ -71,6 +71,7 @@ import { GitConfirmSheet } from "./features/threads/git/GitConfirmSheet";
71
import { GitOverviewSheet } from "./features/threads/git/GitOverviewSheet";
72
import { ThreadPullRequestsSheet } from "./features/threads/ThreadPullRequestsSheet";
73
import { ThreadAgentsSheet } from "./features/threads/ThreadAgentsSheet";
74
+import { ThreadBackgroundWorkSheet } from "./features/threads/ThreadBackgroundWorkSheet";
75
import { ThreadQueueSheet } from "./features/threads/ThreadQueueControl";
76
import { ThreadRouteScreen } from "./features/threads/ThreadRouteScreen";
77
import { McpAppFullscreenScreen } from "./features/threads/McpAppFullscreenScreen";
@@ -558,6 +559,7 @@ const WORKSPACE_OVERLAY_ROUTES = new Set([
559
"SettingsLegal",
560
"SettingsSheet",
561
"ThreadAgents",
562
+ "ThreadBackgroundWork",
563
"ThreadPullRequests",
564
"ThreadQueue",
565
"ThreadReviewComment",
@@ -869,6 +871,15 @@ const RootStackConfig = createWorkspaceStackNavigator({
871
sheetGrabberVisible: true,
872
},
873
}),
874
+ ThreadBackgroundWork: createNativeStackScreen({
875
+ screen: ThreadBackgroundWorkSheet,
876
+ options: {
877
+ ...FORM_SHEET_PRESENTATION_OPTIONS,
878
+ headerShown: false,
879
+ sheetAllowedDetents: [0.5, 0.9],
880
+ sheetGrabberVisible: true,
881
+ },
882
+ }),
883
ThreadAgents: createNativeStackScreen({
884
screen: ThreadAgentsSheet,
885
options: {
apps/mobile/src/features/threads/ThreadBackgroundWorkSheet.tsx
new
+143
@@ -0,0 +1,143 @@
1
+import { useAtomValue } from "@effect/atom-react";
2
+import { StackActions, useNavigation, type StaticScreenProps } from "@react-navigation/native";
3
+import { scopeThreadRef } from "@t3tools/client-runtime/environment";
4
+import {
5
+ presentPendingBackgroundWork,
6
+ type PendingBackgroundWorkItem,
7
+} from "@t3tools/client-runtime/state/thread-execution";
8
+import type { EnvironmentId, ThreadId } from "@t3tools/contracts";
9
+import * as Haptics from "expo-haptics";
10
+import { Platform, Pressable, ScrollView, View } from "react-native";
11
+import { ScreenStack } from "react-native-screens";
12
+import { useSafeAreaInsets } from "react-native-safe-area-context";
13
+
14
+import { AndroidSheetHeader } from "../../components/ui/AndroidScreenHeader";
15
+import { SymbolView } from "../../components/ui/AppSymbol";
16
+import { AppText as Text } from "../../components/ui/AppText";
17
+import { ScreenContent } from "../../components/ui/ScreenContent";
18
+import { NativeStackScreenOptions, nativeHeaderScrollEdgeEffects } from "../../native/StackHeader";
19
+import { NativeHeader, NativeScreen } from "../../native/ThemedScreenStack";
20
+import { environmentThreadShells } from "../../state/threads";
21
+import { useAdaptiveWorkspaceLayout } from "../layout/AdaptiveWorkspaceLayout";
22
+
23
+const HEADER_SCROLL_EDGE_EFFECTS = nativeHeaderScrollEdgeEffects(Platform.OS, Platform.Version);
24
+const KIND_LABELS = {
25
+ subagent: "Subagent",
26
+ command: "Command",
27
+ monitor: "Monitor",
28
+ background_task: "Background task",
29
+} as const;
30
+
31
+type BackgroundWorkTarget = { readonly environmentId: EnvironmentId; readonly threadId: ThreadId };
32
+
33
+export function ThreadBackgroundWorkSheet({ route }: StaticScreenProps<BackgroundWorkTarget>) {
34
+ const { layout } = useAdaptiveWorkspaceLayout();
35
+ const navigation = useNavigation();
36
+ const insets = useSafeAreaInsets();
37
+ const target = route.params;
38
+ const thread = useAtomValue(
39
+ environmentThreadShells.threadShellAtom(scopeThreadRef(target.environmentId, target.threadId)),
40
+ );
41
+ const presentation = presentPendingBackgroundWork(thread?.pendingBackgroundTasks ?? []);
42
+ const openThread = (threadId: ThreadId) => {
43
+ void Haptics.selectionAsync();
44
+ // A thread replaces the leaf sheet so workspace back navigation still works.
45
+ navigation.dispatch(
46
+ StackActions.replace("Thread", { environmentId: target.environmentId, threadId }),
47
+ );
48
+ };
49
+ const content = (
50
+ <ScrollView
51
+ nestedScrollEnabled
52
+ className="flex-1"
53
+ contentInsetAdjustmentBehavior={Platform.OS === "ios" ? "automatic" : "never"}
54
+ contentContainerClassName="px-5 pb-6"
55
+ contentContainerStyle={{ paddingBottom: Math.max(insets.bottom, 16) + 8 }}
56
+ >
57
+ {presentation === null ? (
58
+ <Text className="pt-6 text-center text-sm text-foreground-muted">
59
+ Nothing running in the background.
60
+ </Text>
61
+ ) : (
62
+ presentation.items.map((item) => (
63
+ <BackgroundWorkRow key={item.taskId} item={item} onOpen={openThread} />
64
+ ))
65
+ )}
66
+ </ScrollView>
67
+ );
68
+ if (Platform.OS === "ios") {
69
+ return (
70
+ <View collapsable={false} className="flex-1 bg-sheet">
71
+ <ScreenStack style={{ flex: 1 }}>
72
+ <NativeScreen
73
+ activityState={2}
74
+ enabled
75
+ isNativeStack
76
+ screenId="thread-background-work-sheet-native"
77
+ scrollEdgeEffects={HEADER_SCROLL_EDGE_EFFECTS}
78
+ className="flex-1 bg-sheet"
79
+ >
80
+ {content}
81
+ <NativeHeader
82
+ backgroundColor="rgba(0,0,0,0)"
83
+ tintColorClassName="accent-foreground"
84
+ hideBackButton
85
+ hideShadow={false}
86
+ title="Background work"
87
+ titleColorClassName="accent-foreground"
88
+ titleFontSize={18}
89
+ titleFontWeight="800"
90
+ translucent
91
+ />
92
+ </NativeScreen>
93
+ </ScreenStack>
94
+ </View>
95
+ );
96
+ }
97
+ return (
98
+ <View collapsable={false} className="flex-1 bg-sheet">
99
+ <NativeStackScreenOptions options={{ sheetCornerRadius: 28 }} />
100
+ <AndroidSheetHeader title="Background work" onBack={() => navigation.goBack()} />
101
+ <ScreenContent insetHorizontal={layout.usesSplitView}>{content}</ScreenContent>
102
+ </View>
103
+ );
104
+}
105
+
106
+function BackgroundWorkRow(props: {
107
+ readonly item: PendingBackgroundWorkItem;
108
+ readonly onOpen: (threadId: ThreadId) => void;
109
+}) {
110
+ const { item } = props;
111
+ const childThreadId = item.childThreadId;
112
+ const row = (
113
+ <View className="flex-row items-center gap-3 border-b border-border py-3.5">
114
+ <SymbolView
115
+ name={
116
+ item.kind === "subagent" ? "person.2" : item.kind === "monitor" ? "clock" : "terminal"
117
+ }
118
+ size={15}
119
+ tintColorClassName="accent-foreground-muted"
120
+ type="monochrome"
121
+ />
122
+ <View className="min-w-0 flex-1">
123
+ <Text className="font-t3-medium text-sm text-foreground">{item.label}</Text>
124
+ <Text className="text-xs text-foreground-muted">{KIND_LABELS[item.kind]}</Text>
125
+ </View>
126
+ {childThreadId === undefined ? null : (
127
+ <SymbolView name="chevron.right" size={12} tintColorClassName="accent-icon-subtle" />
128
+ )}
129
+ </View>
130
+ );
131
+ return childThreadId === undefined ? (
132
+ <View accessible>{row}</View>
133
+ ) : (
134
+ <Pressable
135
+ accessibilityRole="link"
136
+ accessibilityLabel={`Open subagent ${item.label}`}
137
+ onPress={() => props.onOpen(childThreadId)}
138
+ className="active:opacity-70"
139
+ >
140
+ {row}
141
+ </Pressable>
142
+ );
143
+}
apps/mobile/src/features/threads/ThreadDetailScreen.tsx
+142
-2
@@ -1,4 +1,8 @@
1
-import { settlePromise, squashAtomCommandFailure } from "@t3tools/client-runtime/state/runtime";
1
+import {
2
+ isAtomCommandInterrupted,
3
+ settlePromise,
4
+ squashAtomCommandFailure,
5
+} from "@t3tools/client-runtime/state/runtime";
6
import { AsyncResult } from "effect/reactivity";
7
import * as Dialog from "../../components/ui/Dialog";
8
import { useAtomValue } from "@effect/atom-react";
@@ -8,7 +12,13 @@ import {
12
useThreadShell,
13
} from "../../state/entities";
14
import { UsageLimitRecoveryCard } from "./UsageLimitRecoveryCard";
11
-import { StackActions, useNavigation } from "@react-navigation/native";
15
+import { StackActions, useFocusEffect, useNavigation } from "@react-navigation/native";
16
+import {
17
+ effectiveSnoozed,
18
+ threadWokeAt,
19
+ isThreadWokeUnseen,
20
+ snoozeWakeLabel,
21
+} from "@t3tools/client-runtime/state/thread-settled";
22
import type { WorktreeSetupCardProps } from "./worktree-setup-card";
23
import type { ComposerTextPaste } from "../../native/T3ComposerEditor.types";
24
import { type EnvironmentConnectionPhase } from "@t3tools/client-runtime/connection";
@@ -516,6 +526,96 @@ export const ThreadDetailScreen = function ThreadDetailScreen(props: ThreadDetai
526
}
527
})();
528
const threadSyncLabel = useDelayedStatus(selectedThreadKey, realThreadSyncLabel);
529
+ const interruptThreadTurn = useAtomCommand(threadEnvironment.interruptTurn, {
530
+ reportFailure: false,
531
+ });
532
+ const unsnoozeThread = useAtomCommand(threadEnvironment.unsnooze, { reportFailure: false });
533
+ const unsettleThread = useAtomCommand(threadEnvironment.unsettle, { reportFailure: false });
534
+ const updateMetadata = useAtomCommand(threadEnvironment.updateMetadata, { reportFailure: false });
535
+ const visitThread = useAtomCommand(threadEnvironment.visit, { reportFailure: false });
536
+ const [statusRequest, setStatusRequest] = useState<{ threadKey: string } | null>(null);
537
+ const statusPending = statusRequest?.threadKey === selectedThreadKey;
538
+ const [lifecycleNow, setLifecycleNow] = useState(() => new Date().toISOString());
539
+ useFocusEffect(
540
+ useCallback(() => {
541
+ setLifecycleNow(new Date().toISOString());
542
+ const timer = setInterval(() => setLifecycleNow(new Date().toISOString()), 60_000);
543
+ return () => clearInterval(timer);
544
+ }, []),
545
+ );
546
+ const snoozed =
547
+ props.serverConfig?.environment.capabilities.threadSnooze === true &&
548
+ effectiveSnoozed(props.selectedThread, { now: lifecycleNow });
549
+ const snoozedUntil = props.selectedThread.snoozedUntil;
550
+ useEffect(() => {
551
+ if (!snoozed || snoozedUntil === null) return;
552
+ const timer = setTimeout(
553
+ () => setLifecycleNow(new Date().toISOString()),
554
+ Math.min(Math.max(0, Date.parse(snoozedUntil) - Date.now()) + 50, 2_147_483_647),
555
+ );
556
+ return () => clearTimeout(timer);
557
+ // oxlint-disable-next-line react/exhaustive-effect-dependencies -- Re-arm if timer clamping fires before the wake time.
558
+ }, [snoozed, snoozedUntil, lifecycleNow]);
559
+ const settled =
560
+ props.serverConfig?.environment.capabilities.threadSettlement === true &&
561
+ props.selectedThread.settledOverride === "settled";
562
+ const wokeAt =
563
+ props.serverConfig?.environment.capabilities.threadSnooze === true
564
+ ? threadWokeAt(props.selectedThread, { now: lifecycleNow })
565
+ : null;
566
+ const woke = isThreadWokeUnseen({
567
+ wokeAt,
568
+ settled,
569
+ lastVisitedAt: props.selectedThread.lastVisitedAt,
570
+ latestRunCompletedAt: props.selectedThread.latestRun?.completedAt ?? null,
571
+ });
572
+ const runStatusAction = async (action: "stop" | "wake" | "unsettle" | "dismiss") => {
573
+ if (statusPending || !props.canOperateThread) return;
574
+ const request = { threadKey: selectedThreadKey };
575
+ setStatusRequest(request);
576
+ const target = {
577
+ environmentId: props.environmentId,
578
+ input: { threadId: props.selectedThread.id },
579
+ };
580
+ const recovery = props.selectedThread.limitRecovery;
581
+ const recoveryOwnsSnooze =
582
+ recovery?.snooze === true &&
583
+ recovery.runId === props.selectedThread.latestRun?.runId &&
584
+ snoozedUntil !== null &&
585
+ Date.parse(snoozedUntil) === Date.parse(recovery.resetAt);
586
+ const result =
587
+ action === "stop"
588
+ ? await interruptThreadTurn(target)
589
+ : action === "wake"
590
+ ? recoveryOwnsSnooze
591
+ ? await updateMetadata({
592
+ ...target,
593
+ input: {
594
+ ...target.input,
595
+ limitRecovery: {
596
+ runId: recovery.runId,
597
+ resetAt: recovery.resetAt,
598
+ snooze: false,
599
+ },
600
+ },
601
+ })
602
+ : await unsnoozeThread({ ...target, input: { ...target.input, reason: "user" } })
603
+ : action === "unsettle"
604
+ ? await unsettleThread({ ...target, input: { ...target.input, reason: "user" } })
605
+ : await visitThread({
606
+ ...target,
607
+ input: { ...target.input, visitedAt: wokeAt ?? lifecycleNow },
608
+ });
609
+ // An accepted interrupt can leave tasks running. Release the action for retry.
610
+ setStatusRequest((current) => (current === request ? null : current));
611
+ if (result._tag === "Failure" && !isAtomCommandInterrupted(result)) {
612
+ const error = squashAtomCommandFailure(result);
613
+ Dialog.alert(
614
+ "Could not update thread",
615
+ error instanceof Error ? error.message : "Try again.",
616
+ );
617
+ }
618
+ };
619
const pendingBackgroundWork = presentPendingBackgroundWork(
620
props.selectedThread.pendingBackgroundTasks,
621
);
@@ -576,6 +676,46 @@ export const ThreadDetailScreen = function ThreadDetailScreen(props: ThreadDetai
676
.map((item) => item.label)
677
.join(", ")}`,
678
waiting: pendingBackgroundWork.waiting,
679
+ onPress: () => {
680
+ Keyboard.dismiss();
681
+ navigation.navigate("ThreadBackgroundWork", {
682
+ environmentId: props.environmentId,
683
+ threadId: props.selectedThread.id,
684
+ });
685
+ },
686
+ action: {
687
+ label: statusPending ? "Stopping..." : "Stop",
688
+ accessibilityLabel: "Stop background work",
689
+ disabled: !props.canOperateThread || statusPending,
690
+ onPress: () => void runStatusAction("stop"),
691
+ },
692
+ };
693
+ }
694
+ if (contentPresentationKind === "ready" && (snoozed || settled || woke)) {
695
+ const state = snoozed ? "snoozed" : settled ? "settled" : "woke";
696
+ const label =
697
+ snoozed && snoozedUntil !== null
698
+ ? `Snoozed, wakes in ${snoozeWakeLabel(snoozedUntil, { now: lifecycleNow })}`
699
+ : settled
700
+ ? "Settled"
701
+ : "Woke from snooze";
702
+ const actionLabel = snoozed ? "Wake now" : settled ? "Un-settle" : "Dismiss";
703
+ return {
704
+ kind: "lifecycle",
705
+ state,
706
+ label,
707
+ action: {
708
+ label: statusPending
709
+ ? snoozed
710
+ ? "Waking..."
711
+ : settled
712
+ ? "Un-settling..."
713
+ : "Dismissing..."
714
+ : actionLabel,
715
+ accessibilityLabel: actionLabel,
716
+ disabled: !props.canOperateThread || statusPending,
717
+ onPress: () => void runStatusAction(snoozed ? "wake" : settled ? "unsettle" : "dismiss"),
718
+ },
719
};
720
}
721
if (props.selectedThread.goal !== null && contentPresentationKind === "ready") {
apps/mobile/src/features/threads/floating-working-control.tsx
+50
-3
@@ -84,6 +84,11 @@ export function FloatingWorkingControl(props: {
84
const { width: windowWidth } = useWindowDimensions();
85
const [overlayWidth, setOverlayWidth] = useState(windowWidth);
86
const [queueWidth, setQueueWidth] = useState(0);
87
+ const [actionWidth, setActionWidth] = useState(0);
88
+ const action =
89
+ props.status?.kind === "background" || props.status?.kind === "lifecycle"
90
+ ? props.status.action
91
+ : null;
92
const [agentsWidth, setAgentsWidth] = useState(0);
93
const hasQueue = props.queuedCount > 0;
94
const hasPreview = props.devicePreview !== null || props.browserPreview !== null;
@@ -95,6 +100,7 @@ export function FloatingWorkingControl(props: {
100
Math.min(overlayWidth, windowWidth) -
101
CONTROL_HEIGHT -
102
32 -
103
+ (action !== null ? actionWidth : 0) -
104
(hasQueue ? queueWidth : 0) -
105
(hasAgents ? agentsWidth : 0) -
106
(hasPreview ? previewWidth : 0),
@@ -156,8 +162,11 @@ export function FloatingWorkingControl(props: {
162
hasQueue ||
163
(props.devicePreview !== null && props.browserPreview !== null);
164
const statusInteractive =
159
- props.status?.kind === "connection" || props.status?.kind === "child-input";
160
- const capsuleInteractive = statusInteractive || hasQueue || hasAgents || hasPreview;
165
+ props.status?.kind === "connection" ||
166
+ props.status?.kind === "child-input" ||
167
+ props.status?.kind === "background";
168
+ const capsuleInteractive =
169
+ statusInteractive || action !== null || hasQueue || hasAgents || hasPreview;
170
const statusContent =
171
props.status !== null ? (
172
<View
@@ -186,6 +195,22 @@ export function FloatingWorkingControl(props: {
195
const capsuleContent = (
196
<View className="flex-row items-center">
197
{statusContent}
198
+ {action !== null ? (
199
+ <Pressable
200
+ accessibilityRole="button"
201
+ accessibilityLabel={action.accessibilityLabel}
202
+ accessibilityState={{ disabled: action.disabled }}
203
+ disabled={action.disabled}
204
+ onPress={action.onPress}
205
+ onLayout={(event) => setActionWidth(settleWidth(event.nativeEvent.layout.width))}
206
+ className={`h-11 flex-row items-center gap-1.5 px-3 active:opacity-70 ${action.disabled ? "opacity-50" : ""}`}
207
+ >
208
+ <View className="mr-1 h-4 w-px bg-border" />
209
+ <Text className="font-t3-medium text-xs text-foreground" numberOfLines={1}>
210
+ {action.label}
211
+ </Text>
212
+ </Pressable>
213
+ ) : null}
214
{hasPreview ? (
215
<View
216
className="h-11 flex-row items-center"
@@ -404,16 +429,38 @@ function FloatingStatusLabel(props: {
429
</StatusLabelRow>
430
);
431
}
432
+ if (props.status.kind === "lifecycle") {
433
+ return (
434
+ <StatusLabelRow
435
+ key="lifecycle"
436
+ accessibilityLabel={props.status.label}
437
+ className="gap-2"
438
+ onLayout={props.onLayout}
439
+ >
440
+ <SymbolView
441
+ name={props.status.state === "settled" ? "checkmark.circle" : "clock"}
442
+ size={13}
443
+ tintColorClassName="foreground"
444
+ type="monochrome"
445
+ />
446
+ <Text className="shrink font-t3-medium text-xs text-foreground" numberOfLines={1}>
447
+ {props.status.label}
448
+ </Text>
449
+ </StatusLabelRow>
450
+ );
451
+ }
452
if (props.status.kind === "background") {
453
return (
454
<StatusLabelRow
455
key="background"
456
accessibilityLabel={props.status.accessibilityLabel}
457
+ accessibilityRole="button"
458
+ onPress={props.status.onPress}
459
className="gap-2"
460
onLayout={props.onLayout}
461
>
462
<SymbolView
416
- name={props.status.waiting ? { ios: "bolt", android: "bolt" } : "terminal"}
463
+ name={props.status.waiting ? "person.2" : "terminal"}
464
size={13}
465
tintColorClassName="foreground"
466
type="monochrome"
apps/mobile/src/features/threads/floating-working-status.ts
+15
@@ -1,5 +1,12 @@
1
import type { EnvironmentConnectionPhase } from "@t3tools/client-runtime/connection";
2
3
+export interface FloatingStatusAction {
4
+ readonly label: string;
5
+ readonly accessibilityLabel: string;
6
+ readonly disabled: boolean;
7
+ readonly onPress: () => void;
8
+}
9
+
10
export type FloatingWorkingStatus =
11
| { readonly kind: "working"; readonly startedAt: string }
12
| { readonly kind: "syncing"; readonly label: string }
@@ -15,6 +22,14 @@ export type FloatingWorkingStatus =
22
readonly label: string;
23
readonly accessibilityLabel: string;
24
readonly waiting: boolean;
25
+ readonly onPress: () => void;
26
+ readonly action: FloatingStatusAction;
27
+ }
28
+ | {
29
+ readonly kind: "lifecycle";
30
+ readonly state: "snoozed" | "settled" | "woke";
31
+ readonly label: string;
32
+ readonly action: FloatingStatusAction;
33
}
34
| { readonly kind: "goal"; readonly label: string; readonly accessibilityLabel: string }
35
| { readonly kind: "preparing"; readonly label: string }
apps/web/src/components/ChatView.logic.ts
+1
-18
@@ -1362,21 +1362,4 @@ export function mergeDirectPreviewAnnotation(input: {
1362
return { images, previewAnnotations };
1363
}
1364
1365
-/**
1366
- * Whether a woken thread woke after the user last saw it. A run that completed
1367
- * after the last visit counts as seeing it, since the user watched it finish.
1368
- */
1369
-export function isThreadWokeUnseen(input: {
1370
- readonly wokeAt: string | null;
1371
- readonly settled: boolean;
1372
- readonly lastVisitedAt: string | null | undefined;
1373
- readonly latestRunCompletedAt: string | null;
1374
-}): boolean {
1375
- if (input.wokeAt === null || input.settled) return false;
1376
- const wokeAtMs = Date.parse(input.wokeAt);
1377
- if (Number.isNaN(wokeAtMs)) return false;
1378
- const seenAt = [input.lastVisitedAt, input.latestRunCompletedAt]
1379
- .map((value) => (value ? Date.parse(value) : NaN))
1380
- .filter((ms) => !Number.isNaN(ms));
1381
- return seenAt.every((ms) => ms < wokeAtMs);
1382
-}
1365
+export { isThreadWokeUnseen } from "@t3tools/client-runtime/state/thread-settled";
packages/client-runtime/src/state/threadSettled.ts
+19
@@ -294,3 +294,22 @@ export function localSnoozeDate(date: Date): string {
294
export function localSnoozeTime(date: Date): string {
295
return `${String(date.getHours()).padStart(2, "0")}:${String(date.getMinutes()).padStart(2, "0")}`;
296
}
297
+
298
+/**
299
+ * Whether a woken thread woke after the user last saw it. A run that completed
300
+ * after the last visit counts as seeing it, since the user watched it finish.
301
+ */
302
+export function isThreadWokeUnseen(input: {
303
+ readonly wokeAt: string | null;
304
+ readonly settled: boolean;
305
+ readonly lastVisitedAt: string | null | undefined;
306
+ readonly latestRunCompletedAt: string | null;
307
+}): boolean {
308
+ if (input.wokeAt === null || input.settled) return false;
309
+ const wokeAtMs = Date.parse(input.wokeAt);
310
+ if (Number.isNaN(wokeAtMs)) return false;
311
+ const seenAt = [input.lastVisitedAt, input.latestRunCompletedAt]
312
+ .map((value) => (value ? Date.parse(value) : NaN))
313
+ .filter((ms) => !Number.isNaN(ms));
314
+ return seenAt.every((ms) => ms < wokeAtMs);
315
+}
packages/client-runtime/src/state/threadSnoozed.test.ts
+14
@@ -11,6 +11,7 @@ import {
11
snoozeWakeLabel,
12
threadRaisedHandWhileSnoozed,
13
threadWokeAt,
14
+ isThreadWokeUnseen,
15
type ThreadSnoozeShell,
16
} from "./threadSettled.ts";
17
@@ -418,3 +419,16 @@ describe("resolveSnoozePresets", () => {
419
expect(tomorrow.getDay()).toBe(1);
420
});
421
});
422
+
423
+it("dismisses a wake at its timestamp without hiding a later wake", () => {
424
+ const firstWake = "2026-04-10T10:00:00.000Z";
425
+ const state = {
426
+ wokeAt: firstWake,
427
+ settled: false,
428
+ lastVisitedAt: null,
429
+ latestRunCompletedAt: null,
430
+ };
431
+ expect(isThreadWokeUnseen(state)).toBe(true);
432
+ expect(isThreadWokeUnseen({ ...state, lastVisitedAt: firstWake })).toBe(false);
433
+ expect(isThreadWokeUnseen({ ...state, lastVisitedAt: firstWake, wokeAt: NOW })).toBe(true);
434
+});