@@ -10,6 +10,7 @@ import { hasAdminPermission } from '@/lib/permissions/utils'
1010import { processStreamingBlockLogs } from '@/lib/tokenization'
1111import { getEmailDomain } from '@/lib/urls/utils'
1212import { decryptSecret } from '@/lib/utils'
13+ import { getBlock } from '@/blocks'
1314import { db } from '@/db'
1415import { chat , environment as envTable , userStats , workflow } from '@/db/schema'
1516import { Executor } from '@/executor'
@@ -423,7 +424,22 @@ export async function executeWorkflowForChat(
423424
424425 // Prepare for execution, similar to use-workflow-execution.ts
425426 const mergedStates = mergeSubblockState ( blocks )
426- const currentBlockStates = Object . entries ( mergedStates ) . reduce (
427+
428+ const filteredStates = Object . entries ( mergedStates ) . reduce (
429+ ( acc , [ id , block ] ) => {
430+ const blockConfig = getBlock ( block . type )
431+ const isTriggerBlock = blockConfig ?. category === 'triggers'
432+
433+ // Skip trigger blocks during chat execution
434+ if ( ! isTriggerBlock ) {
435+ acc [ id ] = block
436+ }
437+ return acc
438+ } ,
439+ { } as typeof mergedStates
440+ )
441+
442+ const currentBlockStates = Object . entries ( filteredStates ) . reduce (
427443 ( acc , [ id , block ] ) => {
428444 acc [ id ] = Object . entries ( block . subBlocks ) . reduce (
429445 ( subAcc , [ key , subBlock ] ) => {
@@ -465,10 +481,20 @@ export async function executeWorkflowForChat(
465481 logger . warn ( `[${ requestId } ] Could not parse workflow variables:` , error )
466482 }
467483
468- // Create serialized workflow
484+ // Filter edges to exclude connections to/from trigger blocks (same as manual execution)
485+ const triggerBlockIds = Object . keys ( mergedStates ) . filter ( ( id ) => {
486+ const blockConfig = getBlock ( mergedStates [ id ] . type )
487+ return blockConfig ?. category === 'triggers'
488+ } )
489+
490+ const filteredEdges = edges . filter (
491+ ( edge ) => ! triggerBlockIds . includes ( edge . source ) && ! triggerBlockIds . includes ( edge . target )
492+ )
493+
494+ // Create serialized workflow with filtered blocks and edges
469495 const serializedWorkflow = new Serializer ( ) . serializeWorkflow (
470- mergedStates ,
471- edges ,
496+ filteredStates ,
497+ filteredEdges ,
472498 loops ,
473499 parallels ,
474500 true // Enable validation during execution
@@ -562,7 +588,7 @@ export async function executeWorkflowForChat(
562588 contextExtensions : {
563589 stream : true ,
564590 selectedOutputIds : selectedOutputIds . length > 0 ? selectedOutputIds : outputBlockIds ,
565- edges : edges . map ( ( e : any ) => ( {
591+ edges : filteredEdges . map ( ( e : any ) => ( {
566592 source : e . source ,
567593 target : e . target ,
568594 } ) ) ,
0 commit comments