Skip to content

RAGFlow is an agent-native database: a Retrieval-Augmented Generation (RAG) engine that grew into context infrastructure.

Fix: Agent: Clicking multiple times to view the version history and then clicking the initial version causes an error. (#19674)

balibabu7f8ac34fa829
diff --git a/web/src/hooks/use-agent-request.ts b/web/src/hooks/use-agent-request.ts
index 1b94330f71..212814ce8b 100644
--- a/web/src/hooks/use-agent-request.ts
+++ b/web/src/hooks/use-agent-request.ts
@@ -119,6 +119,10 @@ export const AgentKeys = {
: ([AgentApiAction.FetchAgentTags, canvasCategory] as const),
detail: (agentId?: string) =>
[AgentApiAction.FetchAgentDetail, agentId] as const,
+ versionList: (agentId?: string) =>
+ [AgentApiAction.FetchVersionList, agentId] as const,
+ version: (agentId?: string, versionId?: string) =>
+ [AgentApiAction.FetchVersion, agentId, versionId] as const,
};
export const useFetchAgentTemplates = () => {
@@ -548,6 +552,14 @@ export const useSetAgent = (
queryClient.invalidateQueries({
queryKey: AgentKeys.list(),
});
+ // Every save can prune the oldest unpublished versions server-side,
+ // so the version history list must refetch even when autosave skips
+ // detail invalidation.
+ if (agentId) {
+ queryClient.invalidateQueries({
+ queryKey: AgentKeys.versionList(agentId),
+ });
+ }
if (!agentId) {
queryClient.invalidateQueries({
queryKey: AgentKeys.filters(),
@@ -779,7 +791,7 @@ export const useFetchVersionList = () => {
const { data, isFetching: loading } = useQuery<
Array<{ created_at: string; title: string; id: string; release?: boolean }>
>({
- queryKey: [AgentApiAction.FetchVersionList],
+ queryKey: AgentKeys.versionList(id),
initialData: [],
gcTime: 0,
queryFn: async () => {
@@ -797,26 +809,44 @@ export const useFetchVersion = (
): {
data?: IFlow;
loading: boolean;
+ isError: boolean;
} => {
const { id } = useParams();
- const { data, isFetching: loading } = useQuery({
- queryKey: [AgentApiAction.FetchVersion, id, version_id],
+ const {
+ data,
+ isFetching: loading,
+ isError,
+ } = useQuery({
+ queryKey: AgentKeys.version(id, version_id),
initialData: undefined,
gcTime: 0,
+ // A pruned version never recovers on retry, and each attempt would
+ // re-fire the global error notification.
+ retry: false,
enabled: !!id && !!version_id,
queryFn: async () => {
if (!id || !version_id) return undefined;
- const { data } = await agentService.fetchVersion({
- agentId: id,
- versionId: version_id,
- });
+ // The dialog renders its own error state, so suppress the global
+ // notification whose "no permission" wording misleads here.
+ const { data } = await agentService.fetchVersion(
+ {
+ agentId: id,
+ versionId: version_id,
+ skipGlobalErrorNotification: true,
+ },
+ true,
+ );
+
+ if (data?.code !== 0) {
+ throw new Error(data?.message);
+ }
return data?.data ?? undefined;
},
});
- return { data, loading };
+ return { data, loading, isError };
};
export const useFetchAgentLog = (searchParams: IAgentLogsRequest) => {
diff --git a/web/src/locales/en.ts b/web/src/locales/en.ts
index 8ba565aab5..fc44bd4cb5 100644
--- a/web/src/locales/en.ts
+++ b/web/src/locales/en.ts
@@ -3293,6 +3293,7 @@ This delimiter is used to split the input text into several text pieces echo of
details: 'Version details',
dsl: 'DSL',
download: 'Download',
+ loadFailed: 'Failed to load the version; it may have been deleted',
version: 'Version',
select: 'No version selected',
},
diff --git a/web/src/locales/zh.ts b/web/src/locales/zh.ts
index 46b7bde72f..0b63dbd520 100644
--- a/web/src/locales/zh.ts
+++ b/web/src/locales/zh.ts
@@ -2389,6 +2389,7 @@ NER:使用 spaCy NER 和基于规则的关键词提取来抽取 Entities 和 R
version: {
details: '版本详情',
download: '下载',
+ loadFailed: '版本加载失败,该版本可能已被删除',
version: '版本',
},
cite: '引用',
diff --git a/web/src/pages/agent/version-dialog/index.tsx b/web/src/pages/agent/version-dialog/index.tsx
index ef97e895a8..d32ec75417 100644
--- a/web/src/pages/agent/version-dialog/index.tsx
+++ b/web/src/pages/agent/version-dialog/index.tsx
@@ -38,7 +38,11 @@ export function VersionDialog({
const { t } = useTranslation();
const { data, loading } = useFetchVersionList();
const [selectedId, setSelectedId] = useState<string>('');
- const { data: agent, loading: versionLoading } = useFetchVersion(selectedId);
+ const {
+ data: agent,
+ loading: versionLoading,
+ isError: versionLoadFailed,
+ } = useFetchVersion(selectedId);
const { page, pageSize, onPaginationChange, pagedList } =
useClientPagination(data);
@@ -56,11 +60,13 @@ export function VersionDialog({
}
}, [agent?.dsl, agent?.title]);
+ // Keep the current selection across list refreshes; only fall back to the
+ // newest version when the selected one was pruned server-side.
useEffect(() => {
- if (data.length > 0) {
+ if (data.length > 0 && !data.some((x) => x.id === selectedId)) {
setSelectedId(data[0].id);
}
- }, [data]);
+ }, [data, selectedId]);
return (
<Dialog open onOpenChange={hideModal}>
@@ -96,6 +102,10 @@ export function VersionDialog({
<div className="relative flex-1 ">
{versionLoading ? (
<Spin className="top-1/2" />
+ ) : versionLoadFailed ? (
+ <div className="h-full flex items-center justify-center text-sm text-text-secondary">
+ {t('flow.version.loadFailed')}
+ </div>
) : (
<Card className="h-full">
<CardContent className="h-full p-5 flex flex-col">