diff --git a/apps/mobile/src/features/threads/ThreadRouteScreen.tsx b/apps/mobile/src/features/threads/ThreadRouteScreen.tsx
index 6feb3750d6f5..02b5ff931d31 100644
--- a/apps/mobile/src/features/threads/ThreadRouteScreen.tsx
+++ b/apps/mobile/src/features/threads/ThreadRouteScreen.tsx
@@ -994,7 +994,12 @@ function ThreadRouteContent(
// A thread this client is creating has nothing older to sync.
const threadSyncLabel =
creationState === null
- ? threadSyncStatusLabel(selectedThreadDetailState.status, contentPresentation.kind, m)
+ ? threadSyncStatusLabel(
+ selectedThreadDetailState.status,
+ contentPresentation.kind,
+ Option.isSome(selectedThreadDetailState.error),
+ m,
+ )
: null;
// Transient states go in the header subtitle so the composer's status slot doesn't jump.
const threadStatusLabel = useDelayedStatus(
diff --git a/apps/mobile/src/features/threads/threadContentPresentation.test.ts b/apps/mobile/src/features/threads/threadContentPresentation.test.ts
index 3990799d8592..fbfd575fcb63 100644
--- a/apps/mobile/src/features/threads/threadContentPresentation.test.ts
+++ b/apps/mobile/src/features/threads/threadContentPresentation.test.ts
@@ -1,6 +1,9 @@
import { describe, expect, it } from "@effect/vitest";
-import { projectThreadContentPresentation } from "./threadContentPresentation";
+import {
+ projectThreadContentPresentation,
+ threadSyncStatusLabel,
+} from "./threadContentPresentation";
describe("thread content presentation", () => {
it("renders cached detail while its environment reconnects", () => {
@@ -28,4 +31,9 @@ describe("thread content presentation", () => {
detail: "Reconnect this environment to load the conversation.",
});
});
+
+ it("shows a sync failure over cached messages instead of syncing forever", () => {
+ expect(threadSyncStatusLabel("cached", "ready", true)).toBe("Could not sync messages");
+ expect(threadSyncStatusLabel("cached", "ready", false)).toBe("Syncing messages…");
+ });
});
diff --git a/apps/mobile/src/features/threads/threadContentPresentation.ts b/apps/mobile/src/features/threads/threadContentPresentation.ts
index 6723fb8bd559..a6157d43ad79 100644
--- a/apps/mobile/src/features/threads/threadContentPresentation.ts
+++ b/apps/mobile/src/features/threads/threadContentPresentation.ts
@@ -55,9 +55,12 @@ export function projectThreadContentPresentation(input: {
export function threadSyncStatusLabel(
status: EnvironmentThreadStatus,
presentation: ThreadContentPresentation["kind"],
+ hasError: boolean,
resolve: MessageResolver = m,
): string | null {
if (status !== "empty" && status !== "cached" && status !== "synchronizing") return null;
- if (presentation === "ready") return resolve(msg("Syncing messages…"));
+ if (presentation === "ready") {
+ return hasError ? resolve(msg("Could not sync messages")) : resolve(msg("Syncing messages…"));
+ }
return presentation === "loading" ? resolve(msg("Loading messages…")) : null;
}
diff --git a/apps/mobile/src/i18n/translations/de.json b/apps/mobile/src/i18n/translations/de.json
index 7120b11245be..f7547681200a 100644
--- a/apps/mobile/src/i18n/translations/de.json
+++ b/apps/mobile/src/i18n/translations/de.json
@@ -4863,6 +4863,7 @@
"fd7d017dc6b0e2c9": "Unterhaltung konnte nicht geladen werden",
"d06aa0c461291a2a": "Nachrichten nicht zwischengespeichert",
"2414be1137e0112a": "Verbinde diese Umgebung erneut, um die Unterhaltung zu laden.",
+ "c1968621dc365115": "Nachrichten konnten nicht synchronisiert werden",
"5e7b8c39e3c0a6a0": "Nachrichten werden synchronisiert…",
"8a1cb930736c03cf": "Nachrichten werden geladen…",
"cd625fe969e84626": "Mehr",
diff --git a/apps/mobile/src/i18n/translations/en.json b/apps/mobile/src/i18n/translations/en.json
index 3a6db4a4bd1d..bcc2e5089de7 100644
--- a/apps/mobile/src/i18n/translations/en.json
+++ b/apps/mobile/src/i18n/translations/en.json
@@ -4864,6 +4864,7 @@
"fd7d017dc6b0e2c9": "Could not load conversation",
"d06aa0c461291a2a": "Messages not cached",
"2414be1137e0112a": "Reconnect this environment to load the conversation.",
+ "c1968621dc365115": "Could not sync messages",
"5e7b8c39e3c0a6a0": "Syncing messages…",
"8a1cb930736c03cf": "Loading messages…",
"cd625fe969e84626": "More",
diff --git a/apps/mobile/src/i18n/translations/es.json b/apps/mobile/src/i18n/translations/es.json
index 6006cd01c86e..86056bdd2537 100644
--- a/apps/mobile/src/i18n/translations/es.json
+++ b/apps/mobile/src/i18n/translations/es.json
@@ -4856,6 +4856,7 @@
"fd7d017dc6b0e2c9": "No se pudo cargar la conversación",
"d06aa0c461291a2a": "Mensajes no guardados en caché",
"2414be1137e0112a": "Vuelve a conectar este entorno para cargar la conversación.",
+ "c1968621dc365115": "No se pudieron sincronizar los mensajes",
"5e7b8c39e3c0a6a0": "Sincronizando mensajes…",
"8a1cb930736c03cf": "Cargando mensajes…",
"cd625fe969e84626": "Más",
diff --git a/apps/mobile/src/i18n/translations/fr.json b/apps/mobile/src/i18n/translations/fr.json
index cb4dbb64249b..8c895b80ee10 100644
--- a/apps/mobile/src/i18n/translations/fr.json
+++ b/apps/mobile/src/i18n/translations/fr.json
@@ -4857,6 +4857,7 @@
"fd7d017dc6b0e2c9": "Impossible de charger la conversation",
"d06aa0c461291a2a": "Messages non mis en cache",
"2414be1137e0112a": "Reconnectez cet environnement pour charger la conversation.",
+ "c1968621dc365115": "Impossible de synchroniser les messages",
"5e7b8c39e3c0a6a0": "Synchronisation des messages…",
"8a1cb930736c03cf": "Chargement des messages…",
"cd625fe969e84626": "Plus",
diff --git a/apps/mobile/src/i18n/translations/ja.json b/apps/mobile/src/i18n/translations/ja.json
index 516f7a74b7d2..3b322bb2cdaf 100644
--- a/apps/mobile/src/i18n/translations/ja.json
+++ b/apps/mobile/src/i18n/translations/ja.json
@@ -4838,6 +4838,7 @@
"fd7d017dc6b0e2c9": "会話を読み込めませんでした",
"d06aa0c461291a2a": "メッセージはキャッシュされていません",
"2414be1137e0112a": "会話を読み込むにはこの環境に再接続してください。",
+ "c1968621dc365115": "メッセージを同期できませんでした",
"5e7b8c39e3c0a6a0": "メッセージを同期しています…",
"8a1cb930736c03cf": "メッセージを読み込んでいます…",
"cd625fe969e84626": "その他",
diff --git a/apps/mobile/src/i18n/translations/ko.json b/apps/mobile/src/i18n/translations/ko.json
index 271b2f688294..13d92369c0ec 100644
--- a/apps/mobile/src/i18n/translations/ko.json
+++ b/apps/mobile/src/i18n/translations/ko.json
@@ -4843,6 +4843,7 @@
"fd7d017dc6b0e2c9": "대화를 불러올 수 없습니다",
"d06aa0c461291a2a": "메시지가 캐시되지 않음",
"2414be1137e0112a": "대화를 불러오려면 이 환경을 다시 연결하세요.",
+ "c1968621dc365115": "메시지를 동기화할 수 없습니다",
"5e7b8c39e3c0a6a0": "메시지 동기화 중…",
"8a1cb930736c03cf": "메시지 불러오는 중…",
"cd625fe969e84626": "더 보기",
diff --git a/apps/mobile/src/i18n/translations/pt-BR.json b/apps/mobile/src/i18n/translations/pt-BR.json
index 4756d402cd98..5eb8d30f354a 100644
--- a/apps/mobile/src/i18n/translations/pt-BR.json
+++ b/apps/mobile/src/i18n/translations/pt-BR.json
@@ -4857,6 +4857,7 @@
"fd7d017dc6b0e2c9": "Não foi possível carregar a conversa",
"d06aa0c461291a2a": "Mensagens não armazenadas em cache",
"2414be1137e0112a": "Reconecte este ambiente para carregar a conversa.",
+ "c1968621dc365115": "Não foi possível sincronizar as mensagens",
"5e7b8c39e3c0a6a0": "Sincronizando mensagens…",
"8a1cb930736c03cf": "Carregando mensagens…",
"cd625fe969e84626": "Mais",
diff --git a/apps/mobile/src/i18n/translations/ru.json b/apps/mobile/src/i18n/translations/ru.json
index 835404ab5567..e578a65fe684 100644
--- a/apps/mobile/src/i18n/translations/ru.json
+++ b/apps/mobile/src/i18n/translations/ru.json
@@ -4935,6 +4935,7 @@
"fd7d017dc6b0e2c9": "Не удалось загрузить беседу",
"d06aa0c461291a2a": "Сообщения не закешированы",
"2414be1137e0112a": "Переподключите это окружение, чтобы загрузить беседу.",
+ "c1968621dc365115": "Не удалось синхронизировать сообщения",
"5e7b8c39e3c0a6a0": "Синхронизация сообщений…",
"8a1cb930736c03cf": "Загрузка сообщений…",
"cd625fe969e84626": "Ещё",
diff --git a/apps/mobile/src/i18n/translations/sv.json b/apps/mobile/src/i18n/translations/sv.json
index 85b6cb5f8ea9..f403798f4b2d 100644
--- a/apps/mobile/src/i18n/translations/sv.json
+++ b/apps/mobile/src/i18n/translations/sv.json
@@ -4863,6 +4863,7 @@
"fd7d017dc6b0e2c9": "Kunde inte läsa in konversationen",
"d06aa0c461291a2a": "Meddelandena är inte cachade",
"2414be1137e0112a": "Återanslut miljön för att läsa in konversationen.",
+ "c1968621dc365115": "Det gick inte att synkronisera meddelanden",
"5e7b8c39e3c0a6a0": "Synkroniserar meddelanden…",
"8a1cb930736c03cf": "Läser in meddelanden…",
"cd625fe969e84626": "Mer",
diff --git a/apps/mobile/src/i18n/translations/zh.json b/apps/mobile/src/i18n/translations/zh.json
index 2fa277f9d97a..2280326a22be 100644
--- a/apps/mobile/src/i18n/translations/zh.json
+++ b/apps/mobile/src/i18n/translations/zh.json
@@ -4846,6 +4846,7 @@
"fd7d017dc6b0e2c9": "无法加载对话",
"d06aa0c461291a2a": "消息未缓存",
"2414be1137e0112a": "重新连接此环境以加载对话。",
+ "c1968621dc365115": "无法同步消息",
"5e7b8c39e3c0a6a0": "正在同步消息…",
"8a1cb930736c03cf": "正在加载消息…",
"cd625fe969e84626": "更多",
diff --git a/apps/web/src/components/ChatView.tsx b/apps/web/src/components/ChatView.tsx
index a97fde7ebee3..07b858dc1835 100644
--- a/apps/web/src/components/ChatView.tsx
+++ b/apps/web/src/components/ChatView.tsx
@@ -282,6 +282,7 @@ import {
useThreadUpdatedAt,
useThreadLastVisitedAt,
useQuietThreadVisibleTurnItems,
+ useThreadError,
useThreadStatus,
useThreadHistory,
useQuietThreadShell,
@@ -550,10 +551,12 @@ export default function ChatView(props: ChatViewProps) {
? deriveReportedModelSelection(serverProjection)
: null;
const threadStatus = useThreadStatus(routeThreadDetailRef);
+ const threadSyncError = useThreadError(routeThreadDetailRef);
const threadSyncPhase = resolveThreadSyncPhase({
detailExists: serverProjection !== null,
shellExists: serverThread !== null,
status: threadStatus,
+ hasError: threadSyncError !== null,
});
const threadDetailLoading = threadSyncPhase === "loading";
// Held back briefly, so a quick sync does not flash a status line at the end of the timeline.
diff --git a/apps/web/src/components/chat/ThreadNow.tsx b/apps/web/src/components/chat/ThreadNow.tsx
index 0fe75b736b12..43f17df95f67 100644
--- a/apps/web/src/components/chat/ThreadNow.tsx
+++ b/apps/web/src/components/chat/ThreadNow.tsx
@@ -1,4 +1,4 @@
-import { RefreshCwIcon } from "lucide-react";
+import { CircleAlertIcon, RefreshCwIcon } from "lucide-react";
import type { ReactNode } from "react";
import { threadSyncLabel, type ThreadSyncPhase } from "../../threadSync";
@@ -61,8 +61,12 @@ function ThreadNowLine({
function ThreadSyncLine({ phase }: { readonly phase: ThreadSyncPhase }) {
const m = useMessages();
return (
-
-
+
+ {phase === "failed" ? : }
{threadSyncLabel(phase, m)}
);
diff --git a/apps/web/src/i18n/translations/de.json b/apps/web/src/i18n/translations/de.json
index 84ccbdd27d5a..ed3b458f0eb4 100644
--- a/apps/web/src/i18n/translations/de.json
+++ b/apps/web/src/i18n/translations/de.json
@@ -1440,6 +1440,7 @@
"5590426dc4cfa3f6": "Benachrichtigungen mit Ton",
"0aceebf3f6d0d568": "Nachrichten werden geladen...",
"ed50d75cb04dfb8c": "Nachrichten werden synchronisiert...",
+ "c1968621dc365115": "Nachrichten konnten nicht synchronisiert werden",
"de032945adf75356": "{time}, {date}",
"fe01feb02ef95d6c": "gestern um {time}",
"d54b94665b443500": "morgen um {time}",
diff --git a/apps/web/src/i18n/translations/en.json b/apps/web/src/i18n/translations/en.json
index 0a83a48c9eb7..ee601119f127 100644
--- a/apps/web/src/i18n/translations/en.json
+++ b/apps/web/src/i18n/translations/en.json
@@ -1440,6 +1440,7 @@
"5590426dc4cfa3f6": "Notifications with sound",
"0aceebf3f6d0d568": "Loading messages...",
"ed50d75cb04dfb8c": "Syncing messages...",
+ "c1968621dc365115": "Could not sync messages",
"de032945adf75356": "{time}, {date}",
"fe01feb02ef95d6c": "yesterday at {time}",
"d54b94665b443500": "tomorrow at {time}",
diff --git a/apps/web/src/i18n/translations/es.json b/apps/web/src/i18n/translations/es.json
index 3d16aa41355e..dc81ff2ab2e5 100644
--- a/apps/web/src/i18n/translations/es.json
+++ b/apps/web/src/i18n/translations/es.json
@@ -1440,6 +1440,7 @@
"5590426dc4cfa3f6": "Notificaciones con sonido",
"0aceebf3f6d0d568": "Cargando mensajes...",
"ed50d75cb04dfb8c": "Sincronizando mensajes...",
+ "c1968621dc365115": "No se pudieron sincronizar los mensajes",
"de032945adf75356": "{time}, {date}",
"fe01feb02ef95d6c": "ayer a las {time}",
"d54b94665b443500": "mañana a las {time}",
diff --git a/apps/web/src/i18n/translations/fr.json b/apps/web/src/i18n/translations/fr.json
index 7aef263e10a8..134cec3719d7 100644
--- a/apps/web/src/i18n/translations/fr.json
+++ b/apps/web/src/i18n/translations/fr.json
@@ -1440,6 +1440,7 @@
"5590426dc4cfa3f6": "Notifications avec son",
"0aceebf3f6d0d568": "Chargement des messages...",
"ed50d75cb04dfb8c": "Synchronisation des messages...",
+ "c1968621dc365115": "Impossible de synchroniser les messages",
"de032945adf75356": "{time}, {date}",
"fe01feb02ef95d6c": "hier à {time}",
"d54b94665b443500": "demain à {time}",
diff --git a/apps/web/src/i18n/translations/ja.json b/apps/web/src/i18n/translations/ja.json
index b5b720265f30..ba4cbfadbcd7 100644
--- a/apps/web/src/i18n/translations/ja.json
+++ b/apps/web/src/i18n/translations/ja.json
@@ -1440,6 +1440,7 @@
"5590426dc4cfa3f6": "通知とサウンド",
"0aceebf3f6d0d568": "メッセージを読み込んでいます...",
"ed50d75cb04dfb8c": "メッセージを同期しています...",
+ "c1968621dc365115": "メッセージを同期できませんでした",
"de032945adf75356": "{date} {time}",
"fe01feb02ef95d6c": "昨日 {time}",
"d54b94665b443500": "明日 {time}",
diff --git a/apps/web/src/i18n/translations/ko.json b/apps/web/src/i18n/translations/ko.json
index 489cb1b187c0..b0a22c410366 100644
--- a/apps/web/src/i18n/translations/ko.json
+++ b/apps/web/src/i18n/translations/ko.json
@@ -1440,6 +1440,7 @@
"5590426dc4cfa3f6": "알림 및 소리",
"0aceebf3f6d0d568": "메시지를 불러오는 중...",
"ed50d75cb04dfb8c": "메시지를 동기화하는 중...",
+ "c1968621dc365115": "메시지를 동기화할 수 없습니다",
"de032945adf75356": "{date} {time}",
"fe01feb02ef95d6c": "어제 {time}",
"d54b94665b443500": "내일 {time}",
diff --git a/apps/web/src/i18n/translations/pt-BR.json b/apps/web/src/i18n/translations/pt-BR.json
index f3e0839ebaaf..fd63febb03d5 100644
--- a/apps/web/src/i18n/translations/pt-BR.json
+++ b/apps/web/src/i18n/translations/pt-BR.json
@@ -1440,6 +1440,7 @@
"5590426dc4cfa3f6": "Notificações com som",
"0aceebf3f6d0d568": "Carregando mensagens...",
"ed50d75cb04dfb8c": "Sincronizando mensagens...",
+ "c1968621dc365115": "Não foi possível sincronizar as mensagens",
"de032945adf75356": "{time}, {date}",
"fe01feb02ef95d6c": "ontem às {time}",
"d54b94665b443500": "amanhã às {time}",
diff --git a/apps/web/src/i18n/translations/ru.json b/apps/web/src/i18n/translations/ru.json
index 61fa8128bea2..4b0f54b4a75c 100644
--- a/apps/web/src/i18n/translations/ru.json
+++ b/apps/web/src/i18n/translations/ru.json
@@ -1440,6 +1440,7 @@
"5590426dc4cfa3f6": "Уведомления со звуком",
"0aceebf3f6d0d568": "Загрузка сообщений...",
"ed50d75cb04dfb8c": "Синхронизация сообщений...",
+ "c1968621dc365115": "Не удалось синхронизировать сообщения",
"de032945adf75356": "{time}, {date}",
"fe01feb02ef95d6c": "вчера в {time}",
"d54b94665b443500": "завтра в {time}",
diff --git a/apps/web/src/i18n/translations/sv.json b/apps/web/src/i18n/translations/sv.json
index dfd0ebabbc84..2ed0492eaaee 100644
--- a/apps/web/src/i18n/translations/sv.json
+++ b/apps/web/src/i18n/translations/sv.json
@@ -1440,6 +1440,7 @@
"5590426dc4cfa3f6": "Aviseringar med ljud",
"0aceebf3f6d0d568": "Läser in meddelanden...",
"ed50d75cb04dfb8c": "Synkar meddelanden...",
+ "c1968621dc365115": "Det gick inte att synkronisera meddelanden",
"de032945adf75356": "{time}, {date}",
"fe01feb02ef95d6c": "i går kl. {time}",
"d54b94665b443500": "i morgon kl. {time}",
diff --git a/apps/web/src/i18n/translations/zh.json b/apps/web/src/i18n/translations/zh.json
index c70b20c3e14d..9581d100fb97 100644
--- a/apps/web/src/i18n/translations/zh.json
+++ b/apps/web/src/i18n/translations/zh.json
@@ -1440,6 +1440,7 @@
"5590426dc4cfa3f6": "通知与声音",
"0aceebf3f6d0d568": "正在加载消息…",
"ed50d75cb04dfb8c": "正在同步消息…",
+ "c1968621dc365115": "无法同步消息",
"de032945adf75356": "{date} {time}",
"fe01feb02ef95d6c": "昨天 {time}",
"d54b94665b443500": "明天 {time}",
diff --git a/apps/web/src/state/entities.ts b/apps/web/src/state/entities.ts
index 185069d4849e..e2205c7c2d78 100644
--- a/apps/web/src/state/entities.ts
+++ b/apps/web/src/state/entities.ts
@@ -76,6 +76,9 @@ const EMPTY_ASSISTANT_MESSAGE_TEXT_ATOM = Atom.make
(null).pipe(
const EMPTY_LAST_VISITED_AT_ATOM = Atom.make(null).pipe(
Atom.withLabel("web-thread-last-visited:empty"),
);
+const EMPTY_THREAD_ERROR_ATOM = Atom.make(null).pipe(
+ Atom.withLabel("web-thread-error:empty"),
+);
const EMPTY_UPDATED_AT_ATOM = Atom.make(null).pipe(
Atom.withLabel("web-thread-updated-at:empty"),
);
@@ -211,6 +214,12 @@ export function useThreadStatus(ref: ScopedThreadRef | null): EnvironmentThreadS
);
}
+export function useThreadError(ref: ScopedThreadRef | null): string | null {
+ return useAtomValue(
+ ref === null ? EMPTY_THREAD_ERROR_ATOM : environmentThreadDetails.errorAtom(ref),
+ );
+}
+
export function useThreadHistory(ref: ScopedThreadRef | null): ThreadHistoryMeta {
return useAtomValue(
ref === null ? EMPTY_THREAD_HISTORY_ATOM : environmentThreadDetails.historyAtom(ref),
diff --git a/apps/web/src/threadSync.test.ts b/apps/web/src/threadSync.test.ts
new file mode 100644
index 000000000000..f76d1bda71fc
--- /dev/null
+++ b/apps/web/src/threadSync.test.ts
@@ -0,0 +1,32 @@
+import { describe, expect, it } from "vite-plus/test";
+
+import { resolveThreadSyncPhase } from "./threadSync";
+
+describe("resolveThreadSyncPhase", () => {
+ it("reports a failed sync instead of syncing over cached messages", () => {
+ expect(
+ resolveThreadSyncPhase({
+ detailExists: true,
+ shellExists: true,
+ status: "cached",
+ hasError: true,
+ }),
+ ).toBe("failed");
+ expect(
+ resolveThreadSyncPhase({
+ detailExists: false,
+ shellExists: true,
+ status: "synchronizing",
+ hasError: true,
+ }),
+ ).toBe("loading");
+ expect(
+ resolveThreadSyncPhase({
+ detailExists: true,
+ shellExists: true,
+ status: "synchronizing",
+ hasError: false,
+ }),
+ ).toBe("syncing");
+ });
+});
diff --git a/apps/web/src/threadSync.ts b/apps/web/src/threadSync.ts
index 6e8d1bc6f812..9390d64d1b80 100644
--- a/apps/web/src/threadSync.ts
+++ b/apps/web/src/threadSync.ts
@@ -3,12 +3,13 @@ import { msg } from "gt-react";
import { m, type MessageResolver } from "./i18n/messages";
-export type ThreadSyncPhase = "loading" | "syncing";
+export type ThreadSyncPhase = "loading" | "syncing" | "failed";
export function resolveThreadSyncPhase(input: {
readonly detailExists: boolean;
readonly shellExists: boolean;
readonly status: EnvironmentThreadStatus;
+ readonly hasError: boolean;
}): ThreadSyncPhase | null {
if (!input.shellExists) {
return null;
@@ -18,7 +19,8 @@ export function resolveThreadSyncPhase(input: {
case "empty":
case "cached":
case "synchronizing":
- return input.detailExists ? "syncing" : "loading";
+ if (!input.detailExists) return "loading";
+ return input.hasError ? "failed" : "syncing";
case "deleted":
case "live":
return null;
@@ -26,7 +28,12 @@ export function resolveThreadSyncPhase(input: {
}
export function threadSyncLabel(phase: ThreadSyncPhase, resolve: MessageResolver = m): string {
- return phase === "loading"
- ? resolve(msg("Loading messages..."))
- : resolve(msg("Syncing messages..."));
+ switch (phase) {
+ case "loading":
+ return resolve(msg("Loading messages..."));
+ case "syncing":
+ return resolve(msg("Syncing messages..."));
+ case "failed":
+ return resolve(msg("Could not sync messages"));
+ }
}
diff --git a/packages/client-runtime/src/state/threads-sync.test.ts b/packages/client-runtime/src/state/threads-sync.test.ts
index 5a771646f03f..3694b670b281 100644
--- a/packages/client-runtime/src/state/threads-sync.test.ts
+++ b/packages/client-runtime/src/state/threads-sync.test.ts
@@ -2489,6 +2489,47 @@ describe("EnvironmentThreads", () => {
}),
);
+ it.effect("reloads the full snapshot after a resumed replay hits a defect", () =>
+ Effect.gen(function* () {
+ const harness = yield* makeHarness({ cached: BASE_PROJECTION, completionMarker: true });
+ const awaitSubscriptions = (count: number) =>
+ SubscriptionRef.changes(harness.subscriptionCount).pipe(
+ Stream.filter((value) => value >= count),
+ Stream.runHead,
+ );
+ yield* awaitSubscriptions(1);
+ expect(yield* Ref.get(harness.lastSubscribeAfterSequence)).toBe(CACHED_SNAPSHOT_SEQUENCE);
+
+ // The cursor that died would die again, so the retry drops it at once, without an error.
+ yield* Queue.offer(harness.inputs, TEST_DEFECT);
+ yield* awaitSubscriptions(2);
+ expect(yield* Ref.get(harness.lastSubscribeAfterSequence)).toBeUndefined();
+ expect(Option.isNone((yield* Ref.get(harness.latest)).error)).toBe(true);
+
+ // A failed reload backs off, still from the snapshot.
+ yield* Queue.offer(harness.inputs, TEST_DEFECT);
+ yield* awaitThreadState(harness.observed, (value) => Option.isSome(value.error));
+ yield* TestClock.adjust("60 seconds");
+ yield* awaitSubscriptions(3);
+ expect(yield* Ref.get(harness.lastSubscribeAfterSequence)).toBeUndefined();
+
+ yield* Queue.offerAll(harness.inputs, [
+ snapshot(
+ { ...BASE_PROJECTION, thread: { ...BASE_PROJECTION.thread, title: "Reloaded thread" } },
+ CACHED_SNAPSHOT_SEQUENCE + 5,
+ ),
+ synchronized(),
+ ]);
+ const live = yield* awaitThreadState(harness.observed, (value) => value.status === "live");
+ expect(Option.isNone(live.error)).toBe(true);
+ expect(Option.getOrThrow(live.data).thread.title).toBe("Reloaded thread");
+
+ yield* harness.replaceSession;
+ yield* awaitSubscriptions(4);
+ expect(yield* Ref.get(harness.lastSubscribeAfterSequence)).toBe(CACHED_SNAPSHOT_SEQUENCE + 5);
+ }),
+ );
+
it.effect("keeps replayed updates synchronizing until the completion marker arrives", () =>
Effect.gen(function* () {
const harness = yield* makeHarness({ cached: BASE_PROJECTION, completionMarker: true });
diff --git a/packages/client-runtime/src/state/threads.ts b/packages/client-runtime/src/state/threads.ts
index 462be846d84a..7ea4b72e4779 100644
--- a/packages/client-runtime/src/state/threads.ts
+++ b/packages/client-runtime/src/state/threads.ts
@@ -674,6 +674,7 @@ export const makeEnvironmentThreadState = Effect.fn("EnvironmentThreadState.make
}
if (item.kind === "snapshot") {
+ yield* Ref.set(forceSnapshot, false);
yield* SubscriptionRef.set(lastSequence, item.snapshotSequence);
const hasProgressiveHistory =
item.historyCursor !== undefined ||
@@ -1000,6 +1001,10 @@ export const makeEnvironmentThreadState = Effect.fn("EnvironmentThreadState.make
});
// A stream defect parks the subscription until something resubscribes it.
const resubscribes = yield* Queue.unbounded();
+ // A resumed replay that dies (an event this client cannot decode) dies the same
+ // way from the same cursor, so later attempts reload the full snapshot until one applies.
+ const resuming = yield* Ref.make(false);
+ const forceSnapshot = yield* Ref.make(false);
const markSynchronizing = Effect.gen(function* () {
if (yield* Ref.get(resumingLive)) return;
yield* SubscriptionRef.update(state, (current) =>
@@ -1110,7 +1115,8 @@ export const makeEnvironmentThreadState = Effect.fn("EnvironmentThreadState.make
}
const sequence = yield* SubscriptionRef.get(lastSequence);
- const canResume = Option.isSome(current.data);
+ const canResume = Option.isSome(current.data) && !(yield* Ref.get(forceSnapshot));
+ yield* Ref.set(resuming, canResume);
const acceptBoundedSnapshot = yield* Ref.get(acceptsBoundedSocketSnapshots);
return {
@@ -1139,6 +1145,10 @@ export const makeEnvironmentThreadState = Effect.fn("EnvironmentThreadState.make
if (!Cause.hasDies(cause)) {
return yield* setStreamError(THREAD_SYNC_ERROR);
}
+ yield* Ref.set(forceSnapshot, true);
+ if (yield* Ref.getAndSet(resuming, false)) {
+ return yield* Queue.offer(resubscribes, undefined);
+ }
yield* backOffAfterDefect;
yield* Queue.offer(resubscribes, undefined);
}),
@@ -1168,6 +1178,7 @@ export const makeEnvironmentThreadState = Effect.fn("EnvironmentThreadState.make
environmentId,
threadId,
}).pipe(
+ Effect.andThen(Ref.set(forceSnapshot, true)),
Effect.andThen(backOffAfterDefect),
Effect.andThen(Effect.suspend(followThread)),
),