Open-source Grok Bot alternative for named AI teammates. Local-first desktop, web, and mobile clients with per-bot tools, instructions, and memory. Independent fork of T3 Code.
fix(web): delay transient reconnect warnings (#5670)
t3-code[bot]ed886fe18148
diff --git a/apps/web/src/components/ChatView.logic.test.ts b/apps/web/src/components/ChatView.logic.test.tsindex 39285438d..5c026c94a 100644--- a/apps/web/src/components/ChatView.logic.test.ts+++ b/apps/web/src/components/ChatView.logic.test.ts@@ -6,7 +6,7 @@ import {ThreadId,TurnId,} from "@t3tools/contracts";-import { describe, expect, it } from "vite-plus/test";+import { afterEach, describe, expect, it, vi } from "vite-plus/test";import type { Thread, ThreadShell } from "../types";import {@@ -19,13 +19,16 @@ import {createLocalDispatchSnapshot,deriveComposerSendState,dismissBranchMismatchForSession,+ ENVIRONMENT_RECONNECT_WARNING_GRACE_MS,getStartedThreadModelChangeBlockReason,+ hasEnvironmentReconnectWarningGraceElapsed,hasServerAcknowledgedLocalDispatch,isBranchMismatchDismissedForSession,reconcileMountedTerminalThreadIds,reconcileRetainedMountedThreadIds,resolveThreadMetadataUpdateForNextTurn,resolveSendEnvMode,+ scheduleEnvironmentReconnectWarning,startNewThreadForProject,shouldShowBranchMismatchBanner,shouldWriteThreadErrorToCurrentServerThread,@@ -36,6 +39,42 @@ const projectId = ProjectId.make("project-1");const threadId = ThreadId.make("thread-1");const now = "2026-03-29T00:00:00.000Z";+describe("environment reconnect warning grace", () => {+ afterEach(() => vi.useRealTimers());++ it("shows a persistent reconnect after the grace period", () => {+ vi.useFakeTimers();+ const showWarning = vi.fn();++ scheduleEnvironmentReconnectWarning(showWarning);+ vi.advanceTimersByTime(ENVIRONMENT_RECONNECT_WARNING_GRACE_MS - 1);+ expect(showWarning).not.toHaveBeenCalled();++ vi.advanceTimersByTime(1);+ expect(showWarning).toHaveBeenCalledOnce();+ });++ it("cancels the warning when the connection recovers during the grace period", () => {+ vi.useFakeTimers();+ const showWarning = vi.fn();++ const cancel = scheduleEnvironmentReconnectWarning(showWarning);+ cancel();+ vi.advanceTimersByTime(ENVIRONMENT_RECONNECT_WARNING_GRACE_MS);++ expect(showWarning).not.toHaveBeenCalled();+ });++ it("does not reuse elapsed grace from another environment", () => {+ const anotherEnvironmentId = EnvironmentId.make("environment-remote");++ expect(hasEnvironmentReconnectWarningGraceElapsed(environmentId, environmentId)).toBe(true);+ expect(hasEnvironmentReconnectWarningGraceElapsed(anotherEnvironmentId, environmentId)).toBe(+ false,+ );+ });+});+function makeThread(overrides: Partial<Thread> = {}): Thread {return {id: threadId,diff --git a/apps/web/src/components/ChatView.logic.ts b/apps/web/src/components/ChatView.logic.tsindex 04b35fd45..60df1cd96 100644--- a/apps/web/src/components/ChatView.logic.ts+++ b/apps/web/src/components/ChatView.logic.ts@@ -25,9 +25,22 @@ import type { DraftThreadEnvMode } from "../composerDraftStore";export const LAST_INVOKED_SCRIPT_BY_PROJECT_KEY = "t3code:last-invoked-script-by-project";export const MAX_HIDDEN_MOUNTED_TERMINAL_THREADS = 10;export const MAX_HIDDEN_MOUNTED_PREVIEW_THREADS = 3;+export const ENVIRONMENT_RECONNECT_WARNING_GRACE_MS = 2_000;export const LastInvokedScriptByProjectSchema = Schema.Record(ProjectId, Schema.String);+export function scheduleEnvironmentReconnectWarning(showWarning: () => void): () => void {+ const timeoutId = globalThis.setTimeout(showWarning, ENVIRONMENT_RECONNECT_WARNING_GRACE_MS);+ return () => globalThis.clearTimeout(timeoutId);+}++export function hasEnvironmentReconnectWarningGraceElapsed(+ activeEnvironmentId: EnvironmentId | null,+ elapsedEnvironmentId: EnvironmentId | null,+): boolean {+ return activeEnvironmentId !== null && activeEnvironmentId === elapsedEnvironmentId;+}+export function startNewThreadForProject(projectRef: ScopedProjectRef | null,handleNewThread: (projectRef: ScopedProjectRef) => Promise<void>,diff --git a/apps/web/src/components/ChatView.tsx b/apps/web/src/components/ChatView.tsxindex cfbe1ac8d..8b510d457 100644--- a/apps/web/src/components/ChatView.tsx+++ b/apps/web/src/components/ChatView.tsx@@ -283,6 +283,8 @@ import {createLocalDispatchSnapshot,deriveComposerSendState,dismissBranchMismatchForSession,+ hasEnvironmentReconnectWarningGraceElapsed,+ scheduleEnvironmentReconnectWarning,hasServerAcknowledgedLocalDispatch,isBranchMismatchDismissedForSession,shouldShowBranchMismatchBanner,@@ -1733,6 +1735,24 @@ function ChatViewContent(props: ChatViewProps) {const activeEnvironmentConnectionPhase = activeEnvironment?.connection.phase ?? "available";const activeEnvironmentUnavailable =activeEnvironment !== null && activeEnvironmentConnectionPhase !== "connected";+ const activeReconnectingEnvironmentId =+ activeEnvironmentConnectionPhase === "connecting" ||+ activeEnvironmentConnectionPhase === "reconnecting"+ ? (activeEnvironment?.environmentId ?? null)+ : null;+ const [reconnectWarningGraceElapsedEnvironmentId, setReconnectWarningGraceElapsedEnvironmentId] =+ useState<EnvironmentId | null>(null);+ const reconnectWarningGraceElapsed = hasEnvironmentReconnectWarningGraceElapsed(+ activeReconnectingEnvironmentId,+ reconnectWarningGraceElapsedEnvironmentId,+ );+ useEffect(() => {+ setReconnectWarningGraceElapsedEnvironmentId(null);+ if (activeReconnectingEnvironmentId === null) return;+ return scheduleEnvironmentReconnectWarning(() =>+ setReconnectWarningGraceElapsedEnvironmentId(activeReconnectingEnvironmentId),+ );+ }, [activeReconnectingEnvironmentId]);const activeEnvironmentUnavailableLabel = activeEnvironment?.label ?? null;const activeEnvironmentUnavailableState = useMemo<EnvironmentUnavailableState | null>(() => {if (!activeEnvironmentUnavailable || !activeEnvironmentUnavailableLabel || !activeEnvironment) {@@ -1965,7 +1985,9 @@ function ChatViewContent(props: ChatViewProps) {// While an update runs, transient connect blips are expected (the server// restarts) and the update banner already shows progress. Hard failure// phases still surface so the Reconnect action stays reachable.- const suppressUnavailableBanner = updateRunning && environmentReconnecting;+ const suppressUnavailableBanner =+ environmentReconnecting &&+ (updateRunning || (!reconnectingThroughVersionSkew && !reconnectWarningGraceElapsed));if (activeEnvironmentUnavailableState && unavailableConnection && !suppressUnavailableBanner) {if (reconnectingThroughVersionSkew) {items.push({@@ -2093,6 +2115,7 @@ function ChatViewContent(props: ChatViewProps) {return items;}, [activeEnvironmentUnavailableState,+ reconnectWarningGraceElapsed,handleReconnectActiveEnvironment,navigate,setDismissedVersionMismatchKey,