From 476e15ab6743832d3d8273ad76df260e91b0e920 Mon Sep 17 00:00:00 2001 From: leex279 Date: Mon, 22 Sep 2025 13:42:39 +0200 Subject: [PATCH] fix: Correct ActiveOperationsResponse handling in useCrawlUrlV2 - Fixed missing count and timestamp fields in optimistic updates - Preserve all ActiveOperationsResponse fields when updating progress IDs - Fixed incorrect field comparison (source_id vs id) when replacing temp IDs - Added query invalidation for progress queries in v2 implementation - Ensures proper data shape consistency with backend API These fixes ensure that: 1. ActiveOperationsResponse always has required count/timestamp fields 2. Optimistic entities are correctly matched and updated with real IDs 3. Progress queries are properly refreshed after crawl starts --- .../features/knowledge/hooks/useKnowledgeQueries.ts | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/archon-ui-main/src/features/knowledge/hooks/useKnowledgeQueries.ts b/archon-ui-main/src/features/knowledge/hooks/useKnowledgeQueries.ts index 3729ff4b..93209cda 100644 --- a/archon-ui-main/src/features/knowledge/hooks/useKnowledgeQueries.ts +++ b/archon-ui-main/src/features/knowledge/hooks/useKnowledgeQueries.ts @@ -401,6 +401,8 @@ export function useCrawlUrlV2() { progressId: tempProgressId, } as ActiveOperation, ], + count: 1, + timestamp: new Date().toISOString(), }); } else { queryClient.setQueryData(progressKeys.active(), { @@ -416,6 +418,8 @@ export function useCrawlUrlV2() { } as ActiveOperation, ...(previousOperations.operations || []), ], + count: (previousOperations.count || 0) + 1, + timestamp: new Date().toISOString(), }); } @@ -429,7 +433,8 @@ export function useCrawlUrlV2() { if (context) { const activeOps = queryClient.getQueryData(progressKeys.active()); if (activeOps) { - const updated = { + const updated: ActiveOperationsResponse = { + ...activeOps, // Preserve count, timestamp, and any other fields operations: activeOps.operations.map((op) => op.progressId === context.tempProgressId ? { ...op, progressId: response.progressId } : op, ), @@ -446,7 +451,7 @@ export function useCrawlUrlV2() { const updated = { ...data, items: data.items.map((item) => - item.id === context.tempItemId ? { ...item, source_id: response.progressId } : item, + item.source_id === context.tempProgressId ? { ...item, source_id: response.progressId } : item, ), }; queryClient.setQueryData(qk, updated); @@ -454,6 +459,9 @@ export function useCrawlUrlV2() { } } + // Invalidate to get fresh data + queryClient.invalidateQueries({ queryKey: progressKeys.active() }); + // Return the response so caller can access progressId return response; },