🪢 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 in-app agent activity poll from crashing render (#16571)
cursor[bot]8ea91dacac38
diff --git a/web/src/features/in-app-agent/lib/inAppAgentActivity.clienttest.ts b/web/src/features/in-app-agent/lib/inAppAgentActivity.clienttest.tsindex acc8903cb2..b250e96a3f 100644--- a/web/src/features/in-app-agent/lib/inAppAgentActivity.clienttest.ts+++ b/web/src/features/in-app-agent/lib/inAppAgentActivity.clienttest.ts@@ -6,8 +6,10 @@ import { InAppAgentRunStatus } from "@langfuse/shared";import {getInAppAgentActivityKey,+ getInAppAgentActivityRefetchInterval,getInAppAgentPendingNotificationCards,hasInFlightInAppAgentActivity,+ IN_APP_AGENT_ACTIVITY_POLL_INTERVAL_MS,markInAppAgentActivityDelivered,markInAppAgentConversationHandled,mergeInAppAgentReceipts,@@ -267,4 +269,28 @@ describe("in-app agent activity receipts", () => {]),).toBe(true);});++ it("does not throw from the poll interval helper when a conversation cannot be read", () => {+ const conversations = [+ {+ id: "c1",+ title: "c1",+ get latestRun(): InAppAgentConversationLatestRun {+ throw new SyntaxError("Invalid or unexpected token");+ },+ },+ ];++ expect(getInAppAgentActivityRefetchInterval(conversations)).toBe(false);+ expect(getInAppAgentActivityRefetchInterval(undefined)).toBe(false);+ expect(getInAppAgentActivityRefetchInterval({ pages: [] })).toBe(false);+ expect(+ getInAppAgentActivityRefetchInterval([+ conversation(+ "queued",+ latestRun({ id: "queued-run", status: InAppAgentRunStatus.QUEUED }),+ ),+ ]),+ ).toBe(IN_APP_AGENT_ACTIVITY_POLL_INTERVAL_MS);+ });});diff --git a/web/src/features/in-app-agent/lib/inAppAgentActivity.ts b/web/src/features/in-app-agent/lib/inAppAgentActivity.tsindex bc85cd871a..7a1fb02ba2 100644--- a/web/src/features/in-app-agent/lib/inAppAgentActivity.ts+++ b/web/src/features/in-app-agent/lib/inAppAgentActivity.ts@@ -375,6 +375,8 @@ export function getInAppAgentPendingNotificationCards(params: {* run on its own. Parked approvals wait on the user; `refetchOnWindowFocus`* is enough if another tab decides them.*/+export const IN_APP_AGENT_ACTIVITY_POLL_INTERVAL_MS = 4_000;+export function hasInFlightInAppAgentActivity(conversations: readonly InAppAgentActivityConversation[],): boolean {@@ -386,3 +388,26 @@ export function hasInFlightInAppAgentActivity();});}++/**+ * Interval for `useQuery({ refetchInterval })`. React Query invokes this+ * during observer construction (first render), so a throw becomes a+ * client-side exception and takes down the tree. Unknown snapshots and+ * unexpected read failures disable polling instead of crashing the page.+ */+export function getInAppAgentActivityRefetchInterval(+ conversations: unknown,+): number | false {+ try {+ if (!Array.isArray(conversations)) {+ return false;+ }+ return hasInFlightInAppAgentActivity(+ conversations as InAppAgentActivityConversation[],+ )+ ? IN_APP_AGENT_ACTIVITY_POLL_INTERVAL_MS+ : false;+ } catch {+ return false;+ }+}diff --git a/web/src/features/in-app-agent/lib/useInAppAgentActivity.ts b/web/src/features/in-app-agent/lib/useInAppAgentActivity.tsindex e8e03d423b..cd6d9f739c 100644--- a/web/src/features/in-app-agent/lib/useInAppAgentActivity.ts+++ b/web/src/features/in-app-agent/lib/useInAppAgentActivity.ts@@ -4,8 +4,8 @@ import useLocalStorage from "@/src/components/useLocalStorage";import {IN_APP_AGENT_ACTIVITY_LIST_LIMIT,getInAppAgentActivityReceiptsStorageKey,+ getInAppAgentActivityRefetchInterval,getInAppAgentDeliveredReceiptsStorageKey,- hasInFlightInAppAgentActivity,markInAppAgentActivityDelivered,markInAppAgentConversationHandled,mergeInAppAgentReceipts,@@ -20,8 +20,6 @@ import {} from "@/src/features/in-app-agent/lib/inAppAgentActivity";import { api } from "@/src/utils/api";-const ACTIVITY_POLL_INTERVAL_MS = 4_000;-const EMPTY_ACKNOWLEDGEMENTS: InAppAgentActivityAcknowledgement[] = [];/**@@ -64,9 +62,7 @@ export function useInAppAgentActivity(params: {{enabled: pollEnabled,refetchInterval: (query) =>- hasInFlightInAppAgentActivity(query.state.data?.conversations ?? [])- ? ACTIVITY_POLL_INTERVAL_MS- : false,+ getInAppAgentActivityRefetchInterval(query.state.data?.conversations),refetchIntervalInBackground: false,refetchOnWindowFocus: true,},