mirror of
https://github.com/Abdulazizzn/n8n-enterprise-unlocked.git
synced 2025-12-16 17:46:45 +00:00
fix(core): Fix race condition in AI tool invocation with multiple items from the parent (#12169)
This commit is contained in:
committed by
GitHub
parent
57c6a6167d
commit
dce0c58f86
@@ -391,7 +391,8 @@ class AIParametersParser {
|
||||
description,
|
||||
schema,
|
||||
func: async (toolArgs: z.infer<typeof schema>) => {
|
||||
const context = this.options.contextFactory(this.runIndex, {});
|
||||
const currentRunIndex = this.runIndex++;
|
||||
const context = this.options.contextFactory(currentRunIndex, {});
|
||||
context.addInputData(NodeConnectionType.AiTool, [[{ json: toolArgs }]]);
|
||||
|
||||
try {
|
||||
@@ -402,7 +403,7 @@ class AIParametersParser {
|
||||
const mappedResults = result?.[0]?.flatMap((item) => item.json);
|
||||
|
||||
// Add output data to the context
|
||||
context.addOutputData(NodeConnectionType.AiTool, this.runIndex, [
|
||||
context.addOutputData(NodeConnectionType.AiTool, currentRunIndex, [
|
||||
[{ json: { response: mappedResults } }],
|
||||
]);
|
||||
|
||||
@@ -410,10 +411,8 @@ class AIParametersParser {
|
||||
return JSON.stringify(mappedResults);
|
||||
} catch (error) {
|
||||
const nodeError = new NodeOperationError(this.options.node, error as Error);
|
||||
context.addOutputData(NodeConnectionType.AiTool, this.runIndex, nodeError);
|
||||
context.addOutputData(NodeConnectionType.AiTool, currentRunIndex, nodeError);
|
||||
return 'Error during node execution: ' + nodeError.description;
|
||||
} finally {
|
||||
this.runIndex++;
|
||||
}
|
||||
},
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user