fix: workflow onEndWithStream handles stream asynchronously (#518)

This commit is contained in:
shentongmartin 2025-08-04 11:58:34 +08:00 committed by GitHub
parent 08d1f6bf67
commit 3fe4031531
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 38 additions and 37 deletions

View File

@ -496,7 +496,7 @@ func (w *WorkflowHandler) OnEndWithStreamOutput(ctx context.Context, info *callb
return ctx return ctx
} }
// consumes the stream synchronously because the Exit node has already processed this stream synchronously. safego.Go(ctx, func() {
defer output.Close() defer output.Close()
fullOutput := make(map[string]any) fullOutput := make(map[string]any)
for { for {
@ -512,12 +512,12 @@ func (w *WorkflowHandler) OnEndWithStreamOutput(ctx context.Context, info *callb
logs.Errorf("workflow OnEndWithStreamOutput failed to receive stream output: %v", e) logs.Errorf("workflow OnEndWithStreamOutput failed to receive stream output: %v", e)
_ = w.OnError(ctx, info, e) _ = w.OnError(ctx, info, e)
return ctx return
} }
fullOutput, e = nodes.ConcatTwoMaps(fullOutput, chunk.(map[string]any)) fullOutput, e = nodes.ConcatTwoMaps(fullOutput, chunk.(map[string]any))
if e != nil { if e != nil {
logs.Errorf("failed to concat two maps: %v", e) logs.Errorf("failed to concat two maps: %v", e)
return ctx return
} }
} }
@ -538,6 +538,7 @@ func (w *WorkflowHandler) OnEndWithStreamOutput(ctx context.Context, info *callb
} }
} }
w.ch <- e w.ch <- e
})
return ctx return ctx
} }