From 35e077fd8b16021aa6ff697eb111f2d512a8b9dd Mon Sep 17 00:00:00 2001 From: Sergey Kozyrenko Date: Sat, 16 May 2026 23:26:44 +0700 Subject: [PATCH] fix(frontend): always refetch knowledgeDocuments on provider remount The Apollo client's global nextFetchPolicy is 'cache-first', so returning to /knowledges via SPA navigation would serve potentially stale cache. Subscriptions are now scoped to /knowledges* and detach on other pages, so changes from AI agents during flow runs would be missed until a full reload. Override nextFetchPolicy to keep cache-and-network for this query. Co-Authored-By: Claude Opus 4.7 (1M context) --- frontend/src/providers/knowledges-provider.tsx | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/frontend/src/providers/knowledges-provider.tsx b/frontend/src/providers/knowledges-provider.tsx index b73e3bff..1b02a53d 100644 --- a/frontend/src/providers/knowledges-provider.tsx +++ b/frontend/src/providers/knowledges-provider.tsx @@ -46,8 +46,13 @@ export const KnowledgesProvider = ({ children }: KnowledgesProviderProps) => { const shouldFetch = Boolean(authInfo && authInfo.type !== 'guest' && isAuthenticated()); + // Override the client's default `nextFetchPolicy: 'cache-first'`: since + // subscriptions are scoped to this provider, the cache can drift while the + // user is on other pages (AI agents write documents during flow runs). + // Re-mounting the provider on return to /knowledges should refresh. const { data, loading: isLoading } = useKnowledgeDocumentsQuery({ fetchPolicy: 'cache-and-network', + nextFetchPolicy: 'cache-and-network', skip: !shouldFetch, variables: { withContent: true }, });