Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
76 changes: 64 additions & 12 deletions apps/http-backend/src/routes/userRoutes/executionRoutes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,23 +29,75 @@ execRouter.post('/node', userMiddleware, async(req: AuthRequest, res: Response)
if(nodeData){
const type = nodeData.AvailableNode.type
const config = dataSafe.data.Config ? dataSafe.data.Config : nodeData.config // for test api data prefered fist then config in db
console.log(`config and type: ${JSON.stringify(config)} & ${type}`)
// // console.log(`config and type: ${JSON.stringify(config)} & ${type}`)

const context = {
userId: req.user.sub,
config: config,
credentialId: nodeData.CredentialsID || config?.credentialId || ""
}

console.log(`Execution context: ${JSON.stringify(context)}`)
const executionResult = await ExecutionRegister.execute(type, context)

console.log(`Execution result: ${executionResult}`)

if(executionResult.success)
return res.status(statusCodes.ACCEPTED).json({
message: `${nodeData.name} node execution done` ,
data: executionResult
const result = await prismaClient.$transaction(async(tx)=>{
// // console.log(`Execution context: ${JSON.stringify(context)}`)
const workflowExecution = await tx.workflowExecution.create({
data:{
workflowId: nodeData.workflowId || "",
status: "Start",
startAt: new Date(),
metadata:{"isTesting": true},
}
})
const NodeExecution = await tx.nodeExecution.create({
data:{
status: "Start",
nodeId: nodeData.id,
workflowExecId: workflowExecution.id,
startedAt: new Date(),
inputData: context,
isTest: true
}
})
const executionResult = await ExecutionRegister.execute(type, context)


// console.log(`Execution result: ${executionResult}`)

if(executionResult.success){
await tx.nodeExecution.update({
where: { id: NodeExecution.id},
data:{
status: "Completed",
outputData: executionResult.output,
completedAt: new Date()
}
})
await tx.workflowExecution.update({
where: {id: workflowExecution.id},
data: {
status: "Completed",
completedAt: new Date()
}
})
return res.status(statusCodes.ACCEPTED).json({
message: `${nodeData.name} node execution done` ,
data: executionResult
})
}
Comment on lines +39 to +84

Copilot AI Apr 16, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The route sends an HTTP response from inside the Prisma $transaction callback, then execution continues after the transaction and a second response is sent (the 403 at the end). This will trigger “headers already sent” and can leave the transaction in an unclear state. Refactor to have the transaction return data/status (or throw), then send exactly one res.status(...).json(...) after the transaction resolves.

Copilot uses AI. Check for mistakes.
await tx.nodeExecution.update({
where: {id : NodeExecution.id},
data:{
status: "Failed",
completedAt: new Date(),
error: executionResult.error
}
})
await tx.workflowExecution.update({
where: {id: workflowExecution.id},
data:{
status: "Failed",
completedAt: new Date(),
error: executionResult.output

Copilot AI Apr 16, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

On failure, workflowExecution.error is being set to executionResult.output, but WorkflowExecution.error is a String in Prisma. If output is an object (common), this will throw at runtime and also loses the real error message. Use executionResult.error (and/or serialize output into metadata) when updating workflowExecution on failure.

Suggested change
error: executionResult.output
error: typeof executionResult.error === "string"
? executionResult.error
: JSON.stringify(executionResult.error ?? executionResult.output)

Copilot uses AI. Check for mistakes.
}
})
})

return res.status(statusCodes.FORBIDDEN).json({
Expand All @@ -57,7 +109,7 @@ execRouter.post('/node', userMiddleware, async(req: AuthRequest, res: Response)
})

}catch(e){
console.log("This is the error from executing node", e);
// console.log("This is the error from executing node", e);
return res.status(statusCodes.INTERNAL_SERVER_ERROR).json({
message: "Internal server Error from node execution ",
});
Expand Down
Loading