Skip to content

Commit 6a13192

Browse files
saphidclaude
andcommitted
fix(mobile): threads on an unreachable environment no longer hide as Working
The thread list trusted each thread's last cached run state. When an environment stopped answering, its running threads kept a ticking "Working" label and stayed folded into the collapsed Working shelf, so a broken thread was invisible. Past a first connection attempt, a thread's environment counts as disconnected (the same rule thread-route hydration uses). Its Working or Waiting status shows as "Disconnected", and it is listed in the inbox rather than the Working shelf until the environment reconnects. Co-Authored-By: Claude Opus 5.5 <[email protected]>
1 parent 36d4d71 commit 6a13192

6 files changed

Lines changed: 118 additions & 3 deletions

File tree

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -565,6 +565,7 @@ export function HomeScreen(props: HomeScreenProps) {
565565
snoozed={item.item.snoozed}
566566
pinned={item.item.pinned}
567567
wokeAt={item.item.wokeAt}
568+
disconnected={item.item.disconnected}
568569
snoozePresetMinute={item.snoozePresetMinute ?? ""}
569570
snoozeWakeLabelText={item.snoozeWakeLabelText}
570571
timeLabel={item.timeLabel}

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -542,6 +542,7 @@ function ThreadNavigationSidebarPane(
542542
snoozed={item.item.snoozed}
543543
pinned={item.item.pinned}
544544
wokeAt={item.item.wokeAt}
545+
disconnected={item.item.disconnected}
545546
snoozePresetMinute={item.snoozePresetMinute ?? ""}
546547
snoozeWakeLabelText={item.snoozeWakeLabelText}
547548
timeLabel={item.timeLabel}

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

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,12 @@ const STATUS_LABEL_BY_STATUS: Partial<Record<ThreadListV2Status, StatusLabel>> =
125125
className: "text-warning-foreground",
126126
iconTintClassName: "accent-warning-foreground",
127127
},
128+
disconnected: {
129+
label: "Disconnected",
130+
icon: "wifi.slash",
131+
className: "text-warning-foreground",
132+
iconTintClassName: "accent-warning-foreground",
133+
},
128134
};
129135
const DONE_STATUS_LABEL: StatusLabel = {
130136
label: "Done",
@@ -577,6 +583,7 @@ export const ThreadListV2Row = memo(function ThreadListV2Row(props: {
577583
readonly snoozed?: boolean;
578584
readonly pinned?: boolean;
579585
readonly wokeAt: string | null;
586+
readonly disconnected?: boolean;
580587
readonly snoozeWakeLabelText?: string;
581588
readonly timeLabel: string;
582589
readonly snoozePresetMinute: string;
@@ -679,7 +686,7 @@ export const ThreadListV2Row = memo(function ThreadListV2Row(props: {
679686
const selected = props.selected === true;
680687
const rowAppearance = getThreadListV2RowAppearance(theme, sidebarPane, selected);
681688

682-
const status = resolveThreadListV2Status(thread);
689+
const status = resolveThreadListV2Status(thread, { disconnected: props.disconnected === true });
683690
const isUnread = status === "ready" && threadHasUnseenCompletion(thread);
684691
const workingLabel = STATUS_LABEL_BY_STATUS[status];
685692
const showsWoke = status === "ready" && props.wokeAt !== null;

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

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ import {
3434
buildThreadListV2Items,
3535
buildThreadListV2ListItems,
3636
getThreadListV2OrderedSection,
37+
isThreadListV2EnvironmentDisconnected,
3738
resolveThreadListV2SnoozeMenuSelection,
3839
resolveThreadListV2Status,
3940
resolveThreadListV2WokeAt,
@@ -135,6 +136,41 @@ describe("resolveThreadListV2Status", () => {
135136
expect(threadHasUnseenCompletion(thread)).toBe(true);
136137
},
137138
);
139+
140+
it("does not claim live progress for a thread on a disconnected environment", () => {
141+
const raw = makeRawThreadShell({
142+
status: "running",
143+
activeRunId: RunId.make("run-live"),
144+
latestRunId: RunId.make("run-live"),
145+
});
146+
const running = presentThreadShell(environmentId, decodeThreadShell(raw));
147+
const blocked = presentThreadShell(
148+
environmentId,
149+
decodeThreadShell({ ...raw, blockedOnThreadWait: true }),
150+
);
151+
const disconnected = { disconnected: true };
152+
153+
expect(resolveThreadListV2Status(running, disconnected)).toBe("disconnected");
154+
expect(resolveThreadListV2Status(blocked, disconnected)).toBe("disconnected");
155+
expect(resolveThreadListV2Status({ ...running, hasPendingApprovals: true }, disconnected)).toBe(
156+
"approval",
157+
);
158+
expect(resolveThreadListV2Status(running, { disconnected: false })).toBe("working");
159+
});
160+
});
161+
162+
describe("isThreadListV2EnvironmentDisconnected", () => {
163+
it.each([
164+
["connected", false],
165+
["connecting", false],
166+
["reconnecting", true],
167+
["offline", true],
168+
["error", true],
169+
["unsupported", true],
170+
["available", true],
171+
] as const)("treats %s as disconnected: %s", (connectionState, disconnected) => {
172+
expect(isThreadListV2EnvironmentDisconnected(connectionState)).toBe(disconnected);
173+
});
138174
});
139175

140176
describe("queued messages keep a settled thread active", () => {
@@ -1631,6 +1667,27 @@ describe("Working section beta", () => {
16311667
}
16321668
});
16331669

1670+
it("lists a working thread on a disconnected environment outside the shelf", () => {
1671+
const unreachableId = EnvironmentId.make("environment-unreachable");
1672+
const unreachable = makeThreadShellFixture({
1673+
environmentId: unreachableId,
1674+
id: ThreadId.make("unreachable"),
1675+
title: "unreachable",
1676+
runtime: running,
1677+
});
1678+
const layout = build({
1679+
threads: [...threads, unreachable],
1680+
disconnectedEnvironmentIds: new Set([unreachableId]),
1681+
});
1682+
1683+
expect(ids(layout)).toContain("unreachable");
1684+
expect(layout.workingCount).toBe(1);
1685+
expect(layout.items.find((item) => item.thread.id === "unreachable")?.disconnected).toBe(true);
1686+
expect(layout.items.find((item) => item.thread.id === "pinned-working")?.disconnected).toBe(
1687+
false,
1688+
);
1689+
});
1690+
16341691
it("orders the inbox by the latest return this device observed", () => {
16351692
const layout = build({
16361693
inboxReturnAt: (thread) =>

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

Lines changed: 41 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ import {
2727
sortPinnedThreadsByOrderKey,
2828
sortSettledThreads,
2929
} from "@t3tools/client-runtime/state/thread-sort";
30+
import type { EnvironmentConnectionPhase } from "@t3tools/client-runtime/connection";
3031
import type { EnvironmentId, ProjectId } from "@t3tools/contracts";
3132

3233
import type { ThreadListProvider } from "../../state/thread-list-environments";
@@ -69,6 +70,7 @@ export type ThreadListV2Status =
6970
| "waiting"
7071
| "failed"
7172
| "limited"
73+
| "disconnected"
7274
| "ready";
7375
export type ThreadListV2SwipeAction = "archive" | "settle" | "unsettle" | "snooze" | "unsnooze";
7476

@@ -184,6 +186,16 @@ export function resolveThreadListV2WokeAt(
184186
: null;
185187
}
186188

189+
/**
190+
* Past a first connection attempt the environment is not answering, so its threads' last run
191+
* states are stale. Matches `threadRouteIsHydrating`.
192+
*/
193+
export function isThreadListV2EnvironmentDisconnected(
194+
connectionState: EnvironmentConnectionPhase,
195+
): boolean {
196+
return connectionState !== "connected" && connectionState !== "connecting";
197+
}
198+
187199
export function resolveThreadListV2Status(
188200
thread: Pick<
189201
EnvironmentThreadShell,
@@ -194,6 +206,16 @@ export function resolveThreadListV2Status(
194206
| "runtime"
195207
| "blockedOnThreadWait"
196208
>,
209+
options?: { readonly disconnected?: boolean },
210+
): ThreadListV2Status {
211+
const status = resolveConnectedThreadListV2Status(thread);
212+
return options?.disconnected === true && (status === "working" || status === "waiting")
213+
? "disconnected"
214+
: status;
215+
}
216+
217+
function resolveConnectedThreadListV2Status(
218+
thread: Parameters<typeof resolveThreadListV2Status>[0],
197219
): ThreadListV2Status {
198220
if (thread.hasPendingApprovals || thread.pendingSubagentRequest === "approval") {
199221
return "approval";
@@ -285,6 +307,8 @@ export interface ThreadListV2Item {
285307
readonly snoozed: boolean;
286308
readonly pinned: boolean;
287309
readonly wokeAt: string | null;
310+
/** Its environment stopped answering, so its last known run state is stale. */
311+
readonly disconnected: boolean;
288312
readonly isLast: boolean;
289313
}
290314

@@ -386,6 +410,7 @@ export function threadListV2ListItemsAreEqual(
386410
previous.item.snoozed === item.item.snoozed &&
387411
previous.item.pinned === item.item.pinned &&
388412
previous.item.wokeAt === item.item.wokeAt &&
413+
previous.item.disconnected === item.item.disconnected &&
389414
previous.snoozeWakeLabelText === item.snoozeWakeLabelText &&
390415
previous.timeLabel === item.timeLabel &&
391416
previous.snoozePresetMinute === item.snoozePresetMinute &&
@@ -434,7 +459,7 @@ function resolveThreadListV2ItemTimeLabel(
434459
if (showSnoozeWakeLabel) return "";
435460
if (
436461
variant === "card" &&
437-
(resolveThreadListV2Status(thread) !== "ready" ||
462+
(resolveThreadListV2Status(thread, { disconnected: item.disconnected }) !== "ready" ||
438463
item.wokeAt !== null ||
439464
threadHasUnseenCompletion(thread))
440465
)
@@ -589,6 +614,7 @@ export function buildThreadListV2Items(input: {
589614
readonly matchedThreadKeys?: ReadonlySet<string>;
590615
readonly settlementEnvironmentIds?: ReadonlySet<EnvironmentId>;
591616
readonly snoozeEnvironmentIds?: ReadonlySet<EnvironmentId>;
617+
readonly disconnectedEnvironmentIds?: ReadonlySet<string>;
592618
readonly settledLimit?: number;
593619
readonly now: string;
594620
readonly workingShelfEnabled?: boolean;
@@ -630,6 +656,8 @@ export function buildThreadListV2Items(input: {
630656
const snoozed: EnvironmentThreadShell[] = [];
631657
let nextSnoozeWakeAt: string | null = null;
632658
const queuedThreadKeys = input.queuedThreadKeys?.size ? input.queuedThreadKeys : undefined;
659+
const isDisconnected = (thread: EnvironmentThreadShell) =>
660+
input.disconnectedEnvironmentIds?.has(thread.environmentId) === true;
633661
const listedThreads = input.threads.filter(
634662
(thread) =>
635663
thread.archivedAt === null &&
@@ -680,7 +708,12 @@ export function buildThreadListV2Items(input: {
680708
settled.push(thread);
681709
} else if (thread.pinnedAt != null) {
682710
pinned.push(thread);
683-
} else if (workingShelfEnabled && (input.isWorking ?? isThreadWorking)(thread)) {
711+
} else if (
712+
workingShelfEnabled &&
713+
// A shelf the user collapsed must not hide a thread whose progress is unknown.
714+
!isDisconnected(thread) &&
715+
(input.isWorking ?? isThreadWorking)(thread)
716+
) {
684717
working.push(thread);
685718
} else {
686719
active.push(thread);
@@ -712,6 +745,7 @@ export function buildThreadListV2Items(input: {
712745
snoozed: snoozedThreads.has(thread),
713746
pinned: pinnedThreads.has(thread),
714747
wokeAt: slim.has(thread) ? null : resolveThreadListV2WokeAt(thread, { now }),
748+
disconnected: isDisconnected(thread),
715749
isLast: index === results.length - 1,
716750
})),
717751
hiddenSettledCount: 0,
@@ -785,6 +819,7 @@ export function buildThreadListV2Items(input: {
785819
snoozed: false,
786820
pinned: true,
787821
wokeAt: resolveThreadListV2WokeAt(thread, { now }),
822+
disconnected: isDisconnected(thread),
788823
isLast: false,
789824
});
790825
}
@@ -795,6 +830,7 @@ export function buildThreadListV2Items(input: {
795830
snoozed: false,
796831
pinned: false,
797832
wokeAt: resolveThreadListV2WokeAt(thread, { now }),
833+
disconnected: isDisconnected(thread),
798834
isLast: false,
799835
});
800836
}
@@ -806,6 +842,7 @@ export function buildThreadListV2Items(input: {
806842
snoozed: false,
807843
pinned: false,
808844
wokeAt: resolveThreadListV2WokeAt(thread, { now }),
845+
disconnected: isDisconnected(thread),
809846
isLast: false,
810847
});
811848
}
@@ -817,6 +854,7 @@ export function buildThreadListV2Items(input: {
817854
snoozed: true,
818855
pinned: false,
819856
wokeAt: null,
857+
disconnected: isDisconnected(thread),
820858
isLast: false,
821859
});
822860
}
@@ -828,6 +866,7 @@ export function buildThreadListV2Items(input: {
828866
snoozed: false,
829867
pinned: false,
830868
wokeAt: null,
869+
disconnected: isDisconnected(thread),
831870
isLast: false,
832871
});
833872
}

‎apps/mobile/src/features/threads/useThreadListV2.ts‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,12 @@ import { useMemo, useSyncExternalStore } from "react";
55
import { scopedProjectKey } from "../../lib/scopedEntities";
66
import { useOlderSettledShelf, useOlderSettledShelfGrowth } from "../../state/olderSettledShelf";
77
import type { PendingNewTask } from "../../state/use-pending-new-tasks";
8+
import { useWorkspaceEnvironments } from "../../state/workspace";
89
import {
910
buildThreadListV2Items,
1011
buildThreadListV2ListItems,
1112
getThreadListV2OrderedSection,
13+
isThreadListV2EnvironmentDisconnected,
1214
threadListInboxReturns,
1315
} from "./threadListV2";
1416
import { computeThreadMoveAvailability } from "./threadOrder";
@@ -66,6 +68,13 @@ export function useThreadListV2(input: {
6668
// oxlint-disable-next-line react/memo-dependencies -- the version signals an expired grace
6769
[threads, workingShelfEnabled, inboxVersion],
6870
);
71+
const disconnectedEnvironmentIds = useKeySet(
72+
useWorkspaceEnvironments()
73+
.filter((environment) => isThreadListV2EnvironmentDisconnected(environment.connectionState))
74+
.map((environment) => environment.environmentId)
75+
.sort()
76+
.join("\n"),
77+
);
6978
// Up/down menu availability for every card, computed once per section per
7079
// rebuild (see computeThreadMoveAvailability): per-thread planner calls made
7180
// list construction quadratic, and this list rebuilds on every minute tick.
@@ -107,6 +116,7 @@ export function useThreadListV2(input: {
107116
matchedThreadKeys: new Set(input.searchMatches.keys()),
108117
settlementEnvironmentIds: input.settlementEnvironmentIds,
109118
snoozeEnvironmentIds: input.snoozeEnvironmentIds,
119+
disconnectedEnvironmentIds,
110120
queuedThreadKeys: input.queuedThreadKeys,
111121
settledLimit: input.settledLimit,
112122
now: input.now,

0 commit comments

Comments
 (0)