Improve reconnect status feedback (#2931)
* fix(app): debounce reconnect status toast Keep reconnect transport immediate while delaying the visible status toast so brief outages stay quiet. Scope the toast to the active retained panel, keep its copy and status dot consistent across locales, and add a manual real relay deployment journey that verifies streaming recovery without user action. * fix(app): isolate manual relay deployment check Keep the deployment journey out of the provider-wide real test project so it runs only when its local relay prerequisites are explicitly requested. Also keep the relay teardown active when packaged daemon startup or later cleanup fails. * fix(app): preserve reconnect toast across tabs Keep reconnect presentation timing at the host level so switching between retained panels does not restart the debounce or flash the toast. Add a browser regression covering a visible outage across retained tab switches. * fix(app): anchor reconnect debounce to host status Record host connection status transitions independently of mounted agent panels and preserve the outage start across reconnecting states. Use that host-level timestamp when a visible agent panel appears, with runtime coverage for the transition lifecycle. * fix(app): reset reconnect toast state per outage * test(app): build relay journey prerequisites
This commit is contained in:
@@ -205,7 +205,7 @@ export const ar: TranslationResources = {
|
||||
states: {
|
||||
notFound: "لم يتم العثور على Agent",
|
||||
failedToLoad: "فشل تحميل الوكيل",
|
||||
reconnecting: "جارٍ إعادة الاتصال...",
|
||||
reconnecting: "جارٍ إعادة الاتصال",
|
||||
timelineSyncFailed: "تعذر تحديث سجل الوكيل. جارٍ إعادة المحاولة…",
|
||||
archivingTitle: "وكيل الارشيف...",
|
||||
archivingSubtitle: "الرجاء الانتظار بينما نقوم بأرشفة هذا الوكيل.",
|
||||
|
||||
@@ -203,7 +203,7 @@ export const en = {
|
||||
states: {
|
||||
notFound: "Agent not found",
|
||||
failedToLoad: "Failed to load agent",
|
||||
reconnecting: "Reconnecting...",
|
||||
reconnecting: "Reconnecting",
|
||||
timelineSyncFailed: "Couldn't refresh agent history. Retrying…",
|
||||
archivingTitle: "Archiving agent...",
|
||||
archivingSubtitle: "Please wait while we archive this agent.",
|
||||
|
||||
@@ -205,7 +205,7 @@ export const es: TranslationResources = {
|
||||
states: {
|
||||
notFound: "Agentno encontrado",
|
||||
failedToLoad: "No se pudo cargar el agente",
|
||||
reconnecting: "Reconectando...",
|
||||
reconnecting: "Reconectando",
|
||||
timelineSyncFailed: "No se pudo actualizar el historial del agente. Reintentando…",
|
||||
archivingTitle: "Agente de archivo...",
|
||||
archivingSubtitle: "Espere mientras archivamos este agente.",
|
||||
|
||||
@@ -207,7 +207,7 @@ export const fr: TranslationResources = {
|
||||
states: {
|
||||
notFound: "Agentintrouvable",
|
||||
failedToLoad: "Échec du chargement de l'agent",
|
||||
reconnecting: "Reconnexion...",
|
||||
reconnecting: "Reconnexion",
|
||||
timelineSyncFailed: "Impossible d’actualiser l’historique de l’agent. Nouvelle tentative…",
|
||||
archivingTitle: "Agent d'archivage...",
|
||||
archivingSubtitle: "Veuillez patienter pendant que nous archivons cet agent.",
|
||||
|
||||
@@ -205,7 +205,7 @@ export const ja: TranslationResources = {
|
||||
states: {
|
||||
notFound: "エージェントが見つかりません",
|
||||
failedToLoad: "エージェントの読み込みに失敗しました",
|
||||
reconnecting: "再接続中...",
|
||||
reconnecting: "再接続中",
|
||||
timelineSyncFailed: "エージェントの履歴を更新できませんでした。再試行しています…",
|
||||
archivingTitle: "エージェントをアーカイブ中...",
|
||||
archivingSubtitle: "このエージェントをアーカイブするまでお待ちください。",
|
||||
|
||||
@@ -205,7 +205,7 @@ export const ko: TranslationResources = {
|
||||
states: {
|
||||
notFound: "에이전트를 찾을 수 없습니다",
|
||||
failedToLoad: "에이전트를 불러오지 못했습니다",
|
||||
reconnecting: "다시 연결하는 중...",
|
||||
reconnecting: "다시 연결하는 중",
|
||||
timelineSyncFailed: "에이전트 기록을 새로고침할 수 없습니다. 재시도 중…",
|
||||
archivingTitle: "에이전트 보관 중...",
|
||||
archivingSubtitle: "이 에이전트를 보관하는 동안 잠시 기다려 주세요.",
|
||||
|
||||
@@ -205,7 +205,7 @@ export const ptBR: TranslationResources = {
|
||||
states: {
|
||||
notFound: "Agente não encontrado",
|
||||
failedToLoad: "Falha ao carregar agente",
|
||||
reconnecting: "Reconectando...",
|
||||
reconnecting: "Reconectando",
|
||||
timelineSyncFailed: "Não foi possível atualizar o histórico do agente. Tentando novamente…",
|
||||
archivingTitle: "Arquivando agente...",
|
||||
archivingSubtitle: "Aguarde enquanto arquivamos este agente.",
|
||||
|
||||
@@ -205,7 +205,7 @@ export const ru: TranslationResources = {
|
||||
states: {
|
||||
notFound: "Agent не найден",
|
||||
failedToLoad: "Не удалось загрузить агент",
|
||||
reconnecting: "Повторное подключение...",
|
||||
reconnecting: "Повторное подключение",
|
||||
timelineSyncFailed: "Не удалось обновить историю агента. Повторная попытка…",
|
||||
archivingTitle: "Архивный агент...",
|
||||
archivingSubtitle: "Пожалуйста, подождите, пока мы архивируем этого агента.",
|
||||
|
||||
@@ -205,7 +205,7 @@ export const zhCN: TranslationResources = {
|
||||
states: {
|
||||
notFound: "未找到 Agent",
|
||||
failedToLoad: "加载 Agent 失败",
|
||||
reconnecting: "正在重连...",
|
||||
reconnecting: "正在重连",
|
||||
timelineSyncFailed: "无法刷新代理历史记录。正在重试…",
|
||||
archivingTitle: "正在归档 Agent...",
|
||||
archivingSubtitle: "请稍候,我们正在归档这个 Agent。",
|
||||
|
||||
@@ -52,12 +52,17 @@ import { useArchiveAgent } from "@/hooks/use-archive-agent";
|
||||
import { useKeyboardShiftStyle } from "@/hooks/use-keyboard-shift-style";
|
||||
import { useContainerWidthBelow } from "@/hooks/use-container-width";
|
||||
import { reconcileMissingAgentStateWithPresentAgent } from "@/panels/agent-panel-load-state";
|
||||
import {
|
||||
reconcileReconnectToastState,
|
||||
type ReconnectToastState,
|
||||
} from "@/panels/reconnect-toast-state";
|
||||
import { usePaneContext, usePaneFocus } from "@/panels/pane-context";
|
||||
import type { PanelDescriptor, PanelRegistration } from "@/panels/panel-registry";
|
||||
import { RenderProfile } from "@/utils/render-profiler";
|
||||
import { buildDraftPanelDescriptor } from "@/panels/draft-panel-descriptor";
|
||||
import {
|
||||
type HostRuntimeConnectionStatus,
|
||||
getHostRuntimeConnectionStatusSince,
|
||||
useHostRuntimeClient,
|
||||
useHostRuntimeConnectionStatus,
|
||||
useHostRuntimeIsConnected,
|
||||
@@ -114,6 +119,10 @@ interface ChatAgentStateShape {
|
||||
lastError?: Agent["lastError"] | null;
|
||||
}
|
||||
|
||||
const RECONNECT_TOAST_DELAY_MS = 1_000;
|
||||
|
||||
const reconnectToastStateByServerId = new Map<string, ReconnectToastState>();
|
||||
|
||||
interface ChatAgentSelectedState extends ChatAgentStateShape {
|
||||
archivedAt: Date | null;
|
||||
requiresAttention: boolean;
|
||||
@@ -768,7 +777,7 @@ function ChatAgentContent({
|
||||
const streamViewRef = useRef<AgentStreamViewHandle>(null);
|
||||
const clearOnAgentBlurRef = useRef<() => void>(() => {});
|
||||
const wasPaneFocusedRef = useRef(isPaneFocused);
|
||||
const reconnectToastArmedRef = useRef(false);
|
||||
const reconnectToastPresentedRef = useRef(false);
|
||||
const initAttemptTokenRef = useRef(0);
|
||||
const routeBottomAnchorRequestRef = useRef<{
|
||||
routeKey: string;
|
||||
@@ -857,26 +866,72 @@ function ChatAgentContent({
|
||||
const { style: animatedKeyboardStyle } = useKeyboardShiftStyle({
|
||||
mode: "translate",
|
||||
});
|
||||
const shouldPresentReconnectToast =
|
||||
isPaneVisible && connectionStatus !== "online" && connectionStatus !== "idle";
|
||||
|
||||
useEffect(() => {
|
||||
if (connectionStatus === "online") {
|
||||
if (reconnectToastArmedRef.current) {
|
||||
reconnectToastArmedRef.current = false;
|
||||
if (connectionStatus === "online" || connectionStatus === "idle") {
|
||||
reconnectToastStateByServerId.delete(serverId);
|
||||
}
|
||||
|
||||
if (!shouldPresentReconnectToast) {
|
||||
if (reconnectToastPresentedRef.current) {
|
||||
reconnectToastPresentedRef.current = false;
|
||||
dismissToast();
|
||||
}
|
||||
return;
|
||||
}
|
||||
if (connectionStatus === "idle") {
|
||||
|
||||
const startedAt = getHostRuntimeConnectionStatusSince(serverId) ?? Date.now();
|
||||
const previousReconnectToastState = reconnectToastStateByServerId.get(serverId);
|
||||
const reconnectToastState = reconcileReconnectToastState(
|
||||
previousReconnectToastState,
|
||||
startedAt,
|
||||
);
|
||||
if (reconnectToastState !== previousReconnectToastState) {
|
||||
reconnectToastStateByServerId.set(serverId, reconnectToastState);
|
||||
}
|
||||
|
||||
if (reconnectToastState.presented) {
|
||||
if (!reconnectToastPresentedRef.current) {
|
||||
reconnectToastPresentedRef.current = true;
|
||||
toastApi.show(t("agentPanel.states.reconnecting"), {
|
||||
durationMs: null,
|
||||
icon: (
|
||||
<View
|
||||
accessible={false}
|
||||
testID="agent-reconnecting-status-dot"
|
||||
style={styles.reconnectingStatusDot}
|
||||
/>
|
||||
),
|
||||
testID: "agent-reconnecting-toast",
|
||||
});
|
||||
}
|
||||
return;
|
||||
}
|
||||
if (!reconnectToastArmedRef.current) {
|
||||
reconnectToastArmedRef.current = true;
|
||||
|
||||
const delayMs = Math.max(0, startedAt + RECONNECT_TOAST_DELAY_MS - Date.now());
|
||||
const timer = setTimeout(() => {
|
||||
if (reconnectToastStateByServerId.get(serverId) !== reconnectToastState) {
|
||||
return;
|
||||
}
|
||||
reconnectToastState.presented = true;
|
||||
reconnectToastPresentedRef.current = true;
|
||||
toastApi.show(t("agentPanel.states.reconnecting"), {
|
||||
durationMs: null,
|
||||
icon: (
|
||||
<View
|
||||
accessible={false}
|
||||
testID="agent-reconnecting-status-dot"
|
||||
style={styles.reconnectingStatusDot}
|
||||
/>
|
||||
),
|
||||
testID: "agent-reconnecting-toast",
|
||||
});
|
||||
}
|
||||
}, [connectionStatus, dismissToast, toastApi, t]);
|
||||
}, delayMs);
|
||||
|
||||
return () => clearTimeout(timer);
|
||||
}, [connectionStatus, dismissToast, serverId, shouldPresentReconnectToast, toastApi, t]);
|
||||
|
||||
const isArchivingCurrentAgent = Boolean(agentId && isArchivingAgent({ serverId, agentId }));
|
||||
|
||||
@@ -1726,6 +1781,12 @@ const styles = StyleSheet.create((theme) => ({
|
||||
fontSize: theme.fontSize.base,
|
||||
color: theme.colors.foregroundMuted,
|
||||
},
|
||||
reconnectingStatusDot: {
|
||||
width: 8,
|
||||
height: 8,
|
||||
borderRadius: 4,
|
||||
backgroundColor: theme.colors.palette.amber[500],
|
||||
},
|
||||
centerState: {
|
||||
flex: 1,
|
||||
alignItems: "center",
|
||||
|
||||
@@ -0,0 +1,17 @@
|
||||
import { describe, expect, it } from "vitest";
|
||||
import { reconcileReconnectToastState, type ReconnectToastState } from "./reconnect-toast-state";
|
||||
|
||||
describe("reconnect toast presentation state", () => {
|
||||
it("resets after the host recovers without a mounted agent panel", () => {
|
||||
const presented: ReconnectToastState = {
|
||||
connectionStatusStartedAt: 100,
|
||||
presented: true,
|
||||
};
|
||||
|
||||
expect(reconcileReconnectToastState(presented, 100)).toBe(presented);
|
||||
expect(reconcileReconnectToastState(presented, 200)).toEqual({
|
||||
connectionStatusStartedAt: 200,
|
||||
presented: false,
|
||||
});
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,18 @@
|
||||
export interface ReconnectToastState {
|
||||
connectionStatusStartedAt: number;
|
||||
presented: boolean;
|
||||
}
|
||||
|
||||
export function reconcileReconnectToastState(
|
||||
state: ReconnectToastState | undefined,
|
||||
connectionStatusStartedAt: number,
|
||||
): ReconnectToastState {
|
||||
if (state?.connectionStatusStartedAt === connectionStatusStartedAt) {
|
||||
return state;
|
||||
}
|
||||
|
||||
return {
|
||||
connectionStatusStartedAt,
|
||||
presented: false,
|
||||
};
|
||||
}
|
||||
@@ -1639,6 +1639,50 @@ describe("HostRuntimeStore", () => {
|
||||
store.syncHosts([]);
|
||||
});
|
||||
|
||||
it("tracks connection status transitions independently of agent panels", async () => {
|
||||
useHostRuntimeClock();
|
||||
const host = makeHost({
|
||||
connections: [
|
||||
{
|
||||
id: "direct:lan:6767",
|
||||
type: "directTcp",
|
||||
endpoint: "lan:6767",
|
||||
},
|
||||
],
|
||||
});
|
||||
const fakeClient = new FakeDaemonClient();
|
||||
fakeClient.setConnectionState({ status: "connected" });
|
||||
const store = new HostRuntimeStore({
|
||||
deps: {
|
||||
createClient: () => fakeClient as unknown as DaemonClient,
|
||||
connectToDaemon: async ({ host: hostProfile }) => ({
|
||||
client: fakeClient as unknown as DaemonClient,
|
||||
serverId: hostProfile.serverId,
|
||||
hostname: hostProfile.label ?? null,
|
||||
}),
|
||||
getClientId: async () => "cid_test_runtime",
|
||||
},
|
||||
});
|
||||
|
||||
store.syncHosts([host]);
|
||||
await fakeClient.waitForFetches(1);
|
||||
await waitForDirectoryReady(store, host.serverId);
|
||||
await vi.advanceTimersByTimeAsync(1_500);
|
||||
|
||||
const outageStartedAt = Date.now();
|
||||
fakeClient.setConnectionState({ status: "disconnected", reason: "transport closed" });
|
||||
expect(store.getConnectionStatusSince(host.serverId)).toBe(outageStartedAt);
|
||||
|
||||
await vi.advanceTimersByTimeAsync(500);
|
||||
expect(store.getConnectionStatusSince(host.serverId)).toBe(outageStartedAt);
|
||||
|
||||
const reconnectStartedAt = Date.now();
|
||||
fakeClient.setConnectionState({ status: "connected" });
|
||||
expect(store.getConnectionStatusSince(host.serverId)).toBe(reconnectStartedAt);
|
||||
|
||||
store.syncHosts([]);
|
||||
});
|
||||
|
||||
it("bootstraps agent directory subscription when host transitions online", async () => {
|
||||
const host = makeHost({
|
||||
connections: [
|
||||
|
||||
@@ -1358,6 +1358,7 @@ export class HostRuntimeStore {
|
||||
private hostRegistryStatus: HostRegistryStatus = "loading";
|
||||
private deps: HostRuntimeControllerDeps;
|
||||
private lastConnectionStatusByServer = new Map<string, HostRuntimeConnectionStatus>();
|
||||
private connectionStatusStartedAtByServer = new Map<string, number>();
|
||||
private directoryBootstrapInFlight = new Map<string, Promise<void>>();
|
||||
private queuedAgentDrainInFlight = new Set<string>();
|
||||
private directorySyncByServer = new Map<string, DirectorySync>();
|
||||
@@ -1593,6 +1594,7 @@ export class HostRuntimeStore {
|
||||
|
||||
rekeyMap(this.controllers, oldServerId, newServerId);
|
||||
rekeyMap(this.lastConnectionStatusByServer, oldServerId, newServerId);
|
||||
rekeyMap(this.connectionStatusStartedAtByServer, oldServerId, newServerId);
|
||||
rekeyMap(this.directoryBootstrapInFlight, oldServerId, newServerId);
|
||||
this.replicaCache.reconcileServerId(oldServerId, newServerId);
|
||||
this.directorySyncByServer.get(oldServerId)?.dispose();
|
||||
@@ -1956,6 +1958,7 @@ export class HostRuntimeStore {
|
||||
}
|
||||
this.controllers.delete(serverId);
|
||||
this.lastConnectionStatusByServer.delete(serverId);
|
||||
this.connectionStatusStartedAtByServer.delete(serverId);
|
||||
this.directoryBootstrapInFlight.delete(serverId);
|
||||
this.directorySyncByServer.get(serverId)?.dispose();
|
||||
this.directorySyncByServer.delete(serverId);
|
||||
@@ -1991,10 +1994,9 @@ export class HostRuntimeStore {
|
||||
markAgentError: (error) => controller.markAgentDirectorySyncError(error),
|
||||
}),
|
||||
);
|
||||
this.lastConnectionStatusByServer.set(
|
||||
host.serverId,
|
||||
controller.getSnapshot().connectionStatus,
|
||||
);
|
||||
const initialSnapshot = controller.getSnapshot();
|
||||
this.lastConnectionStatusByServer.set(host.serverId, initialSnapshot.connectionStatus);
|
||||
this.connectionStatusStartedAtByServer.set(host.serverId, Date.now());
|
||||
controller.subscribe(() => {
|
||||
const snapshot = controller.getSnapshot();
|
||||
this.syncSessionReplica(snapshot.serverId, snapshot);
|
||||
@@ -2035,6 +2037,7 @@ export class HostRuntimeStore {
|
||||
const controller = this.controllers.get(serverId);
|
||||
if (!controller) {
|
||||
this.lastConnectionStatusByServer.delete(serverId);
|
||||
this.connectionStatusStartedAtByServer.delete(serverId);
|
||||
this.directoryBootstrapInFlight.delete(serverId);
|
||||
return;
|
||||
}
|
||||
@@ -2049,6 +2052,14 @@ export class HostRuntimeStore {
|
||||
},
|
||||
}) ?? false;
|
||||
const previousStatus = this.lastConnectionStatusByServer.get(serverId);
|
||||
const statusChanged = previousStatus !== snapshot.connectionStatus;
|
||||
const isUnavailable =
|
||||
snapshot.connectionStatus !== "online" && snapshot.connectionStatus !== "idle";
|
||||
const wasUnavailable =
|
||||
previousStatus !== undefined && previousStatus !== "online" && previousStatus !== "idle";
|
||||
if (statusChanged && (!wasUnavailable || !isUnavailable)) {
|
||||
this.connectionStatusStartedAtByServer.set(serverId, Date.now());
|
||||
}
|
||||
this.lastConnectionStatusByServer.set(serverId, snapshot.connectionStatus);
|
||||
const didTransitionOnline =
|
||||
snapshot.connectionStatus === "online" && previousStatus !== "online";
|
||||
@@ -2160,6 +2171,10 @@ export class HostRuntimeStore {
|
||||
return this.controllers.get(serverId)?.getSnapshot() ?? null;
|
||||
}
|
||||
|
||||
getConnectionStatusSince(serverId: string): number | null {
|
||||
return this.connectionStatusStartedAtByServer.get(serverId) ?? null;
|
||||
}
|
||||
|
||||
getVersion(): number {
|
||||
return this.version;
|
||||
}
|
||||
@@ -2319,6 +2334,10 @@ export function getHostRuntimeStore(): HostRuntimeStore {
|
||||
return singletonHostRuntimeStore;
|
||||
}
|
||||
|
||||
export function getHostRuntimeConnectionStatusSince(serverId: string): number | null {
|
||||
return getHostRuntimeStore().getConnectionStatusSince(serverId);
|
||||
}
|
||||
|
||||
export function useHostRuntimeSnapshot(serverId: string): HostRuntimeSnapshot | null {
|
||||
const store = getHostRuntimeStore();
|
||||
return useSyncExternalStore(
|
||||
|
||||
Reference in New Issue
Block a user