From 5fa41bd73ae57fa0d957541643f0bf9c64a53d8f Mon Sep 17 00:00:00 2001 From: Benjamin Schroth <68321970+schrothbn@users.noreply.github.com> Date: Thu, 1 May 2025 00:54:02 +0200 Subject: [PATCH] fix(core): Error in partial execution of vector stores (#15019) --- .../__tests__/rewire-graph.test.ts | 5 +++-- .../partial-execution-utils/rewire-graph.ts | 16 +++++++++------- 2 files changed, 12 insertions(+), 9 deletions(-) diff --git a/packages/core/src/execution-engine/partial-execution-utils/__tests__/rewire-graph.test.ts b/packages/core/src/execution-engine/partial-execution-utils/__tests__/rewire-graph.test.ts index 839650f6c0..77a939b212 100644 --- a/packages/core/src/execution-engine/partial-execution-utils/__tests__/rewire-graph.test.ts +++ b/packages/core/src/execution-engine/partial-execution-utils/__tests__/rewire-graph.test.ts @@ -93,14 +93,15 @@ describe('rewireGraph()', () => { expect(tool.rewireOutputLogTo).toBe(NodeConnectionTypes.AiTool); }); - it('fails when the tool has no incoming connections', () => { + it('should not rewire when the tool has no root', () => { const tool = createNodeData({ name: 'tool', type: 'n8n-nodes-base.ai-tool' }); const root = createNodeData({ name: 'root' }); const graph = new DirectedGraph(); graph.addNodes(root, tool); + const result = rewireGraph(tool, graph); - expect(() => rewireGraph(tool, graph)).toThrow(); + expect(result).toStrictEqual(graph); }); it('removes the root node from the graph', () => { diff --git a/packages/core/src/execution-engine/partial-execution-utils/rewire-graph.ts b/packages/core/src/execution-engine/partial-execution-utils/rewire-graph.ts index 51decae9a0..bda9d3830c 100644 --- a/packages/core/src/execution-engine/partial-execution-utils/rewire-graph.ts +++ b/packages/core/src/execution-engine/partial-execution-utils/rewire-graph.ts @@ -4,26 +4,28 @@ import { type INode, NodeConnectionTypes } from 'n8n-workflow'; import { type DirectedGraph } from './directed-graph'; export function rewireGraph(tool: INode, graph: DirectedGraph): DirectedGraph { - graph = graph.clone(); - const children = graph.getChildren(tool); + const modifiedGraph = graph.clone(); + const children = modifiedGraph.getChildren(tool); - a.ok(children.size > 0, 'Tool must be connected to a root node'); + if (children.size === 0) { + return graph; + } const rootNode = [...children][0]; a.ok(rootNode); - const allIncomingConnection = graph + const allIncomingConnection = modifiedGraph .getDirectParentConnections(rootNode) .filter((cn) => cn.type === NodeConnectionTypes.Main); tool.rewireOutputLogTo = NodeConnectionTypes.AiTool; for (const cn of allIncomingConnection) { - graph.addConnection({ from: cn.from, to: tool }); + modifiedGraph.addConnection({ from: cn.from, to: tool }); } - graph.removeNode(rootNode); + modifiedGraph.removeNode(rootNode); - return graph; + return modifiedGraph; }