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 24, 09:00 UTC
feat(mobile): show when an existing thread has a message waiting in the outbox (#10405)
Co-authored-by: Claude Fable 5 <noreply@anthropic.com>
Julius Marminge committed
Sep 6, 2026 at 16:40 UTC
d6aa179ad2afe0424e1410cbafbb119bbd5f7809
14 files changed
+193
-8
apps/mobile/src/components/AppSymbol.tsx
+2
@@ -84,6 +84,7 @@ import IconTextIncrease from "@tabler/icons-react-native/IconTextIncrease";
84
import IconTool from "@tabler/icons-react-native/IconTool";
85
import IconTrash from "@tabler/icons-react-native/IconTrash";
86
import IconTypography from "@tabler/icons-react-native/IconTypography";
87
+import IconUpload from "@tabler/icons-react-native/IconUpload";
88
import IconUserCircle from "@tabler/icons-react-native/IconUserCircle";
89
import IconWifiOff from "@tabler/icons-react-native/IconWifiOff";
90
import IconWorld from "@tabler/icons-react-native/IconWorld";
@@ -173,6 +174,7 @@ const ANDROID_ICON_BY_SF_SYMBOL: Partial<Record<SFSymbol, Icon>> = {
174
"textformat.size": IconTypography,
175
"textformat.size.larger": IconTextIncrease,
176
"textformat.size.smaller": IconTextDecrease,
177
+ "tray.and.arrow.up": IconUpload,
178
trash: IconTrash,
179
"wifi.slash": IconWifiOff,
180
xmark: IconX,
apps/mobile/src/features/home/HomeScreen.tsx
+12
@@ -38,6 +38,7 @@ import { useThreadListV2Enabled } from "../threads/use-thread-list-v2-enabled";
38
import { usePendingThreadOrder } from "../../state/thread-order";
39
import { environmentServerConfigsAtom } from "../../state/server";
40
import type { PendingNewTask } from "../../state/use-pending-new-tasks";
41
+import { useQueuedThreadKeys } from "../../state/use-thread-outbox";
42
import {
43
PendingTaskListRow,
44
ThreadListGroupHeader,
@@ -212,6 +213,7 @@ export function HomeScreen(props: HomeScreenProps) {
213
>(() => new Map());
214
const preferencesResult = useAtomValue(mobilePreferencesAtom);
215
const threadListV2Enabled = useThreadListV2Enabled();
216
+ const queuedThreadKeys = useQueuedThreadKeys();
217
const savePreferences = useAtomSet(updateMobilePreferencesAtom);
218
const openSwipeableRef = useRef<SwipeableMethods | null>(null);
219
const listRef = useRef<LegendListRef | null>(null);
@@ -384,6 +386,7 @@ export function HomeScreen(props: HomeScreenProps) {
386
projects: scopedProjects,
387
threads: scopedThreads,
388
pendingTasks: scopedPendingTasks,
389
+ queuedThreadKeys,
390
environmentId: props.selectedEnvironmentId,
391
searchQuery: props.searchQuery,
392
matchedThreadKeys,
@@ -393,6 +396,7 @@ export function HomeScreen(props: HomeScreenProps) {
396
}),
397
[
398
threadListV2Enabled,
399
+ queuedThreadKeys,
400
props.projectGroupingMode,
401
props.projectSortOrder,
402
props.searchQuery,
@@ -655,6 +659,7 @@ export function HomeScreen(props: HomeScreenProps) {
659
now: new Date().toISOString(),
660
settlementEnvironmentIds,
661
snoozeEnvironmentIds,
662
+ queuedThreadKeys,
663
}),
664
});
665
return { pinned: sectionPlanner("pinned"), active: sectionPlanner("active") };
@@ -662,6 +667,7 @@ export function HomeScreen(props: HomeScreenProps) {
667
serverConfigs,
668
props.threads,
669
pendingOrder,
670
+ queuedThreadKeys,
671
settlementEnvironmentIds,
672
snoozeEnvironmentIds,
673
nowMinute,
@@ -689,6 +695,7 @@ export function HomeScreen(props: HomeScreenProps) {
695
matchedThreadKeys,
696
settlementEnvironmentIds,
697
snoozeEnvironmentIds,
698
+ queuedThreadKeys,
699
settledLimit: settledVisibleCount,
700
now: new Date().toISOString(),
701
snoozedShelfExpanded,
@@ -697,6 +704,7 @@ export function HomeScreen(props: HomeScreenProps) {
704
});
705
}, [
706
pendingOrder,
707
+ queuedThreadKeys,
708
nowMinute,
709
snoozeWakeTick,
710
snoozedShelfExpanded,
@@ -818,6 +826,7 @@ export function HomeScreen(props: HomeScreenProps) {
826
<ThreadListV2Row
827
thread={thread}
828
variant={item.item.variant}
829
+ hasQueuedMessages={queuedThreadKeys.has(movedId)}
830
snoozed={item.item.snoozed}
831
pinned={item.item.pinned}
832
snoozePresetMinute={nowMinute}
@@ -883,6 +892,7 @@ export function HomeScreen(props: HomeScreenProps) {
892
activeReorderEnvironmentIds,
893
threadMovePlanners,
894
pendingOrder,
895
+ queuedThreadKeys,
896
handleMoveThread,
897
handlePinThread,
898
handleRegenerateThreadTitle,
@@ -993,6 +1003,7 @@ export function HomeScreen(props: HomeScreenProps) {
1003
<ThreadListRow
1004
variant="compact"
1005
thread={thread}
1006
+ hasQueuedMessages={queuedThreadKeys.has(`${thread.environmentId}:${thread.id}`)}
1007
environmentLabel={
1008
props.savedConnectionsById[thread.environmentId]?.environmentLabel ?? null
1009
}
@@ -1032,6 +1043,7 @@ export function HomeScreen(props: HomeScreenProps) {
1043
handleSwipeableWillOpen,
1044
handleRegenerateThreadTitle,
1045
machineByEnvironmentId,
1046
+ queuedThreadKeys,
1047
props.onArchiveThread,
1048
props.onDeletePendingTask,
1049
props.onDeleteThread,
apps/mobile/src/features/home/homeThreadList.test.ts
+37
@@ -615,6 +615,43 @@ describe("buildHomeThreadGroups", () => {
615
expect(group?.threads.map((thread) => thread.id)).toEqual(["recent-1", "recent-2", "old"]);
616
});
617
618
+ it("keeps an old thread in the default view while a message waits in its outbox", () => {
619
+ const environmentId = EnvironmentId.make("environment-1");
620
+ const project = makeProject({
621
+ environmentId,
622
+ id: ProjectId.make("project-1"),
623
+ title: "T3 Code",
624
+ });
625
+ const threads = [
626
+ makeThread({
627
+ environmentId,
628
+ id: ThreadId.make("recent"),
629
+ projectId: project.id,
630
+ title: "Today",
631
+ updatedAt: "2026-06-28T00:00:00.000Z",
632
+ }),
633
+ makeThread({
634
+ environmentId,
635
+ id: ThreadId.make("old-queued"),
636
+ projectId: project.id,
637
+ title: "Two weeks ago, follow-up queued offline",
638
+ updatedAt: "2026-06-14T00:00:00.000Z",
639
+ }),
640
+ makeThread({
641
+ environmentId,
642
+ id: ThreadId.make("old"),
643
+ projectId: project.id,
644
+ title: "Two weeks ago",
645
+ updatedAt: "2026-06-13T00:00:00.000Z",
646
+ }),
647
+ ];
648
+
649
+ const group = buildGroups([project], threads, {
650
+ queuedThreadKeys: new Set([`${environmentId}:old-queued`]),
651
+ })[0];
652
+ expect(group?.recentThreads.map((thread) => thread.id)).toEqual(["recent", "old-queued"]);
653
+ });
654
+
655
it("falls back to the most recent 3 threads when none are within 5 days", () => {
656
const environmentId = EnvironmentId.make("environment-1");
657
const project = makeProject({
apps/mobile/src/features/home/homeThreadList.ts
+10
-3
@@ -24,7 +24,7 @@ import * as Arr from "effect/Array";
24
import * as Option from "effect/Option";
25
import * as Order from "effect/Order";
26
27
-import { scopedProjectKey } from "../../lib/scopedEntities";
27
+import { scopedProjectKey, scopedThreadKey } from "../../lib/scopedEntities";
28
import type { PendingNewTask } from "../../state/use-pending-new-tasks";
29
30
export type HomeProjectSortOrder = Exclude<SidebarProjectSortOrder, "manual">;
@@ -190,10 +190,15 @@ function selectRecentThreads(
190
sortedThreads: ReadonlyArray<EnvironmentThreadShell>,
191
threadSortOrder: SidebarThreadSortOrder,
192
now: number,
193
+ queuedThreadKeys: ReadonlySet<string> | undefined,
194
): ReadonlyArray<EnvironmentThreadShell> {
195
const cutoff = now - RECENT_THREAD_WINDOW_MS;
196
+ // A thread with a message waiting in the outbox has work the user is
197
+ // waiting on, however old its last activity; it never trims away.
198
const recent = sortedThreads.filter(
196
- (thread) => getThreadSortTimestamp(thread, threadSortOrder) >= cutoff,
199
+ (thread) =>
200
+ getThreadSortTimestamp(thread, threadSortOrder) >= cutoff ||
201
+ queuedThreadKeys?.has(scopedThreadKey(thread.environmentId, thread.id)) === true,
202
);
203
return recent.length > 0 ? recent : sortedThreads.slice(0, RECENT_THREAD_FALLBACK_COUNT);
204
}
@@ -202,6 +207,8 @@ export function buildHomeThreadGroups(input: {
207
readonly projects: ReadonlyArray<EnvironmentProject>;
208
readonly threads: ReadonlyArray<EnvironmentThreadShell>;
209
readonly pendingTasks?: ReadonlyArray<PendingNewTask>;
210
+ /** Thread keys with a message waiting in the outbox; kept in the default view. */
211
+ readonly queuedThreadKeys?: ReadonlySet<string>;
212
readonly environmentId: EnvironmentId | null;
213
readonly searchQuery: string;
214
readonly matchedThreadKeys?: ReadonlySet<string>;
@@ -326,7 +333,7 @@ export function buildHomeThreadGroups(input: {
333
// only trims the default (no-query) view.
334
const recentThreads =
335
query.length === 0
329
- ? selectRecentThreads(sortedThreads, input.threadSortOrder, now)
336
+ ? selectRecentThreads(sortedThreads, input.threadSortOrder, now, input.queuedThreadKeys)
337
: sortedThreads;
338
339
// A stale project id still resolves to the canonical member with the same
apps/mobile/src/features/home/useThreadListActions.ts
+2
@@ -12,6 +12,7 @@ import { pinOrderKeyBetween } from "@t3tools/client-runtime/state/thread-sort";
12
import { appAtomRegistry } from "../../state/atom-registry";
13
import { environmentServerConfigsAtom } from "../../state/server";
14
import { environmentThreadShells, threadEnvironment } from "../../state/threads";
15
+import { queuedThreadKeysAtom } from "../../state/use-thread-outbox";
16
import { useAtomCommand } from "../../state/use-atom-command";
17
import { beginPendingThreadOrder, getPendingThreadOrder } from "../../state/thread-order";
18
import { createPendingThreadOrder, createThreadMovePlanner } from "../threads/threadOrder";
@@ -480,6 +481,7 @@ export function useThreadListActions(): {
481
threads: shells,
482
section,
483
now: new Date().toISOString(),
484
+ queuedThreadKeys: appAtomRegistry.get(queuedThreadKeysAtom),
485
settlementEnvironmentIds: new Set(
486
[...configs].flatMap(([id, config]) =>
487
config.environment.capabilities.threadSettlement === true ? [id] : [],
apps/mobile/src/features/threads/ThreadNavigationSidebar.tsx
+11
@@ -33,6 +33,7 @@ import { useThreadListV2ShelfPreferences } from "./use-thread-list-v2-shelf-pref
33
import { usePendingThreadOrder } from "../../state/thread-order";
34
import { environmentServerConfigsAtom } from "../../state/server";
35
import { usePendingNewTasks } from "../../state/use-pending-new-tasks";
36
+import { useQueuedThreadKeys } from "../../state/use-thread-outbox";
37
import { useWorkspaceState } from "../../state/workspace";
38
import { useSavedRemoteConnections } from "../../state/use-remote-environment-registry";
39
import { useHardwareKeyboardCommand } from "../keyboard/hardwareKeyboardCommands";
@@ -165,6 +166,7 @@ function ThreadNavigationSidebarPane(
166
} = useThreadListActions();
167
const threadListV2Enabled = useThreadListV2Enabled();
168
const pendingTasks = usePendingNewTasks();
169
+ const queuedThreadKeys = useQueuedThreadKeys();
170
const { openPendingTask, confirmDeletePendingTask } = usePendingTaskListActions();
171
const environments = useMemo(
172
() =>
@@ -313,6 +315,7 @@ function ThreadNavigationSidebarPane(
315
projects: scopedProjects,
316
threads: scopedThreads,
317
pendingTasks: scopedPendingTasks,
318
+ queuedThreadKeys,
319
environmentId: options.selectedEnvironmentId,
320
searchQuery: props.searchQuery,
321
matchedThreadKeys,
@@ -322,6 +325,7 @@ function ThreadNavigationSidebarPane(
325
}),
326
[
327
threadListV2Enabled,
328
+ queuedThreadKeys,
329
matchedThreadKeys,
330
options,
331
props.searchQuery,
@@ -489,6 +493,7 @@ function ThreadNavigationSidebarPane(
493
now: new Date().toISOString(),
494
settlementEnvironmentIds,
495
snoozeEnvironmentIds,
496
+ queuedThreadKeys,
497
}),
498
});
499
return { pinned: sectionPlanner("pinned"), active: sectionPlanner("active") };
@@ -496,6 +501,7 @@ function ThreadNavigationSidebarPane(
501
serverConfigs,
502
threads,
503
pendingOrder,
504
+ queuedThreadKeys,
505
settlementEnvironmentIds,
506
snoozeEnvironmentIds,
507
nowMinute,
@@ -521,6 +527,7 @@ function ThreadNavigationSidebarPane(
527
matchedThreadKeys,
528
settlementEnvironmentIds,
529
snoozeEnvironmentIds,
530
+ queuedThreadKeys,
531
settledLimit: settledVisibleCount,
532
now: new Date().toISOString(),
533
snoozedShelfExpanded,
@@ -529,6 +536,7 @@ function ThreadNavigationSidebarPane(
536
});
537
}, [
538
pendingOrder,
539
+ queuedThreadKeys,
540
nowMinute,
541
snoozeWakeTick,
542
snoozedShelfExpanded,
@@ -884,6 +892,7 @@ function ThreadNavigationSidebarPane(
892
<ThreadListV2Row
893
thread={thread}
894
variant={item.item.variant}
895
+ hasQueuedMessages={queuedThreadKeys.has(`${thread.environmentId}:${thread.id}`)}
896
snoozed={item.item.snoozed}
897
pinned={item.item.pinned}
898
snoozePresetMinute={nowMinute}
@@ -1017,6 +1026,7 @@ function ThreadNavigationSidebarPane(
1026
<ThreadListRow
1027
variant="sidebar"
1028
thread={thread}
1029
+ hasQueuedMessages={queuedThreadKeys.has(`${thread.environmentId}:${thread.id}`)}
1030
environmentLabel={
1031
savedConnectionsById[thread.environmentId]?.environmentLabel ?? null
1032
}
@@ -1061,6 +1071,7 @@ function ThreadNavigationSidebarPane(
1071
activeReorderEnvironmentIds,
1072
threadMovePlanners,
1073
pendingOrder,
1074
+ queuedThreadKeys,
1075
confirmDeletePendingTask,
1076
confirmDeleteThread,
1077
handleSelectThread,
apps/mobile/src/features/threads/queued-message-icon.tsx
new
+15
@@ -0,0 +1,15 @@
1
+import { SymbolView } from "../../components/AppSymbol";
2
+
3
+/** Outbox state is independent of the agent's status, so both stay visible. */
4
+export function QueuedMessageIcon({ selected = false }: { readonly selected?: boolean }) {
5
+ return (
6
+ <SymbolView
7
+ name="tray.and.arrow.up"
8
+ size={12}
9
+ tintColorClassName={
10
+ selected ? "accent-user-bubble-foreground-muted" : "accent-foreground-muted"
11
+ }
12
+ type="monochrome"
13
+ />
14
+ );
15
+}
apps/mobile/src/features/threads/thread-list-items.tsx
+12
-1
@@ -27,6 +27,7 @@ import { useThreadPr, type ThreadPrPresentation } from "../../state/use-thread-p
27
import type { HomeGroupDisplayAction } from "../home/homeListItems";
28
import { ThreadSwipeable } from "../home/thread-swipe-actions";
29
import { buildThreadTitleRegenerationMenuItems } from "./thread-title-regeneration-menu";
30
+import { QueuedMessageIcon } from "./queued-message-icon";
31
import { resolveThreadStatus } from "./threadPresentation";
32
import { ThreadSearchMatchExcerpt } from "./thread-search-match";
33
@@ -440,6 +441,8 @@ export const ThreadListRow = memo(function ThreadListRow(props: {
441
readonly thread: EnvironmentThreadShell;
442
readonly environmentLabel: string | null;
443
readonly environmentMachine?: EnvironmentMachineKind;
444
+ /** A message for this thread is waiting in the outbox. */
445
+ readonly hasQueuedMessages?: boolean;
446
readonly searchMatch?: EnvironmentThreadSearchMatch;
447
readonly searchQuery?: string;
448
readonly isLast: boolean;
@@ -480,7 +483,13 @@ export const ThreadListRow = memo(function ThreadListRow(props: {
483
const timestamp = relativeTime(
484
thread.latestUserMessageAt ?? thread.updatedAt ?? thread.createdAt,
485
);
483
- const threadAccessibilityLabel = pr ? `${thread.title}, ${pr.accessibilityLabel}` : thread.title;
486
+ const threadAccessibilityLabel = [
487
+ thread.title,
488
+ pr?.accessibilityLabel,
489
+ props.hasQueuedMessages ? "messages queued to send" : null,
490
+ ]
491
+ .filter(Boolean)
492
+ .join(", ");
493
const subtitleParts = [props.environmentLabel, thread.branch].filter((part): part is string =>
494
Boolean(part),
495
);
@@ -611,6 +620,7 @@ export const ThreadListRow = memo(function ThreadListRow(props: {
620
{thread.title}
621
</Text>
622
<View className="flex-row items-center gap-2">
623
+ {props.hasQueuedMessages ? <QueuedMessageIcon selected={selected} /> : null}
624
{statusPill}
625
<Text className="text-base tabular-nums text-foreground-tertiary">{timestamp}</Text>
626
<SymbolView
@@ -670,6 +680,7 @@ export const ThreadListRow = memo(function ThreadListRow(props: {
680
{thread.title}
681
</Text>
682
<View className="flex-row items-center gap-2">
683
+ {props.hasQueuedMessages ? <QueuedMessageIcon selected={selected} /> : null}
684
{statusPill}
685
<Text
686
className={cn(
apps/mobile/src/features/threads/thread-list-v2-items.tsx
+11
-2
@@ -31,6 +31,7 @@ import {
31
resolveThreadListV2SwipeActions,
32
type ThreadListV2Status,
33
} from "./threadListV2";
34
+import { QueuedMessageIcon } from "./queued-message-icon";
35
import { ThreadSearchMatchExcerpt } from "./thread-search-match";
36
37
/**
@@ -334,6 +335,8 @@ export const ThreadListV2PendingRow = memo(function ThreadListV2PendingRow(props
335
export const ThreadListV2Row = memo(function ThreadListV2Row(props: {
336
readonly thread: EnvironmentThreadShell;
337
readonly variant: "card" | "slim";
338
+ /** A message for this thread is waiting in the outbox. */
339
+ readonly hasQueuedMessages?: boolean;
340
/** Snoozed-shelf row: shows its wake time and offers Wake. */
341
readonly snoozed?: boolean;
342
/** Pinned-block row: shows the pin glyph and offers Unpin. */
@@ -709,6 +712,7 @@ export const ThreadListV2Row = memo(function ThreadListV2Row(props: {
712
>
713
{props.projectTitle ?? props.project?.title ?? ""}
714
</Text>
715
+ {props.hasQueuedMessages ? <QueuedMessageIcon selected={selected} /> : null}
716
{pinnedRow ? (
717
<SymbolView
718
name="pin"
@@ -830,7 +834,9 @@ export const ThreadListV2Row = memo(function ThreadListV2Row(props: {
834
variant === "card" ? (
835
<Pressable
836
accessibilityHint={swipeAccessibilityHint}
833
- accessibilityLabel={thread.title}
837
+ accessibilityLabel={
838
+ props.hasQueuedMessages ? `${thread.title}, messages queued to send` : thread.title
839
+ }
840
accessibilityRole="button"
841
accessibilityState={{ selected }}
842
onPress={() => {
@@ -870,7 +876,9 @@ export const ThreadListV2Row = memo(function ThreadListV2Row(props: {
876
) : (
877
<Pressable
878
accessibilityHint={swipeAccessibilityHint}
873
- accessibilityLabel={thread.title}
879
+ accessibilityLabel={
880
+ props.hasQueuedMessages ? `${thread.title}, messages queued to send` : thread.title
881
+ }
882
accessibilityRole="button"
883
accessibilityState={{ selected }}
884
className={sidebarPane ? undefined : "bg-screen"}
@@ -927,6 +935,7 @@ export const ThreadListV2Row = memo(function ThreadListV2Row(props: {
935
/>
936
) : null}
937
</View>
938
+ {props.hasQueuedMessages ? <QueuedMessageIcon selected={selected} /> : null}
939
<Text
940
className={cn(
941
"text-sm tabular-nums",
apps/mobile/src/features/threads/threadListV2.test.ts
+42
@@ -166,6 +166,48 @@ describe("resolveThreadListV2Status", () => {
166
});
167
});
168
169
+describe("queued messages keep a settled thread active", () => {
170
+ const threads = [
171
+ makeThread({ id: ThreadId.make("active"), title: "Active" }),
172
+ makeThread({ id: ThreadId.make("settled"), title: "Settled", settledOverride: "settled" }),
173
+ makeThread({
174
+ id: ThreadId.make("settled-queued"),
175
+ title: "Settled with outbox",
176
+ settledOverride: "settled",
177
+ }),
178
+ ];
179
+ const queuedThreadKeys = new Set([`${environmentId}:settled-queued`]);
180
+
181
+ it("lists the thread in the active block instead of the settled shelf", () => {
182
+ const layout = buildThreadListV2Items({
183
+ threads,
184
+ environmentId: null,
185
+ searchQuery: "",
186
+ now: NOW,
187
+ queuedThreadKeys,
188
+ });
189
+ expect(layout.items.map((item) => [item.thread.id, item.variant] as const)).toEqual([
190
+ ["active", "card"],
191
+ ["settled-queued", "card"],
192
+ ["settled", "slim"],
193
+ ]);
194
+ expect(layout.settledCount).toBe(1);
195
+ });
196
+
197
+ it("includes it in the reorderable active section", () => {
198
+ expect(
199
+ getThreadListV2OrderedSection({ threads, section: "active", now: NOW, queuedThreadKeys }).map(
200
+ (thread) => thread.id,
201
+ ),
202
+ ).toEqual(["active", "settled-queued"]);
203
+ expect(
204
+ getThreadListV2OrderedSection({ threads, section: "active", now: NOW }).map(
205
+ (thread) => thread.id,
206
+ ),
207
+ ).toEqual(["active"]);
208
+ });
209
+});
210
+
211
describe("resolveThreadListV2SwipeActions", () => {
212
it("offers settle and snooze for an active snoozable thread", () => {
213
expect(
apps/mobile/src/features/threads/threadListV2.ts
+10
-2
@@ -178,12 +178,14 @@ export function getThreadListV2OrderedSection(input: {
178
readonly now: string;
179
readonly settlementEnvironmentIds?: ReadonlySet<EnvironmentId>;
180
readonly snoozeEnvironmentIds?: ReadonlySet<EnvironmentId>;
181
+ readonly queuedThreadKeys?: ReadonlySet<string>;
182
}): EnvironmentThreadShell[] {
183
const threads = input.threads.filter((thread) => {
184
if (thread.archivedAt !== null) return false;
185
if (
186
(input.settlementEnvironmentIds?.has(thread.environmentId) ?? true) &&
186
- thread.settledOverride === "settled"
187
+ thread.settledOverride === "settled" &&
188
+ input.queuedThreadKeys?.has(`${thread.environmentId}:${thread.id}`) !== true
189
) {
190
return false;
191
}
@@ -362,6 +364,10 @@ export function buildThreadListV2Items(input: {
364
/** The selected thread remains visible on an otherwise collapsed shelf so
365
a split-view detail can never lose its navigation row. */
366
readonly selectedThreadKey?: string | null;
367
+ /** Thread keys (`environmentId:threadId`) with a message waiting in the
368
+ outbox. Such a thread has work the user is waiting on, so it stays in
369
+ the active block even when the server has settled it. */
370
+ readonly queuedThreadKeys?: ReadonlySet<string>;
371
}): ThreadListV2Layout {
372
const now = input.now;
373
const pending =
@@ -417,7 +423,9 @@ export function buildThreadListV2Items(input: {
423
}
424
continue;
425
}
420
- if (supportsSettlement && thread.settledOverride === "settled") {
426
+ const hasQueuedMessages =
427
+ input.queuedThreadKeys?.has(`${thread.environmentId}:${thread.id}`) === true;
428
+ if (supportsSettlement && thread.settledOverride === "settled" && !hasQueuedMessages) {
429
settled.push(thread);
430
} else if (thread.pinnedAt != null) {
431
pinned.push(thread);
apps/mobile/src/state/thread-order.test.ts
+4
@@ -24,6 +24,10 @@ vi.mock("./server", async () => {
24
const { Atom } = await import("effect/unstable/reactivity");
25
return { environmentServerConfigsAtom: Atom.make(new Map()).pipe(Atom.keepAlive) };
26
});
27
+vi.mock("./use-thread-outbox", async () => {
28
+ const { Atom } = await import("effect/unstable/reactivity");
29
+ return { queuedThreadKeysAtom: Atom.make(new Set<string>()).pipe(Atom.keepAlive) };
30
+});
31
32
// The mocked shell source is writable so tests can deliver canonical upserts.
33
const shellsAtom = environmentThreadShells.threadShellsAtom as Atom.Writable<
apps/mobile/src/state/thread-order.ts
+3
@@ -10,6 +10,7 @@ import { getThreadListV2OrderedSection } from "../features/threads/threadListV2"
10
import { appAtomRegistry } from "./atom-registry";
11
import { environmentServerConfigsAtom } from "./server";
12
import { environmentThreadShells } from "./threads";
13
+import { queuedThreadKeysAtom } from "./use-thread-outbox";
14
15
export const pendingThreadOrderAtom = Atom.make<PendingThreadOrder | null>(null).pipe(
16
Atom.keepAlive,
@@ -50,6 +51,7 @@ export function beginPendingThreadOrder(pending: PendingThreadOrder) {
51
threads: appAtomRegistry.get(environmentThreadShells.threadShellsAtom),
52
section: current.section,
53
now: new Date().toISOString(),
54
+ queuedThreadKeys: appAtomRegistry.get(queuedThreadKeysAtom),
55
settlementEnvironmentIds: new Set(
56
[...configs].flatMap(([id, config]) =>
57
config.environment.capabilities.threadSettlement === true ? [id] : [],
@@ -70,6 +72,7 @@ export function beginPendingThreadOrder(pending: PendingThreadOrder) {
72
unsubscribers.push(
73
appAtomRegistry.subscribe(environmentThreadShells.threadShellsAtom, refresh),
74
appAtomRegistry.subscribe(environmentServerConfigsAtom, refresh),
75
+ appAtomRegistry.subscribe(queuedThreadKeysAtom, refresh),
76
);
77
return {
78
isPending: () => {
apps/mobile/src/state/use-thread-outbox.ts
+22
@@ -58,6 +58,28 @@ export function useThreadOutboxMessages() {
58
return useAtomValue(threadOutboxManager.queuedMessagesByThreadKeyAtom);
59
}
60
61
+/**
62
+ * Thread keys (`environmentId:threadId`) of existing threads with a message
63
+ * waiting in the outbox. Creations are excluded: they have no thread row yet
64
+ * and surface as pending tasks instead. Derived once so list builders and
65
+ * reorder planners agree on which settled threads are pulled back to active.
66
+ */
67
+export const queuedThreadKeysAtom = Atom.make((get): ReadonlySet<string> => {
68
+ const keys = new Set<string>();
69
+ for (const [threadKey, queue] of Object.entries(
70
+ get(threadOutboxManager.queuedMessagesByThreadKeyAtom),
71
+ )) {
72
+ if (queue.some((message) => message.creation === undefined)) {
73
+ keys.add(threadKey);
74
+ }
75
+ }
76
+ return keys;
77
+}).pipe(Atom.withLabel("mobile:thread-outbox:queued-thread-keys"));
78
+
79
+export function useQueuedThreadKeys(): ReadonlySet<string> {
80
+ return useAtomValue(queuedThreadKeysAtom);
81
+}
82
+
83
export function useThreadOutboxShellStatuses() {
84
return useAtomValue(threadOutboxShellStatusesAtom);
85
}