🪢 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): stop storage-quota write failures from minting Sentry events (#15774)
Nikita Kabardin08f56494662e
diff --git a/web/src/components/useLocalStorage.clienttest.tsx b/web/src/components/useLocalStorage.clienttest.tsxnew file mode 100644index 0000000000..1017d9df29--- /dev/null+++ b/web/src/components/useLocalStorage.clienttest.tsx@@ -0,0 +1,56 @@+import { act, renderHook } from "@testing-library/react";+import { afterEach, describe, expect, it, vi } from "vitest";++import useLocalStorage from "@/src/components/useLocalStorage";++// Seam contract for preference persistence: a localStorage write that throws+// (quota exceeded, Safari private mode) must not propagate an exception and+// must not log at error level — the Sentry console integration turns+// console.error into events (the QuotaExceededError issue family).+describe("useLocalStorage", () => {+ afterEach(() => {+ vi.restoreAllMocks();+ localStorage.clear();+ });++ it("persists the value when the write succeeds", () => {+ const { result } = renderHook(() =>+ useLocalStorage("test-pref-key", "initial"),+ );++ act(() => {+ result.current[1]("updated");+ });++ expect(result.current[0]).toBe("updated");+ expect(localStorage.getItem("test-pref-key")).toBe(+ JSON.stringify("updated"),+ );+ });++ it("does not throw and warns (not errors) when the write fails", () => {+ const { result } = renderHook(() =>+ useLocalStorage("test-pref-key", "initial"),+ );++ const warnSpy = vi.spyOn(console, "warn").mockImplementation(() => {});+ const errorSpy = vi.spyOn(console, "error").mockImplementation(() => {});+ vi.spyOn(Storage.prototype, "setItem").mockImplementation(() => {+ throw new DOMException(+ "Failed to execute 'setItem' on 'Storage'",+ "QuotaExceededError",+ );+ });++ expect(() => {+ act(() => {+ result.current[1]("updated");+ });+ }).not.toThrow();++ // The in-memory state still updates; only persistence is skipped.+ expect(result.current[0]).toBe("updated");+ expect(warnSpy).toHaveBeenCalled();+ expect(errorSpy).not.toHaveBeenCalled();+ });+});diff --git a/web/src/components/useLocalStorage.tsx b/web/src/components/useLocalStorage.tsxindex 1bfd80db67..33a1e4e363 100644--- a/web/src/components/useLocalStorage.tsx+++ b/web/src/components/useLocalStorage.tsx@@ -40,7 +40,7 @@ function useLocalStorage<T>(// Parse stored value if it exists, otherwise use initial valuereturn stored ? (JSON.parse(stored) as T) : initialValue;} catch (error) {- console.error("Error reading from local storage", error);+ console.warn("Error reading from local storage", error);return initialValue;}});@@ -55,7 +55,7 @@ function useLocalStorage<T>(localStorage.setItem(localStorageKey, stringified);return stringified;} catch (error) {- console.error("Error writing to local storage", error);+ console.warn("Error writing to local storage", error);return null;}},@@ -63,7 +63,7 @@ function useLocalStorage<T>(try {localStorage.removeItem(localStorageKey);} catch (error) {- console.error("Error clearing local storage", error);+ console.warn("Error clearing local storage", error);}},}),@@ -93,7 +93,7 @@ function useLocalStorage<T>(try {setValue(e.newValue ? (JSON.parse(e.newValue) as T) : initialValue);} catch (error) {- console.error("Error parsing storage change", error);+ console.warn("Error parsing storage change", error);}}};@@ -110,7 +110,7 @@ function useLocalStorage<T>(: initialValue,);} catch (error) {- console.error("Error parsing custom event", error);+ console.warn("Error parsing custom event", error);}}};diff --git a/web/src/components/useSessionStorage.tsx b/web/src/components/useSessionStorage.tsxindex dcc8f9503d..371c2c9b44 100644--- a/web/src/components/useSessionStorage.tsx+++ b/web/src/components/useSessionStorage.tsx@@ -30,7 +30,7 @@ function useSessionStorage<T>(const storedValue = sessionStorage.getItem(sessionStorageKey);return storedValue ? (JSON.parse(storedValue) as T) : initialValue;} catch (error) {- console.error("Error reading from session storage", error);+ console.warn("Error reading from session storage", error);return initialValue;}});@@ -40,7 +40,7 @@ function useSessionStorage<T>(sessionStorage.removeItem(sessionStorageKey);setValue(initialValue);} catch (error) {- console.error("Error clearing session storage", error);+ console.warn("Error clearing session storage", error);}};@@ -49,7 +49,7 @@ function useSessionStorage<T>(try {sessionStorage.setItem(sessionStorageKey, JSON.stringify(value));} catch (error) {- console.error("Error writing to session storage", error);+ console.warn("Error writing to session storage", error);}}, [sessionStorageKey, value]);diff --git a/web/src/features/column-visibility/hooks/useColumnOrder.ts b/web/src/features/column-visibility/hooks/useColumnOrder.tsindex 35843e3584..d3b9e8560c 100644--- a/web/src/features/column-visibility/hooks/useColumnOrder.ts+++ b/web/src/features/column-visibility/hooks/useColumnOrder.ts@@ -11,7 +11,7 @@ const readStoredColumnOrder = (localStorageKey: string): string[] => {const storedValue = localStorage.getItem(localStorageKey);return storedValue ? JSON.parse(storedValue) : [];} catch (error) {- console.error("Error reading from local storage", error);+ console.warn("Error reading from local storage", error);return [];}};@@ -49,7 +49,7 @@ const hasRunMigration = (versionKey: string): boolean => {try {return localStorage.getItem(versionKey) !== null;} catch (error) {- console.error("Error reading migration flag from local storage", error);+ console.warn("Error reading migration flag from local storage", error);return true;}};@@ -61,7 +61,7 @@ const markMigrationRun = (versionKey: string): void => {try {localStorage.setItem(versionKey, "1");} catch (error) {- console.error("Error writing migration flag to local storage", error);+ console.warn("Error writing migration flag to local storage", error);}};diff --git a/web/src/features/filters/hooks/useKeyedSessionStorageState.ts b/web/src/features/filters/hooks/useKeyedSessionStorageState.tsindex 224ea25ec7..f149252ebd 100644--- a/web/src/features/filters/hooks/useKeyedSessionStorageState.ts+++ b/web/src/features/filters/hooks/useKeyedSessionStorageState.ts@@ -11,7 +11,7 @@ function readSessionStorageValue<T>(params: {const storedValue = sessionStorage.getItem(storageKey);return storedValue ? (JSON.parse(storedValue) as T) : fallback;} catch (error) {- console.error("Error reading from session storage", error);+ console.warn("Error reading from session storage", error);return fallback;}}@@ -48,7 +48,7 @@ export function useKeyedSessionStorageState<T>(try {sessionStorage.setItem(storageKey, JSON.stringify(state.value));} catch (error) {- console.error("Error writing to session storage", error);+ console.warn("Error writing to session storage", error);}}, [state.key, state.value, storageKey]);@@ -76,7 +76,7 @@ export function useKeyedSessionStorageState<T>(try {sessionStorage.removeItem(storageKey);} catch (error) {- console.error("Error clearing session storage", error);+ console.warn("Error clearing session storage", error);}}diff --git a/web/src/features/search-bar/store/observedMetadataStore.clienttest.ts b/web/src/features/search-bar/store/observedMetadataStore.clienttest.tsindex a79155404b..95d44fb379 100644--- a/web/src/features/search-bar/store/observedMetadataStore.clienttest.ts+++ b/web/src/features/search-bar/store/observedMetadataStore.clienttest.ts@@ -1,4 +1,4 @@-import { describe, expect, it } from "vitest";+import { describe, expect, it, vi } from "vitest";import {mergeIntoProject,@@ -240,4 +240,40 @@ describe("useObservedMetadataStore", () => {"routing.queue": { type: "string", values: ["billing"] },});});++ // The persisted map is a best-effort cache: a full/blocked localStorage+ // (quota exceeded, Safari private mode) must not throw into the React+ // effect that records paths, and must not log at error level (the console+ // integration turns console.error into Sentry events).+ it("does not throw or console.error when the localStorage write fails", () => {+ useObservedMetadataStore.setState({ byProject: {} });+ const setItemSpy = vi+ .spyOn(Storage.prototype, "setItem")+ .mockImplementation(() => {+ throw new DOMException(+ "Failed to execute 'setItem' on 'Storage'",+ "QuotaExceededError",+ );+ });+ const warnSpy = vi.spyOn(console, "warn").mockImplementation(() => {});+ const errorSpy = vi.spyOn(console, "error").mockImplementation(() => {});++ try {+ expect(() =>+ useObservedMetadataStore+ .getState()+ .actions.recordPaths("proj-quota", paths({ a: { type: "number" } })),+ ).not.toThrow();+ // The in-memory state still updates; only persistence is skipped.+ expect(+ useObservedMetadataStore.getState().byProject["proj-quota"]?.paths,+ ).toEqual({ a: { type: "number" } });+ expect(warnSpy).toHaveBeenCalled();+ expect(errorSpy).not.toHaveBeenCalled();+ } finally {+ setItemSpy.mockRestore();+ warnSpy.mockRestore();+ errorSpy.mockRestore();+ }+ });});diff --git a/web/src/features/search-bar/store/observedMetadataStore.ts b/web/src/features/search-bar/store/observedMetadataStore.tsindex 56ba2d6c29..441be6879f 100644--- a/web/src/features/search-bar/store/observedMetadataStore.ts+++ b/web/src/features/search-bar/store/observedMetadataStore.ts@@ -43,6 +43,35 @@ const noopStorage: StateStorage = {removeItem: () => {},};+// localStorage can throw (quota exceeded, Safari private mode). This map is a+// best-effort cache, so a failed write must not throw into the React effect+// that recorded the paths. console.warn, not console.error — error-level logs+// become Sentry events via the console integration.+const safeLocalStorage: StateStorage = {+ getItem: (name) => {+ try {+ return window.localStorage.getItem(name);+ } catch (error) {+ console.warn("Error reading from local storage", error);+ return null;+ }+ },+ setItem: (name, value) => {+ try {+ window.localStorage.setItem(name, value);+ } catch (error) {+ console.warn("Error writing to local storage", error);+ }+ },+ removeItem: (name) => {+ try {+ window.localStorage.removeItem(name);+ } catch (error) {+ console.warn("Error clearing local storage", error);+ }+ },+};+type ProjectMetadataPaths = {/** Observed top-level key → stored type + sample values (see StoredKeyInfo). */paths: Record<string, StoredKeyInfo>;@@ -159,7 +188,7 @@ export const useObservedMetadataStore = create<ObservedMetadataState>()(version: 2,// Hydrates from localStorage on the client; no-op during SSR.storage: createJSONStorage(() =>- typeof window !== "undefined" ? window.localStorage : noopStorage,+ typeof window !== "undefined" ? safeLocalStorage : noopStorage,),// Persist only data, never the actions object.partialize: (state) => ({ byProject: state.byProject }),