Skip to content

🀯 LobeHub - Super-Agents on Your Team. Add super-agents to the chats your team already uses.They take on work by themselves and get better every week.

πŸ› fix(verify): avoid redundant report revalidation (#17006)

Innei3cae103466d3
diff --git a/src/features/Verify/hooks.test.ts b/src/features/Verify/hooks.test.ts
new file mode 100644
index 00000000000..0eee71061ae
--- /dev/null
+++ b/src/features/Verify/hooks.test.ts
@@ -0,0 +1,79 @@
+import { act, renderHook, waitFor } from '@testing-library/react';
+import type { PropsWithChildren } from 'react';
+import { createElement } from 'react';
+import type { Cache } from 'swr';
+import { SWRConfig } from 'swr';
+import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
+
+import { verifyService } from '@/services/verify';
+
+import { useVerifyReportBundle, useVerifyReportSummariesInfinite } from './hooks';
+
+const useSWRInfiniteMock = vi.hoisted(() => vi.fn());
+
+vi.mock('swr/infinite', () => ({ default: useSWRInfiniteMock }));
+
+const mockInfiniteResponse = (overrides: Record<string, unknown> = {}) => ({
+ data: undefined,
+ error: undefined,
+ isLoading: false,
+ isValidating: false,
+ mutate: vi.fn(),
+ setSize: vi.fn(),
+ size: 1,
+ ...overrides,
+});
+
+const createSWRWrapper = (cache: Cache) =>
+ function SWRTestWrapper({ children }: PropsWithChildren) {
+ return createElement(SWRConfig, { value: { provider: () => cache } }, children);
+ };
+
+describe('Verify data hooks', () => {
+ beforeEach(() => {
+ useSWRInfiniteMock.mockReset();
+ });
+
+ afterEach(() => {
+ vi.restoreAllMocks();
+ });
+
+ it('reuses a cached report bundle without revalidating after a remount', async () => {
+ const getReportBundle = vi.spyOn(verifyService, 'getReportBundle').mockResolvedValue(null);
+ const wrapper = createSWRWrapper(new Map());
+
+ const firstMount = renderHook(() => useVerifyReportBundle('run-1'), { wrapper });
+ await waitFor(() => expect(getReportBundle).toHaveBeenCalledTimes(1));
+ firstMount.unmount();
+
+ const secondMount = renderHook(() => useVerifyReportBundle('run-1'), { wrapper });
+ await act(() => new Promise((resolve) => setTimeout(resolve, 20)));
+
+ expect(secondMount.result.current.data).toBeNull();
+ expect(getReportBundle).toHaveBeenCalledTimes(1);
+ });
+
+ it('keeps loaded reports visible while SWR revalidates after a remount', () => {
+ useSWRInfiniteMock.mockReturnValue(
+ mockInfiniteResponse({
+ data: [{ items: [], nextCursor: null }],
+ isLoading: true,
+ isValidating: true,
+ }),
+ );
+
+ const { result } = renderHook(() => useVerifyReportSummariesInfinite(''));
+
+ expect(result.current.isLoadingInitial).toBe(false);
+ expect(result.current.isLoadingMore).toBe(false);
+ });
+
+ it('reports initial loading only before the first page is available', () => {
+ useSWRInfiniteMock.mockReturnValue(mockInfiniteResponse({ isLoading: true }));
+
+ const { result } = renderHook(() => useVerifyReportSummariesInfinite(''));
+
+ expect(result.current.isLoadingInitial).toBe(true);
+ expect(result.current.isLoadingMore).toBe(false);
+ });
+});
diff --git a/src/features/Verify/hooks.ts b/src/features/Verify/hooks.ts
index b5054f01603..4f6f66d0191 100644
--- a/src/features/Verify/hooks.ts
+++ b/src/features/Verify/hooks.ts
@@ -9,6 +9,11 @@ import type { VerifyReportSummaryPage } from '@/services/verify';
import { verifyService } from '@/services/verify';
const VERIFY_REPORT_PAGE_SIZE = 30;
+const VERIFY_REPORT_SWR_CONFIG = {
+ revalidateIfStale: false,
+ revalidateOnFocus: false,
+ revalidateOnReconnect: false,
+} as const;
/** Plan + rollup status for one Agent Run. Pass null operationId to skip. */
export const useVerifyState = (operationId: string | null) =>
@@ -24,8 +29,10 @@ export const useVerifyResults = (operationId: string | null) =>
/** Full standalone report bundle (run + report + results + evidence) by verifyRunId. */
export const useVerifyReportBundle = (verifyRunId: string | null) =>
- useClientDataSWR(verifyRunId ? verifyKeys.reportBundle(verifyRunId) : null, () =>
- verifyService.getReportBundle(verifyRunId!),
+ useClientDataSWR(
+ verifyRunId ? verifyKeys.reportBundle(verifyRunId) : null,
+ () => verifyService.getReportBundle(verifyRunId!),
+ VERIFY_REPORT_SWR_CONFIG,
);
/**
@@ -53,7 +60,7 @@ export const useVerifyReportSummariesInfinite = (q: string) => {
limit: VERIFY_REPORT_PAGE_SIZE,
q: query || undefined,
}),
- { revalidateFirstPage: false },
+ { ...VERIFY_REPORT_SWR_CONFIG, revalidateFirstPage: false },
);
// A new search term starts a fresh key series; collapse size back to 1 so we
@@ -73,11 +80,14 @@ export const useVerifyReportSummariesInfinite = (q: string) => {
const items = data?.flatMap((page) => page?.items ?? []) ?? [];
const lastLoadedPage = data?.findLast(Boolean);
const reachedEnd = lastLoadedPage ? lastLoadedPage.nextCursor === null : false;
+ const hasLoadedPages = data !== undefined;
- // A subsequent page is genuinely in flight only when it hasn't errored β€” an
- // errored page also leaves its slot undefined, but must not read as loading.
+ // Keep already-loaded rows visible while SWR revalidates after a focus/remount.
+ // A subsequent page is genuinely in flight only when the loaded page array has
+ // an unresolved tail slot; raw `isLoading` also covers first-load revalidation.
+ const isLoadingInitial = !error && isLoading && !hasLoadedPages;
const isLoadingMore =
- !error && (isLoading || (size > 0 && !!data && typeof data[size - 1] === 'undefined'));
+ !error && hasLoadedPages && size > 0 && typeof data[size - 1] === 'undefined';
// Pause the sentinel while an error is showing so it can't hot-loop the failed
// page; the panel offers a manual retry (`reload`) instead.
@@ -86,7 +96,7 @@ export const useVerifyReportSummariesInfinite = (q: string) => {
return {
error,
hasMore,
- isLoadingInitial: isLoading,
+ isLoadingInitial,
isLoadingMore,
isValidating,
items,
diff --git a/src/spa/router/desktopRouter.config.desktop.tsx b/src/spa/router/desktopRouter.config.desktop.tsx
index b2aef14a732..83ac0421c6e 100644
--- a/src/spa/router/desktopRouter.config.desktop.tsx
+++ b/src/spa/router/desktopRouter.config.desktop.tsx
@@ -20,7 +20,6 @@ import { agentDocumentRouteMeta } from '@/features/AgentDocumentPage/routeMeta';
import { taskRouteMeta, tasksRouteMeta } from '@/features/AgentTasks/routeMeta';
import { fleetRouteMeta } from '@/features/Fleet/routeMeta';
import { pageRouteMeta } from '@/features/Pages/routeMeta';
-import { verifyReportsRouteMeta, verifyRouteMeta } from '@/features/Verify/routeMeta';
import { workspaceHomeRouteMeta } from '@/features/Workspace/routeMeta';
import DesktopOnboarding from '@/routes/(desktop)/desktop-onboarding';
// Layouts β€” sync import (Electron local, no network overhead)
@@ -126,14 +125,10 @@ import { settingsRouteMeta } from '@/routes/(main)/settings/features/routeMeta';
import { ProviderDetailPage, ProviderLayout } from '@/routes/(main)/settings/provider';
import TaskDetailRoute from '@/routes/(main)/task/[taskId]';
import AllTasksPage from '@/routes/(main)/tasks';
-import VerifyWorkspace from '@/routes/(main)/verify';
-import VerifyEmptyDetail from '@/routes/(main)/verify/empty';
import SharePagePage from '@/routes/share/page/[id]';
import ShareTopicPage from '@/routes/share/t/[id]';
import ShareTopicLayout from '@/routes/share/t/[id]/_layout';
import { shareTopicRouteMeta } from '@/routes/share/t/[id]/routeMeta';
-import VerifyReportPage from '@/routes/verify/[runId]';
-import VerifyImPage from '@/routes/verify-im';
import { routeMeta } from '@/spa/router/routeMeta';
import { SettingsTabs } from '@/store/global/initialState';
import { ErrorBoundary, redirectElement } from '@/utils/router';
@@ -781,32 +776,6 @@ export const desktopRoutes: RouteObject[] = [
path: '/share/page',
},
- // Messenger verify route (outside main layout)
- {
- element: <VerifyImPage />,
- errorElement: <ErrorBoundary />,
- path: '/verify-im',
- },
-
- // Verify report workspace β€” standalone master-detail (outside main layout)
- {
- children: [
- {
- element: <VerifyEmptyDetail />,
- index: true,
- },
- {
- element: <VerifyReportPage />,
- handle: { meta: verifyRouteMeta },
- path: ':runId',
- },
- ],
- element: <VerifyWorkspace />,
- errorElement: <ErrorBoundary />,
- handle: { meta: verifyReportsRouteMeta },
- path: '/verify',
- },
-
// Devtools route (outside main layout, dev-only)
...(__DEV__
? [
diff --git a/src/spa/router/desktopRouter.sync.test.tsx b/src/spa/router/desktopRouter.sync.test.tsx
index 54e170548f6..df8b66272c0 100644
--- a/src/spa/router/desktopRouter.sync.test.tsx
+++ b/src/spa/router/desktopRouter.sync.test.tsx
@@ -14,7 +14,28 @@ const KNOWN_DIVERGENCES: Record<string, string> = {
'/desktop-onboarding': '/onboarding',
};
-const WEB_ONLY_PATHS = new Set(['/onboarding', '/onboarding/agent', '/onboarding/classic']);
+/**
+ * Web-only routes intentionally absent from Electron (no in-app entry points there).
+ * Paths are flat `path: '...'` literals extracted from both configs.
+ */
+const WEB_ONLY_PATHS = new Set([
+ '/onboarding',
+ '/onboarding/agent',
+ '/onboarding/classic',
+ // Verify report workspace + messenger link flow β€” web/CLI only
+ '/verify',
+ '/verify-im',
+ ':runId',
+]);
+
+/** Extra `index: true` routes present only on web (verify empty detail). */
+const WEB_ONLY_INDEX_DELTA = 1;
+
+/** handle.meta blobs present only on web. */
+const WEB_ONLY_HANDLE_METAS = new Set([
+ '{ meta: verifyRouteMeta }',
+ '{ meta: verifyReportsRouteMeta }',
+]);
function extractIndexCount(source: string) {
return [...source.matchAll(/index:\s*true/g)].length;
@@ -87,14 +108,16 @@ describe('desktopRouter config sync', () => {
expect(missingInSync, `Missing in desktop config: ${missingInSync.join(', ')}`).toEqual([]);
expect(extraInSync, `Extra in desktop config: ${extraInSync.join(', ')}`).toEqual([]);
expect(syncIndexCount, 'Desktop config index route count must match async config').toBe(
- asyncIndexCount,
+ asyncIndexCount - WEB_ONLY_INDEX_DELTA,
);
});
it('route handle.meta declarations must match between web and desktop configs', async () => {
const [asyncSource, syncSource] = await readDesktopRouterSources();
- const asyncMetas = extractHandleMetas(asyncSource);
+ const asyncMetas = extractHandleMetas(asyncSource).filter(
+ (meta) => !WEB_ONLY_HANDLE_METAS.has(meta),
+ );
const syncMetas = extractHandleMetas(syncSource);
expect(asyncMetas.length, 'Async config must declare at least one handle.meta').toBeGreaterThan(