🪢 Open source agent evals & observability: Trace, evaluate, and improve LLM applications with one open platform.
TypeScript analyticsautogenevaluationlangchainlarge-language-modelsllama-indexllmllm-evaluationllm-observabilityllmopsmonitoringobservabilityopen-sourceopenaiplaygroundprompt-engineeringprompt-managementself-hostedycombinator
fix(web): drop stale-version toast in favor of the update banner (#16422)
Nikita Kabardincbf4539fb7fb
diff --git a/web/src/features/notifications/showVersionUpdateToast.tsx b/web/src/features/notifications/showVersionUpdateToast.tsxdeleted file mode 100644index 6a0014459b..0000000000--- a/web/src/features/notifications/showVersionUpdateToast.tsx+++ /dev/null@@ -1,38 +0,0 @@-import { Button } from "@/src/components/ui/button";-import { toast } from "sonner";--export const showVersionUpdateToast = () => {- toast.custom(- () => (- <div className="flex justify-between">- <div className="flex min-w-[300px] flex-1 flex-col gap-2">- <div className="flex items-center gap-2">- <div className="text-foreground/70 m-0 text-sm leading-tight font-bold">- We have released a new version of Langfuse. Please refresh your- browser to get the latest update.- </div>- </div>- <Button- variant="outline"- size="sm"- className="text-foreground/50"- onClick={() => {- window.location.reload();- }}- >- Refresh page- </Button>- </div>- </div>- ),- {- duration: Infinity,- style: {- padding: "1rem",- borderRadius: "0.5rem",- border: "1px solid hsl(var(--border))",- backgroundColor: "hsl(var(--border))",- },- },- );-};diff --git a/web/src/utils/api.clienttest.ts b/web/src/utils/api.clienttest.tsindex 9da363702c..8b39e14dd6 100644--- a/web/src/utils/api.clienttest.ts+++ b/web/src/utils/api.clienttest.ts@@ -4,6 +4,7 @@ import { TRPCClientError } from "@trpc/client";import { vi } from "vitest";import {EXPECTED_TRPC_ERROR_CODES,+ captureBuildId,fetchWithParseErrorStatus,getTrpcErrorCode,getTrpcErrorFingerprint,@@ -16,12 +17,17 @@ import {reportTrpcErrorWithoutToast,} from "@/src/utils/api";-const { captureExceptionMock, addBreadcrumbMock, trpcErrorToastMock } =- vi.hoisted(() => ({- captureExceptionMock: vi.fn(),- addBreadcrumbMock: vi.fn(),- trpcErrorToastMock: vi.fn(),- }));+const {+ captureExceptionMock,+ addBreadcrumbMock,+ trpcErrorToastMock,+ showVersionUpdateToastMock,+} = vi.hoisted(() => ({+ captureExceptionMock: vi.fn(),+ addBreadcrumbMock: vi.fn(),+ trpcErrorToastMock: vi.fn(),+ showVersionUpdateToastMock: vi.fn(),+}));vi.mock("@sentry/nextjs", () => ({captureException: captureExceptionMock,@@ -32,6 +38,12 @@ vi.mock("@/src/utils/trpcErrorToast", () => ({trpcErrorToast: trpcErrorToastMock,}));+// Tripwire for the deleted `showVersionUpdateToast` path: 400/404 plus a+// mismatched `x-build-id` must not be remapped to a refresh toast.+vi.mock("@/src/features/notifications/showVersionUpdateToast", () => ({+ showVersionUpdateToast: showVersionUpdateToastMock,+}));+/** A JSON.parse SyntaxError annotated with the HTTP status it was parsed* from, as produced by `fetchWithParseErrorStatus`. */const parseErrorWithStatus = (message: string, status: number) => {@@ -645,3 +657,61 @@ describe("reportNonTrpcError", () => {expect(options.extra).toEqual({ context: "delete-organization" });});});++describe("400/404 tRPC errors must not be remapped to a version-update toast", () => {+ let warnSpy: ReturnType<typeof vi.spyOn>;++ beforeEach(() => {+ captureExceptionMock.mockClear();+ addBreadcrumbMock.mockClear();+ trpcErrorToastMock.mockClear();+ showVersionUpdateToastMock.mockClear();+ warnSpy = vi.spyOn(console, "warn").mockImplementation(() => {});+ vi.stubEnv("NEXT_PUBLIC_BUILD_ID", "running-build");+ });++ afterEach(() => {+ warnSpy.mockRestore();+ vi.unstubAllEnvs();+ });++ it("classifies a 400 even when x-build-id differs from the running build", () => {+ // Evaluators (and any other page) can legitimately 400 while HTML and API+ // are served by different builds. The version-update banner is the only+ // mismatch UX; this seam must still classify the error.+ captureBuildId(+ new Response("", { headers: { "x-build-id": "other-build" } }),+ );++ reportTrpcErrorWithoutToast(+ trpcServerError({+ code: "BAD_REQUEST",+ httpStatus: 400,+ path: "evals.allConfigs",+ }),+ "evals",+ );++ expect(showVersionUpdateToastMock).not.toHaveBeenCalled();+ expect(captureExceptionMock).toHaveBeenCalledTimes(1);+ });++ it("classifies a 404 NOT_FOUND as expected even when build ids differ", () => {+ captureBuildId(+ new Response("", { headers: { "x-build-id": "other-build" } }),+ );++ reportTrpcErrorWithoutToast(+ trpcServerError({+ code: "NOT_FOUND",+ httpStatus: 404,+ path: "evals.byId",+ }),+ "evals",+ );++ expect(showVersionUpdateToastMock).not.toHaveBeenCalled();+ expect(captureExceptionMock).not.toHaveBeenCalled();+ expect(addBreadcrumbMock).toHaveBeenCalledTimes(1);+ });+});diff --git a/web/src/utils/api.ts b/web/src/utils/api.tsindex e09e6678ff..2855ae567f 100644--- a/web/src/utils/api.ts+++ b/web/src/utils/api.ts@@ -23,7 +23,6 @@ import { type inferRouterInputs, type inferRouterOutputs } from "@trpc/server";import { observable } from "@trpc/server/observable";import superjson from "superjson";import { env } from "@/src/env.mjs";-import { showVersionUpdateToast } from "@/src/features/notifications/showVersionUpdateToast";import { versionUpdateStore } from "@/src/features/version-update/versionUpdateStore";import { type AppRouter } from "@/src/server/api/root";import { reportError } from "@/src/utils/reportError";@@ -59,10 +58,6 @@ export const getPathnameWithoutBasePath = () => {return pathname;};-// global build id used to compare versions to show refresh toast on stale cache hit serving deprecated files-let buildId: string | null = null;--const CLIENT_STALE_CACHE_CODES = [404, 400];const REPORTED_FAILED_FETCH_MESSAGE = /^failed to fetch(?: \([^)]+\))?$/i;// Cache to store hashes of recently shown errors (client-side only)@@ -340,16 +335,8 @@ const handleTrpcError = (error: unknown, shouldSilenceError = false) => {const httpStatus: number =typeof error.data?.httpStatus === "number" ? error.data.httpStatus : 500;- if (CLIENT_STALE_CACHE_CODES.includes(httpStatus)) {- if (- !!buildId &&- !!process.env.NEXT_PUBLIC_BUILD_ID &&- buildId !== process.env.NEXT_PUBLIC_BUILD_ID- ) {- showVersionUpdateToast();- return;- }- }+ // Version mismatch UX is owned by VersionUpdateBanner (fed by+ // buildIdLink / versionUpdateStore). 400/404 here are real API errors.if (isExpectedTrpcClientError(error)) {// Expected, user-facing states (a missing/forbidden resource, an expired@@ -446,16 +433,15 @@ export const reportTrpcErrorWithoutToast = (};// Reads the `x-build-id` response header (the build id serving this response)-// and records it: the module-level `buildId` still drives the legacy-// stale-cache toast, and the version-update store drives the persistent reload-// banner (see src/features/version-update). Called on EVERY response — success+// and feeds the version-update store that drives VersionUpdateBanner+// (see src/features/version-update). Called on EVERY response — success// and error — so a mismatch is detected on the first response after a deploy,-// not only when a stale chunk 404s.-const captureBuildId = (response: unknown) => {+// not only when a stale chunk 404s. Exported so tests can inject an observed+// build id without going through the tRPC link.+export const captureBuildId = (response: unknown) => {if (!(response instanceof Response)) return;const observed = response.headers.get("x-build-id");if (!observed) return;- buildId = observed;versionUpdateStore.reportObservedBuildId(observed);};