Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion apps/mobile/src/features/threads/ThreadRouteScreen.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
Original file line number Diff line number Diff line change
@@ -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", () => {
Expand Down Expand Up @@ -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…");
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
1 change: 1 addition & 0 deletions apps/mobile/src/i18n/translations/de.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
1 change: 1 addition & 0 deletions apps/mobile/src/i18n/translations/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
1 change: 1 addition & 0 deletions apps/mobile/src/i18n/translations/es.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
1 change: 1 addition & 0 deletions apps/mobile/src/i18n/translations/fr.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
1 change: 1 addition & 0 deletions apps/mobile/src/i18n/translations/ja.json
Original file line number Diff line number Diff line change
Expand Up @@ -4838,6 +4838,7 @@
"fd7d017dc6b0e2c9": "会話を読み込めませんでした",
"d06aa0c461291a2a": "メッセージはキャッシュされていません",
"2414be1137e0112a": "会話を読み込むにはこの環境に再接続してください。",
"c1968621dc365115": "メッセージを同期できませんでした",
"5e7b8c39e3c0a6a0": "メッセージを同期しています…",
"8a1cb930736c03cf": "メッセージを読み込んでいます…",
"cd625fe969e84626": "その他",
Expand Down
1 change: 1 addition & 0 deletions apps/mobile/src/i18n/translations/ko.json
Original file line number Diff line number Diff line change
Expand Up @@ -4843,6 +4843,7 @@
"fd7d017dc6b0e2c9": "대화를 불러올 수 없습니다",
"d06aa0c461291a2a": "메시지가 캐시되지 않음",
"2414be1137e0112a": "대화를 불러오려면 이 환경을 다시 연결하세요.",
"c1968621dc365115": "메시지를 동기화할 수 없습니다",
"5e7b8c39e3c0a6a0": "메시지 동기화 중…",
"8a1cb930736c03cf": "메시지 불러오는 중…",
"cd625fe969e84626": "더 보기",
Expand Down
1 change: 1 addition & 0 deletions apps/mobile/src/i18n/translations/pt-BR.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
1 change: 1 addition & 0 deletions apps/mobile/src/i18n/translations/ru.json
Original file line number Diff line number Diff line change
Expand Up @@ -4935,6 +4935,7 @@
"fd7d017dc6b0e2c9": "Не удалось загрузить беседу",
"d06aa0c461291a2a": "Сообщения не закешированы",
"2414be1137e0112a": "Переподключите это окружение, чтобы загрузить беседу.",
"c1968621dc365115": "Не удалось синхронизировать сообщения",
"5e7b8c39e3c0a6a0": "Синхронизация сообщений…",
"8a1cb930736c03cf": "Загрузка сообщений…",
"cd625fe969e84626": "Ещё",
Expand Down
1 change: 1 addition & 0 deletions apps/mobile/src/i18n/translations/sv.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
1 change: 1 addition & 0 deletions apps/mobile/src/i18n/translations/zh.json
Original file line number Diff line number Diff line change
Expand Up @@ -4846,6 +4846,7 @@
"fd7d017dc6b0e2c9": "无法加载对话",
"d06aa0c461291a2a": "消息未缓存",
"2414be1137e0112a": "重新连接此环境以加载对话。",
"c1968621dc365115": "无法同步消息",
"5e7b8c39e3c0a6a0": "正在同步消息…",
"8a1cb930736c03cf": "正在加载消息…",
"cd625fe969e84626": "更多",
Expand Down
3 changes: 3 additions & 0 deletions apps/web/src/components/ChatView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -282,6 +282,7 @@ import {
useThreadUpdatedAt,
useThreadLastVisitedAt,
useQuietThreadVisibleTurnItems,
useThreadError,
useThreadStatus,
useThreadHistory,
useQuietThreadShell,
Expand Down Expand Up @@ -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.
Expand Down
10 changes: 7 additions & 3 deletions apps/web/src/components/chat/ThreadNow.tsx
Original file line number Diff line number Diff line change
@@ -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";
Expand Down Expand Up @@ -61,8 +61,12 @@ function ThreadNowLine({
function ThreadSyncLine({ phase }: { readonly phase: ThreadSyncPhase }) {
const m = useMessages();
return (
<div className={lineClassName} role="status" data-composer-sync-status={phase}>
<RefreshCwIcon aria-hidden />
<div
className={lineClassName}
role={phase === "failed" ? "alert" : "status"}
data-composer-sync-status={phase}
>
{phase === "failed" ? <CircleAlertIcon aria-hidden /> : <RefreshCwIcon aria-hidden />}
<span className="truncate">{threadSyncLabel(phase, m)}</span>
</div>
);
Expand Down
1 change: 1 addition & 0 deletions apps/web/src/i18n/translations/de.json
Original file line number Diff line number Diff line change
Expand Up @@ -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}",
Expand Down
1 change: 1 addition & 0 deletions apps/web/src/i18n/translations/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -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}",
Expand Down
1 change: 1 addition & 0 deletions apps/web/src/i18n/translations/es.json
Original file line number Diff line number Diff line change
Expand Up @@ -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}",
Expand Down
1 change: 1 addition & 0 deletions apps/web/src/i18n/translations/fr.json
Original file line number Diff line number Diff line change
Expand Up @@ -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}",
Expand Down
1 change: 1 addition & 0 deletions apps/web/src/i18n/translations/ja.json
Original file line number Diff line number Diff line change
Expand Up @@ -1440,6 +1440,7 @@
"5590426dc4cfa3f6": "通知とサウンド",
"0aceebf3f6d0d568": "メッセージを読み込んでいます...",
"ed50d75cb04dfb8c": "メッセージを同期しています...",
"c1968621dc365115": "メッセージを同期できませんでした",
"de032945adf75356": "{date} {time}",
"fe01feb02ef95d6c": "昨日 {time}",
"d54b94665b443500": "明日 {time}",
Expand Down
1 change: 1 addition & 0 deletions apps/web/src/i18n/translations/ko.json
Original file line number Diff line number Diff line change
Expand Up @@ -1440,6 +1440,7 @@
"5590426dc4cfa3f6": "알림 및 소리",
"0aceebf3f6d0d568": "메시지를 불러오는 중...",
"ed50d75cb04dfb8c": "메시지를 동기화하는 중...",
"c1968621dc365115": "메시지를 동기화할 수 없습니다",
"de032945adf75356": "{date} {time}",
"fe01feb02ef95d6c": "어제 {time}",
"d54b94665b443500": "내일 {time}",
Expand Down
1 change: 1 addition & 0 deletions apps/web/src/i18n/translations/pt-BR.json
Original file line number Diff line number Diff line change
Expand Up @@ -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}",
Expand Down
1 change: 1 addition & 0 deletions apps/web/src/i18n/translations/ru.json
Original file line number Diff line number Diff line change
Expand Up @@ -1440,6 +1440,7 @@
"5590426dc4cfa3f6": "Уведомления со звуком",
"0aceebf3f6d0d568": "Загрузка сообщений...",
"ed50d75cb04dfb8c": "Синхронизация сообщений...",
"c1968621dc365115": "Не удалось синхронизировать сообщения",
"de032945adf75356": "{time}, {date}",
"fe01feb02ef95d6c": "вчера в {time}",
"d54b94665b443500": "завтра в {time}",
Expand Down
1 change: 1 addition & 0 deletions apps/web/src/i18n/translations/sv.json
Original file line number Diff line number Diff line change
Expand Up @@ -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}",
Expand Down
1 change: 1 addition & 0 deletions apps/web/src/i18n/translations/zh.json
Original file line number Diff line number Diff line change
Expand Up @@ -1440,6 +1440,7 @@
"5590426dc4cfa3f6": "通知与声音",
"0aceebf3f6d0d568": "正在加载消息…",
"ed50d75cb04dfb8c": "正在同步消息…",
"c1968621dc365115": "无法同步消息",
"de032945adf75356": "{date} {time}",
"fe01feb02ef95d6c": "昨天 {time}",
"d54b94665b443500": "明天 {time}",
Expand Down
9 changes: 9 additions & 0 deletions apps/web/src/state/entities.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,9 @@ const EMPTY_ASSISTANT_MESSAGE_TEXT_ATOM = Atom.make<string | null>(null).pipe(
const EMPTY_LAST_VISITED_AT_ATOM = Atom.make<DateTime.Utc | null>(null).pipe(
Atom.withLabel("web-thread-last-visited:empty"),
);
const EMPTY_THREAD_ERROR_ATOM = Atom.make<string | null>(null).pipe(
Atom.withLabel("web-thread-error:empty"),
);
const EMPTY_UPDATED_AT_ATOM = Atom.make<DateTime.Utc | null>(null).pipe(
Atom.withLabel("web-thread-updated-at:empty"),
);
Expand Down Expand Up @@ -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),
Expand Down
32 changes: 32 additions & 0 deletions apps/web/src/threadSync.test.ts
Original file line number Diff line number Diff line change
@@ -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");
});
});
17 changes: 12 additions & 5 deletions apps/web/src/threadSync.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -18,15 +19,21 @@ 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;
}
}

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"));
}
}
41 changes: 41 additions & 0 deletions packages/client-runtime/src/state/threads-sync.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 });
Expand Down
Loading
Loading