Skip to content

AI Agents & MCPs & AI Workflow Automation • (~400 MCP servers for AI agents) • AI Automation / AI Agent with MCPs • AI Workflows & AI Agents • MCPs for AI Agents

refactor(chat): remove the reply-polling fallback that never ran (#17173)

Hazem Adel48dd853389ae
diff --git a/packages/web/src/features/chat/lib/use-chat.ts b/packages/web/src/features/chat/lib/use-chat.ts
index 4a65c8f8491..565efc4e7f8 100644
--- a/packages/web/src/features/chat/lib/use-chat.ts
+++ b/packages/web/src/features/chat/lib/use-chat.ts
@@ -16,7 +16,6 @@ import {
subagentProgressId,
SubagentProgressEvent,
} from '@activepieces/shared';
-import { useQuery } from '@tanstack/react-query';
import { t } from 'i18next';
import { useCallback, useEffect, useMemo, useRef, useState } from 'react';
import { toast } from 'sonner';
@@ -91,7 +90,6 @@ function restoreReceiptsIntoStore({
}
const MAX_FILE_SIZE = 10 * 1024 * 1024;
-const AGENT_POLL_INTERVAL_MS = 5_000;
const TOOL_GATES_WITHOUT_A_PIECE = new Set([
'ap_send_email',
'ap_test_flow',
@@ -192,16 +190,6 @@ function buildRunningTaskPart({
};
}
-function appendGatePart({
- messages,
- gate,
-}: {
- messages: ChatUIMessage[];
- gate: PendingGate;
-}): ChatUIMessage[] {
- return appendTrailingPart({ messages, part: buildGatePart(gate) });
-}
-
function appendRunningTaskParts({
messages,
toolCallMeta,
@@ -367,7 +355,6 @@ export function useAgentChat({
string | null
>(null);
const [isLoadingHistory, setIsLoadingHistory] = useState(false);
- const [isPollingForAgentReply, setIsPollingForAgentReply] = useState(false);
const [sendStatus, setSendStatus] = useState<SendStatus>({ type: 'idle' });
const sendStatusRef = useRef<SendStatus>({ type: 'idle' });
const onCreditsExhaustedRef = useRef(onCreditsExhausted);
@@ -681,9 +668,7 @@ export function useAgentChat({
}, [isStreamActive]);
const isStreaming =
- isStreamActive ||
- sendStatusRef.current.type === 'submitting' ||
- isPollingForAgentReply;
+ isStreamActive || sendStatusRef.current.type === 'submitting';
const isAwaitingResponse =
streamPhase === 'awaiting-stream' ||
@@ -753,7 +738,6 @@ export function useAgentChat({
commitInFlightTurn();
stopStream();
setOptimisticUserMessage(null);
- setIsPollingForAgentReply(false);
updateSendStatus({ type: 'cancelled' });
const convId = conversationIdRef.current;
if (convId) {
@@ -972,7 +956,6 @@ export function useAgentChat({
)
return;
stopStream();
- setIsPollingForAgentReply(false);
updateSendStatus({ type: 'idle' });
conversationIdRef.current = id;
setConversationIdState(id);
@@ -1059,59 +1042,6 @@ export function useAgentChat({
[stopStream, startStream, updateSendStatus, store, t],
);
- useQuery({
- queryKey: ['chat-agent-poll', conversationId],
- queryFn: async () => {
- if (!conversationId || conversationIdRef.current !== conversationId)
- return null;
- const [messagesResult, convResult] = await Promise.all([
- chatApi.getMessages(conversationId),
- chatApi.getConversation(conversationId),
- ]);
- if (conversationIdRef.current !== conversationId) return null;
- const mapped = chatUtils.mapHistoryToUIMessages(messagesResult.data);
- const current = persistedMessagesRef.current;
- // Never let a poll shrink the visible history — only apply growth or
- // in-place part updates, never a truncation.
- const hasChanged =
- mapped.length >= current.length &&
- (mapped.length !== current.length ||
- mapped.some((m, i) => m.parts.length !== current[i]?.parts.length));
- if (hasChanged) {
- setPersistedMessages(mapped);
- const restored = chatUtils.extractQuickRepliesFromHistory(mapped);
- applyQuickRepliesToStore({ setState: store.setState, data: restored });
- }
- if (convResult.status !== AgentConversationStatus.STREAMING) {
- setIsPollingForAgentReply(false);
- } else {
- const hasBlockingCard = chatStoreSelectors.hasBlockingCard({
- state: store.getState(),
- lastAssistantMessage: mapped[mapped.length - 1],
- });
- if (!hasBlockingCard) {
- const { data: gate } = await tryCatch(() =>
- chatApi.getPendingGate(conversationId),
- );
- if (gate && conversationIdRef.current === conversationId) {
- store.setState((prev) => ({
- toolCallMeta: {
- ...prev.toolCallMeta,
- ...buildToolCallMetaFromGate(gate),
- },
- }));
- setPersistedMessages((prev) =>
- appendGatePart({ messages: prev, gate }),
- );
- }
- }
- }
- return mapped;
- },
- enabled: isPollingForAgentReply && !isStreamActive,
- refetchInterval: AGENT_POLL_INTERVAL_MS,
- });
-
const setModelPick = useCallback(async (newPick: ChatModelPick) => {
modelPickRef.current = newPick;
setModelPickState(newPick);