Skip to content

Commit 3a02db0

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

14 files changed

Lines changed: 431 additions & 47 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
@@ -84,6 +84,24 @@ interface StatusLabel {
8484
readonly iconTintClassName: string;
8585
}
8686
const STATUS_LABEL_BY_STATUS: Partial<Record<ThreadListV2Status, StatusLabel>> = {
87+
connecting: {
88+
label: "Connecting",
89+
icon: "wifi.slash",
90+
className: "text-foreground-muted",
91+
iconTintClassName: "accent-foreground-muted",
92+
},
93+
reconnecting: {
94+
label: "Reconnecting",
95+
icon: "wifi.slash",
96+
className: "text-foreground-muted",
97+
iconTintClassName: "accent-foreground-muted",
98+
},
99+
offline: {
100+
label: "Offline",
101+
icon: "wifi.slash",
102+
className: "text-foreground-muted",
103+
iconTintClassName: "accent-foreground-muted",
104+
},
87105
approval: {
88106
label: "Approval",
89107
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
@@ -94,6 +94,89 @@ describe("resolveThreadListV2SnoozePresets", () => {
9494
});
9595

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

1706+
it("preserves pins and Working membership across connection loss and recovery", () => {
1707+
const before = build({ workingShelfExpanded: true });
1708+
for (const connectionPhase of ["reconnecting", "offline", "connected"] as const) {
1709+
const layout = build({
1710+
workingShelfExpanded: true,
1711+
threads: threads.map((thread) => ({ ...thread, connectionPhase })),
1712+
});
1713+
expect(ids(layout)).toEqual(ids(before));
1714+
expect(layout.workingCount).toBe(before.workingCount);
1715+
expect(layout.items[0]?.thread.id).toBe("pinned-working");
1716+
expect(layout.items[0]?.thread.runtime?.status).toBe("running");
1717+
}
1718+
});
1719+
16231720
it("keeps an inactive row in Working during the shared grace and returns it on expiry", () => {
16241721
vi.useFakeTimers();
16251722
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
@@ -9,7 +9,10 @@ import {
99
} from "@t3tools/client-runtime/state/thread-settled";
1010
import type { SnoozePreset } from "@t3tools/client-runtime/state/thread-settled";
1111
import type { EnvironmentThreadShell } from "@t3tools/client-runtime/state/shell";
12-
import { resolveThreadProviderStack } from "@t3tools/client-runtime/state/models";
12+
import {
13+
resolveThreadConnectionStatus,
14+
resolveThreadProviderStack,
15+
} from "@t3tools/client-runtime/state/models";
1316
import {
1417
threadSearchMatchKey,
1518
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"
@@ -205,6 +211,8 @@ export function resolveThreadListV2Status(
205211
| "pendingGuestMessageCount"
206212
| "runtime"
207213
| "blockedOnThreadWait"
214+
| "connectionPhase"
215+
| "pendingBackgroundTasks"
208216
>,
209217
): ThreadListV2Status {
210218
if (thread.hasPendingApprovals || thread.pendingSubagentRequest === "approval") {
@@ -217,6 +225,8 @@ export function resolveThreadListV2Status(
217225
if ((thread.pendingGuestMessageCount ?? 0) > 0) {
218226
return "request";
219227
}
228+
const connectionStatus = resolveThreadConnectionStatus(thread);
229+
if (connectionStatus !== null) return connectionStatus;
220230
if (thread.runtime?.status === "running" && thread.blockedOnThreadWait === true) {
221231
return "waiting";
222232
}

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

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

2829
export const threadFamilies = createThreadFamilyAtoms(
@@ -43,6 +44,7 @@ export const environmentThreadDetails = createEnvironmentThreadDetailAtoms(
4344
);
4445
export const environmentThreadShells = createEnvironmentThreadShellAtoms({
4546
catalogValueAtom: environmentCatalog.catalogValueAtom,
47+
connectionPhaseAtom: environmentPresentations.connectionPhaseAtom,
4648
snapshotAtom: threadEnvironment.snapshotAtom,
4749
});
4850

‎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: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -442,6 +442,95 @@ 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(resolveSidebarV2TopStatus({ status, isUnread: false, isWoke: false })).toBe(status);
473+
expect(thread.runtime.status).toBe("running");
474+
},
475+
);
476+
477+
it("keeps cached requests and terminal outcomes when the connection is lost", () => {
478+
const thread = { ...baseThread, connectionPhase: "reconnecting" as const };
479+
expect(
480+
resolveThreadStatusPill({ thread: { ...thread, hasPendingApprovals: true } })?.label,
481+
).toBe("Pending Approval");
482+
expect(
483+
resolveThreadStatusPill({ thread: { ...thread, hasPendingUserInput: true } })?.label,
484+
).toBe("Awaiting Input");
485+
for (const status of ["failed", "completed", "cancelled", "interrupted", "idle"] as const) {
486+
const online = {
487+
...baseThread,
488+
runtime: { ...baseThread.runtime, status, activeRunId: null },
489+
};
490+
const disconnected = { ...online, connectionPhase: "reconnecting" as const };
491+
expect(resolveSidebarThreadStatus(disconnected)).toBe(resolveSidebarThreadStatus(online));
492+
expect(resolveThreadStatusPill({ thread: disconnected })).toEqual(
493+
resolveThreadStatusPill({ thread: online }),
494+
);
495+
}
496+
});
497+
498+
it.each(["preparing", "queued", "starting", "running", "waiting"] as const)(
499+
"qualifies a cached %s runtime while reconnecting",
500+
(status) => {
501+
const thread = {
502+
...baseThread,
503+
connectionPhase: "reconnecting" as const,
504+
runtime: { ...baseThread.runtime, status },
505+
};
506+
expect(resolveSidebarThreadStatus(thread)).toBe("reconnecting");
507+
expect(resolveThreadStatusPill({ thread })?.label).toBe("Reconnecting");
508+
},
509+
);
510+
511+
it.each(["failed", "completed"] as const)(
512+
"preserves an unseen %s outcome while disconnected",
513+
(status) => {
514+
const thread = {
515+
...baseThread,
516+
connectionPhase: "reconnecting" as const,
517+
runtime: { ...baseThread.runtime, status, activeRunId: null },
518+
lastVisitedAt: "2026-03-09T09:00:00.000Z",
519+
latestRun: {
520+
runId: RunId.make("run-ended"),
521+
status,
522+
requestedAt: "2026-03-09T09:30:00.000Z",
523+
startedAt: "2026-03-09T09:30:00.000Z",
524+
completedAt: "2026-03-09T10:00:00.000Z",
525+
assistantMessageId: null,
526+
},
527+
};
528+
expect(resolveThreadStatusPill({ thread })?.label).toBe(
529+
status === "failed" ? "Failed" : "Completed",
530+
);
531+
},
532+
);
533+
445534
it("shows an active thread wait without a pulse and resumes Working when it ends", () => {
446535
const blocked = { ...baseThread, blockedOnThreadWait: true };
447536
expect(resolveSidebarThreadStatus(blocked)).toBe("waiting");

0 commit comments

Comments
 (0)