RAGFlow is an agent-native database: a Retrieval-Augmented Generation (RAG) engine that grew into context infrastructure.
Go agent-harnessagent-native-databaseagentic-aiagentic-retrievalagentic-searchaiai-agentscontext-enginecontext-engineeringcontext-managementharness-engineeringknowledge-compilationragretrieval-augmented-generationretrieval-harnesssearch-harness
Fix: Prevent the left-side handle of a node on the canvas from serving as a starting point for connections to other nodes. (#21019)
balibabu658095dd7498
diff --git a/web/src/pages/agent/canvas/node/agent-node.tsx b/web/src/pages/agent/canvas/node/agent-node.tsxindex fe102f73c7..9bf653d113 100644--- a/web/src/pages/agent/canvas/node/agent-node.tsx+++ b/web/src/pages/agent/canvas/node/agent-node.tsx@@ -63,6 +63,7 @@ function InnerAgentNode({type="target"position={Position.Top}isConnectable={false}+ isConnectableStart={false}id={NodeHandleId.AgentTop}className="!bg-accent-primary !size-2"></Handle>diff --git a/web/src/pages/agent/canvas/node/handle.tsx b/web/src/pages/agent/canvas/node/handle.tsxindex cd3ed06c7b..515610f8e2 100644--- a/web/src/pages/agent/canvas/node/handle.tsx+++ b/web/src/pages/agent/canvas/node/handle.tsx@@ -48,6 +48,12 @@ export function CommonHandle({return (<HandleContext.Provider value={value}><Handle+ // With ConnectionMode.Loose a drag may start from any handle and land+ // on any handle, so pin the direction here: a target handle never+ // starts a drag and a source handle never accepts one. Callers can+ // still override through props.+ isConnectableStart={props.type === 'target' ? false : undefined}+ isConnectableEnd={props.type === 'source' ? false : undefined}{...props}isConnectable={isConnectable && !readOnly}className={cn(@@ -96,6 +102,10 @@ export function LeftEndHandle({}: Omit<HandleProps, 'type' | 'position'>) {return (<Handle+ // A target handle must never start a drag: with ConnectionMode.Loose a+ // drag started here can land on another target handle, and xyflow then+ // records a flipped edge (drop node as source) that cannot render.+ isConnectableStart={false}isConnectable={isConnectable}className={cn('!bg-accent-primary !size-2', className)}id={NodeHandleId.End}diff --git a/web/src/pages/agent/hooks.test.tsx b/web/src/pages/agent/hooks.test.tsxnew file mode 100644index 0000000000..ac5e525377--- /dev/null+++ b/web/src/pages/agent/hooks.test.tsx@@ -0,0 +1,79 @@+import { renderHook } from '@testing-library/react';+import { PropsWithChildren } from 'react';+import { MemoryRouter } from 'react-router';+import { NodeHandleId, Operator } from './constant';+import { useValidateConnection } from './hooks';+import useGraphStore from './store';++const createNode = (id: string, label: Operator) => ({+ id,+ type: 'ragNode',+ position: { x: 0, y: 0 },+ data: {+ label,+ name: id,+ form: {},+ },+});++const wrapper = ({ children }: PropsWithChildren) => (+ <MemoryRouter>{children}</MemoryRouter>+);++describe('useValidateConnection', () => {+ beforeEach(() => {+ useGraphStore.setState({+ nodes: [+ createNode('Agent:a', Operator.Agent),+ createNode('CodeExec:b', Operator.Code),+ ],+ edges: [],+ });+ });++ const renderValidator = () =>+ renderHook(() => useValidateConnection(), { wrapper });++ it('allows a normal start -> end connection', () => {+ const { result } = renderValidator();++ expect(+ result.current({+ source: 'Agent:a',+ sourceHandle: NodeHandleId.Start,+ target: 'CodeExec:b',+ targetHandle: NodeHandleId.End,+ }),+ ).toBe(true);+ });++ // With ConnectionMode.Loose a drag started on a target handle and dropped+ // on another target handle is reported flipped (drop node as source) with+ // the "end" id on both sides; such an edge can never resolve its source+ // handle and renders as a ghost edge.+ it('rejects a flipped target -> target connection', () => {+ const { result } = renderValidator();++ expect(+ result.current({+ source: 'CodeExec:b',+ sourceHandle: NodeHandleId.End,+ target: 'Agent:a',+ targetHandle: NodeHandleId.End,+ }),+ ).toBe(false);+ });++ it('rejects a source -> source connection', () => {+ const { result } = renderValidator();++ expect(+ result.current({+ source: 'Agent:a',+ sourceHandle: NodeHandleId.Start,+ target: 'CodeExec:b',+ targetHandle: NodeHandleId.Start,+ }),+ ).toBe(false);+ });+});diff --git a/web/src/pages/agent/hooks.tsx b/web/src/pages/agent/hooks.tsxindex ed473bed33..31389307d0 100644--- a/web/src/pages/agent/hooks.tsx+++ b/web/src/pages/agent/hooks.tsx@@ -6,7 +6,7 @@ import { RAGFlowNodeType } from '@/interfaces/database/agent';import { get, lowerFirst, omit } from 'lodash';import { UseFormReturn } from 'react-hook-form';import { useTranslation } from 'react-i18next';-import { Operator, RestrictedUpstreamMap } from './constant';+import { NodeHandleId, Operator, RestrictedUpstreamMap } from './constant';import { useIsPipeline } from './hooks/use-is-pipeline';import useGraphStore, { RFState } from './store';import { buildCategorizeObjectFromList, replaceIdWithText } from './utils';@@ -172,6 +172,15 @@ export const useValidateConnection = () => {// node cannot connect to itselfconst isSelfConnected = connection.target === connection.source;+ // With ConnectionMode.Loose a drag can start on a target handle and+ // land on another target handle; xyflow then reports the flipped+ // connection (drop node as source, still carrying the "end" handle id).+ // Such a ghost edge can never resolve its source handle, so reject any+ // connection whose handle ids violate the start/end convention.+ const isHandleDirectionValid =+ connection.sourceHandle !== NodeHandleId.End &&+ connection.targetHandle !== NodeHandleId.Start;+// limit the connection between two nodes to only one connection line in one direction// const hasLine = edges.some(// (x) => x.source === connection.source && x.target === connection.target,@@ -179,6 +188,7 @@ export const useValidateConnection = () => {const ret =!isSelfConnected &&+ isHandleDirectionValid &&RestrictedUpstreamMap[getOperatorTypeFromId(connection.source,