Skip to content

Commit 194d18d

Browse files
github-actions[bot]saphid
authored andcommitted
fix(client): show reconnecting instead of stale working status
1 parent dac8b11 commit 194d18d

14 files changed

Lines changed: 418 additions & 46 deletions

File tree

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

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,24 @@ interface StatusLabel {
8787
readonly iconTintClassName: string;
8888
}
8989
const STATUS_LABEL_BY_STATUS: Partial<Record<ThreadListV2Status, StatusLabel>> = {
90+
connecting: {
91+
label: "Connecting",
92+
icon: "wifi.slash",
93+
className: "text-foreground-muted",
94+
iconTintClassName: "accent-foreground-muted",
95+
},
96+
reconnecting: {
97+
label: "Reconnecting",
98+
icon: "wifi.slash",
99+
className: "text-foreground-muted",
100+
iconTintClassName: "accent-foreground-muted",
101+
},
102+
offline: {
103+
label: "Offline",
104+
icon: "wifi.slash",
105+
className: "text-foreground-muted",
106+
iconTintClassName: "accent-foreground-muted",
107+
},
90108
approval: {
91109
label: "Approval",
92110
icon: "exclamationmark.shield",

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

Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,89 @@ describe("resolveThreadListV2SnoozePresets", () => {
100100
});
101101

102102
describe("resolveThreadListV2Status", () => {
103+
it.each(["preparing", "queued", "starting", "running", "waiting"] as const)(
104+
"qualifies a cached %s runtime while reconnecting",
105+
(status) => {
106+
const thread = presentThreadShell(
107+
environmentId,
108+
makeRawThreadShell({
109+
status,
110+
activeRunId: RunId.make("run-disconnected"),
111+
latestRunId: RunId.make("run-disconnected"),
112+
}),
113+
);
114+
expect(resolveThreadListV2Status({ ...thread, connectionPhase: "reconnecting" })).toBe(
115+
"reconnecting",
116+
);
117+
},
118+
);
119+
120+
it.each(["failed", "completed", "cancelled", "interrupted"] as const)(
121+
"preserves a cached %s outcome while disconnected",
122+
(status) => {
123+
const thread = presentThreadShell(
124+
environmentId,
125+
makeRawThreadShell({
126+
status,
127+
latestRunId: RunId.make("run-ended"),
128+
latestRunCompletedAt: DateTime.makeUnsafe(NOW),
129+
lastVisitedAt: DateTime.makeUnsafe("2026-06-01T23:59:00.000Z"),
130+
}),
131+
);
132+
const disconnected = { ...thread, connectionPhase: "reconnecting" as const };
133+
expect(resolveThreadListV2Status(disconnected)).toBe(
134+
status === "failed" ? "failed" : "ready",
135+
);
136+
expect(threadHasUnseenCompletion(disconnected)).toBe(threadHasUnseenCompletion(thread));
137+
},
138+
);
139+
140+
it("does not claim live work while the environment is reconnecting", () => {
141+
const thread = {
142+
...presentThreadShell(
143+
environmentId,
144+
makeRawThreadShell({
145+
status: "running",
146+
activeRunId: RunId.make("run-disconnected"),
147+
latestRunId: RunId.make("run-disconnected"),
148+
}),
149+
),
150+
connectionPhase: "reconnecting" as const,
151+
};
152+
expect(resolveThreadListV2Status(thread)).toBe("reconnecting");
153+
});
154+
155+
it.each([
156+
["connecting", "connecting"],
157+
["reconnecting", "reconnecting"],
158+
["offline", "offline"],
159+
["error", "offline"],
160+
["unsupported", "offline"],
161+
["available", "offline"],
162+
["connected", "working"],
163+
[undefined, "working"],
164+
] as const)(
165+
"presents cached running work with connection phase %s",
166+
(connectionPhase, expected) => {
167+
const thread = makeThread({
168+
id: ThreadId.make("disconnected"),
169+
title: "Disconnected",
170+
runtime: {
171+
status: "running",
172+
activeRunId: RunId.make("run-disconnected"),
173+
providerInstanceId: ProviderInstanceId.make("codex"),
174+
providerName: "Codex",
175+
lastError: null,
176+
updatedAt: NOW,
177+
},
178+
connectionPhase,
179+
});
180+
expect(resolveThreadListV2Status(thread)).toBe(expected);
181+
expect(resolveThreadListV2Status({ ...thread, hasPendingApprovals: true })).toBe("approval");
182+
expect(resolveThreadListV2Status({ ...thread, hasPendingUserInput: true })).toBe("input");
183+
},
184+
);
185+
103186
it("presents decoded thread waits as Waiting while preserving requests and older servers", () => {
104187
const raw = makeRawThreadShell({
105188
status: "running",
@@ -1625,6 +1708,20 @@ describe("Working section beta", () => {
16251708
expect(off.workingCount).toBe(0);
16261709
});
16271710

1711+
it("preserves pins and Working membership across connection loss and recovery", () => {
1712+
const before = build({ workingShelfExpanded: true });
1713+
for (const connectionPhase of ["reconnecting", "offline", "connected"] as const) {
1714+
const layout = build({
1715+
workingShelfExpanded: true,
1716+
threads: threads.map((thread) => ({ ...thread, connectionPhase })),
1717+
});
1718+
expect(ids(layout)).toEqual(ids(before));
1719+
expect(layout.workingCount).toBe(before.workingCount);
1720+
expect(layout.items[0]?.thread.id).toBe("pinned-working");
1721+
expect(layout.items[0]?.thread.runtime?.status).toBe("running");
1722+
}
1723+
});
1724+
16281725
it("keeps an inactive row in Working during the shared grace and returns it on expiry", () => {
16291726
vi.useFakeTimers();
16301727
vi.setSystemTime(new Date(NOW));

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

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,10 @@ import {
1010
} from "@t3tools/client-runtime/state/thread-settled";
1111
import type { SnoozePreset } from "@t3tools/client-runtime/state/thread-settled";
1212
import type { EnvironmentThreadShell } from "@t3tools/client-runtime/state/shell";
13-
import { resolveThreadProviderStack } from "@t3tools/client-runtime/state/models";
13+
import {
14+
resolveThreadConnectionStatus,
15+
resolveThreadProviderStack,
16+
} from "@t3tools/client-runtime/state/models";
1417
import {
1518
threadSearchMatchKey,
1619
threadSearchSubject,
@@ -62,6 +65,9 @@ export function resolveThreadListV2ProviderDrivers(
6265
}
6366

6467
export type ThreadListV2Status =
68+
| "connecting"
69+
| "reconnecting"
70+
| "offline"
6571
| "approval"
6672
| "input"
6773
| "request"
@@ -207,6 +213,8 @@ export function resolveThreadListV2Status(
207213
| "pendingGuestMessageCount"
208214
| "runtime"
209215
| "blockedOnThreadWait"
216+
| "connectionPhase"
217+
| "pendingBackgroundTasks"
210218
>,
211219
): ThreadListV2Status {
212220
if (thread.hasPendingApprovals || thread.pendingSubagentRequest === "approval") {
@@ -219,6 +227,8 @@ export function resolveThreadListV2Status(
219227
if ((thread.pendingGuestMessageCount ?? 0) > 0) {
220228
return "request";
221229
}
230+
const connectionStatus = resolveThreadConnectionStatus(thread);
231+
if (connectionStatus !== null) return connectionStatus;
222232
if (thread.runtime?.status === "running" && thread.blockedOnThreadWait === true) {
223233
return "waiting";
224234
}

‎apps/mobile/src/state/threads.ts‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import {
2222
selectThreadCreationDetail,
2323
} from "./pending-thread-creation";
2424
import { environmentShell } from "./shell";
25+
import { environmentPresentations } from "./presentation";
2526
import { threadOutboxManager } from "./thread-outbox";
2627

2728
export const threadFamilies = createThreadFamilyAtoms(
@@ -42,6 +43,7 @@ export const environmentThreadDetails = createEnvironmentThreadDetailAtoms(
4243
);
4344
export const environmentThreadShells = createEnvironmentThreadShellAtoms({
4445
catalogValueAtom: environmentCatalog.catalogValueAtom,
46+
connectionPhaseAtom: environmentPresentations.connectionPhaseAtom,
4547
snapshotAtom: threadEnvironment.snapshotAtom,
4648
});
4749

‎apps/mobile/src/state/use-composer-drafts.test.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -312,6 +312,7 @@ function modelReconciliationHarness(
312312
});
313313
const shells = createEnvironmentThreadShellAtoms({
314314
catalogValueAtom,
315+
connectionPhaseAtom: () => Atom.make("connected" as const),
315316
snapshotAtom: () => snapshotAtom,
316317
});
317318
const selectedShell = shells.threadShellAtom({ environmentId, threadId: selectedThreadId });

‎apps/web/src/components/Sidebar.logic.test.ts‎

Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -442,6 +442,94 @@ describe("resolveThreadStatusPill", () => {
442442
},
443443
};
444444

445+
it("does not claim live work while the environment is reconnecting", () => {
446+
const thread = { ...baseThread, connectionPhase: "reconnecting" as const };
447+
expect(resolveSidebarThreadStatus(thread)).toBe("reconnecting");
448+
expect(resolveThreadStatusPill({ thread })).toMatchObject({
449+
label: "Reconnecting",
450+
pulse: false,
451+
});
452+
});
453+
454+
it.each([
455+
["connecting", "connecting", "Connecting"],
456+
["reconnecting", "reconnecting", "Reconnecting"],
457+
["offline", "offline", "Offline"],
458+
["error", "offline", "Offline"],
459+
["unsupported", "offline", "Offline"],
460+
["available", "offline", "Offline"],
461+
["connected", "working", "Working"],
462+
[undefined, "working", "Working"],
463+
] as const)(
464+
"presents cached running work with connection phase %s",
465+
(connectionPhase, status, label) => {
466+
const thread = { ...baseThread, connectionPhase };
467+
expect(resolveSidebarThreadStatus(thread)).toBe(status);
468+
expect(resolveThreadStatusPill({ thread })).toMatchObject({
469+
label,
470+
pulse: status === "working",
471+
});
472+
expect(thread.runtime.status).toBe("running");
473+
},
474+
);
475+
476+
it("keeps cached requests and terminal outcomes when the connection is lost", () => {
477+
const thread = { ...baseThread, connectionPhase: "reconnecting" as const };
478+
expect(
479+
resolveThreadStatusPill({ thread: { ...thread, hasPendingApprovals: true } })?.label,
480+
).toBe("Pending Approval");
481+
expect(
482+
resolveThreadStatusPill({ thread: { ...thread, hasPendingUserInput: true } })?.label,
483+
).toBe("Awaiting Input");
484+
for (const status of ["failed", "completed", "cancelled", "interrupted", "idle"] as const) {
485+
const online = {
486+
...baseThread,
487+
runtime: { ...baseThread.runtime, status, activeRunId: null },
488+
};
489+
const disconnected = { ...online, connectionPhase: "reconnecting" as const };
490+
expect(resolveSidebarThreadStatus(disconnected)).toBe(resolveSidebarThreadStatus(online));
491+
expect(resolveThreadStatusPill({ thread: disconnected })).toEqual(
492+
resolveThreadStatusPill({ thread: online }),
493+
);
494+
}
495+
});
496+
497+
it.each(["preparing", "queued", "starting", "running", "waiting"] as const)(
498+
"qualifies a cached %s runtime while reconnecting",
499+
(status) => {
500+
const thread = {
501+
...baseThread,
502+
connectionPhase: "reconnecting" as const,
503+
runtime: { ...baseThread.runtime, status },
504+
};
505+
expect(resolveSidebarThreadStatus(thread)).toBe("reconnecting");
506+
expect(resolveThreadStatusPill({ thread })?.label).toBe("Reconnecting");
507+
},
508+
);
509+
510+
it.each(["failed", "completed"] as const)(
511+
"preserves an unseen %s outcome while disconnected",
512+
(status) => {
513+
const thread = {
514+
...baseThread,
515+
connectionPhase: "reconnecting" as const,
516+
runtime: { ...baseThread.runtime, status, activeRunId: null },
517+
lastVisitedAt: "2026-03-09T09:00:00.000Z",
518+
latestRun: {
519+
runId: RunId.make("run-ended"),
520+
status,
521+
requestedAt: "2026-03-09T09:30:00.000Z",
522+
startedAt: "2026-03-09T09:30:00.000Z",
523+
completedAt: "2026-03-09T10:00:00.000Z",
524+
assistantMessageId: null,
525+
},
526+
};
527+
expect(resolveThreadStatusPill({ thread })?.label).toBe(
528+
status === "failed" ? "Failed" : "Completed",
529+
);
530+
},
531+
);
532+
445533
it("shows an active thread wait without a pulse and resumes Working when it ends", () => {
446534
const blocked = { ...baseThread, blockedOnThreadWait: true };
447535
expect(resolveSidebarThreadStatus(blocked)).toBe("waiting");

‎apps/web/src/components/Sidebar.logic.ts‎

Lines changed: 33 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
1-
import { resolveThreadWorkingStartedAt } from "@t3tools/client-runtime/state/models";
1+
import {
2+
resolveThreadConnectionStatus,
3+
resolveThreadWorkingStartedAt,
4+
} from "@t3tools/client-runtime/state/models";
25
import { isShownUnderParent } from "@t3tools/client-runtime/state/threads";
36
import { backgroundWorkHoldsCompletion } from "@t3tools/shared/orchestrationV2PendingBackgroundWork";
47
import { threadPullRequestSearchTerms } from "@t3tools/shared/threadPullRequests";
@@ -620,6 +623,8 @@ export interface ThreadStatusPill {
620623
label:
621624
| "Working"
622625
| "Connecting"
626+
| "Reconnecting"
627+
| "Offline"
623628
| "Completed"
624629
| "Failed"
625630
| "Pending Approval"
@@ -639,6 +644,8 @@ const THREAD_STATUS_PRIORITY: Record<ThreadStatusPill["label"], number> = {
639644
Failed: 3.5,
640645
Working: 3,
641646
Connecting: 3,
647+
Reconnecting: 3,
648+
Offline: 3,
642649
Waiting: 2.5,
643650
"Plan Ready": 2,
644651
Completed: 1,
@@ -654,6 +661,7 @@ type ThreadStatusInput = Pick<
654661
| "interactionMode"
655662
| "latestRun"
656663
| "runtime"
664+
| "connectionPhase"
657665
> & {
658666
lastVisitedAt?: string | null | undefined;
659667
pendingBackgroundTasks?: SidebarThreadSummary["pendingBackgroundTasks"] | undefined;
@@ -802,6 +810,9 @@ export function resolveAdjacentThreadId<T>(input: {
802810
}
803811

804812
export type SidebarThreadStatus =
813+
| "connecting"
814+
| "reconnecting"
815+
| "offline"
805816
| "approval"
806817
| "input"
807818
| "request"
@@ -841,7 +852,10 @@ type SidebarThreadStatusInput = Pick<
841852
| "pendingGuestMessageCount"
842853
| "runtime"
843854
| "blockedOnThreadWait"
844-
>;
855+
| "connectionPhase"
856+
> & {
857+
readonly pendingBackgroundTasks?: SidebarThreadSummary["pendingBackgroundTasks"];
858+
};
845859

846860
export function resolveSidebarThreadStatus(thread: SidebarThreadStatusInput): SidebarThreadStatus {
847861
if (thread.hasPendingApprovals || thread.pendingSubagentRequest === "approval") {
@@ -854,6 +868,8 @@ export function resolveSidebarThreadStatus(thread: SidebarThreadStatusInput): Si
854868
if ((thread.pendingGuestMessageCount ?? 0) > 0) {
855869
return "request";
856870
}
871+
const connectionStatus = resolveThreadConnectionStatus(thread);
872+
if (connectionStatus !== null) return connectionStatus;
857873
if (thread.runtime?.status === "running" && thread.blockedOnThreadWait === true) {
858874
return "waiting";
859875
}
@@ -1102,6 +1118,21 @@ export function resolveThreadStatusPill(input: {
11021118
};
11031119
}
11041120

1121+
const connectionStatus = resolveThreadConnectionStatus(thread);
1122+
if (connectionStatus !== null) {
1123+
return {
1124+
label:
1125+
connectionStatus === "connecting"
1126+
? "Connecting"
1127+
: connectionStatus === "reconnecting"
1128+
? "Reconnecting"
1129+
: "Offline",
1130+
colorClass: "text-sidebar-muted-foreground",
1131+
dotClass: "bg-sidebar-muted-foreground",
1132+
pulse: false,
1133+
};
1134+
}
1135+
11051136
if (
11061137
(thread.runtime?.status === "running" && thread.blockedOnThreadWait !== true) ||
11071138
thread.runtime?.status === "waiting"

0 commit comments

Comments
 (0)