From cea53931f74ef7d2b33f7f2104c1b969cd49a649 Mon Sep 17 00:00:00 2001 From: Soumyadas15 Date: Mon, 19 May 2025 10:43:53 +0530 Subject: [PATCH 1/2] chore(dev): second attempt to fix billing checks --- .../(dashboard)/agents/[threadId]/page.tsx | 43 +++++++++---------- 1 file changed, 20 insertions(+), 23 deletions(-) diff --git a/frontend/src/app/(dashboard)/agents/[threadId]/page.tsx b/frontend/src/app/(dashboard)/agents/[threadId]/page.tsx index 336af2a9..e7ead8b5 100644 --- a/frontend/src/app/(dashboard)/agents/[threadId]/page.tsx +++ b/frontend/src/app/(dashboard)/agents/[threadId]/page.tsx @@ -1013,38 +1013,35 @@ export default function ThreadPage({ } }, [project?.account_id, billingStatusQuery]); - // Check billing when agent status changes useEffect(() => { - const previousStatus = previousAgentStatus.current; + let timeoutId: NodeJS.Timeout; + const shouldCheckBilling = + project?.account_id && + (initialLoadCompleted.current || + (messagesLoadedRef.current && !isLoading) || + (previousAgentStatus.current === 'running' && agentStatus === 'idle')); - // Check if agent just completed (status changed from running to idle) - if (previousStatus === 'running' && agentStatus === 'idle') { - checkBillingLimits(); + if (shouldCheckBilling) { + timeoutId = setTimeout(() => { + checkBillingLimits(); + }, 500); } - // Store current status for next comparison previousAgentStatus.current = agentStatus; - }, [agentStatus, checkBillingLimits]); - // Check billing on initial load - useEffect(() => { - if (project?.account_id && initialLoadCompleted.current) { - console.log('Checking billing status on page load'); - checkBillingLimits(); - } - }, [project?.account_id, checkBillingLimits, initialLoadCompleted]); - - // Check billing after messages loaded - useEffect(() => { - if (messagesLoadedRef.current && project?.account_id && !isLoading) { - console.log('Checking billing status after messages loaded'); - checkBillingLimits(); - } + return () => { + if (timeoutId) { + clearTimeout(timeoutId); + } + }; + // eslint-disable-next-line react-hooks/exhaustive-deps }, [ - messagesLoadedRef.current, - checkBillingLimits, project?.account_id, + initialLoadCompleted.current, + messagesLoadedRef.current, isLoading, + agentStatus, + checkBillingLimits ]); // Check for debug mode in URL on initial load and when URL changes From f89d97568d3803309d8ae953c94682e578662920 Mon Sep 17 00:00:00 2001 From: Soumyadas15 Date: Mon, 19 May 2025 11:24:02 +0530 Subject: [PATCH 2/2] chore(dev): cleanup useeffect deps --- frontend/src/app/(dashboard)/agents/[threadId]/page.tsx | 3 --- 1 file changed, 3 deletions(-) diff --git a/frontend/src/app/(dashboard)/agents/[threadId]/page.tsx b/frontend/src/app/(dashboard)/agents/[threadId]/page.tsx index e7ead8b5..e1c9a80d 100644 --- a/frontend/src/app/(dashboard)/agents/[threadId]/page.tsx +++ b/frontend/src/app/(dashboard)/agents/[threadId]/page.tsx @@ -1034,11 +1034,8 @@ export default function ThreadPage({ clearTimeout(timeoutId); } }; - // eslint-disable-next-line react-hooks/exhaustive-deps }, [ project?.account_id, - initialLoadCompleted.current, - messagesLoadedRef.current, isLoading, agentStatus, checkBillingLimits