diff --git a/go.mod b/go.mod index c15428265e..cf51e75013 100644 --- a/go.mod +++ b/go.mod @@ -18,7 +18,7 @@ require ( github.com/gptscript-ai/chat-completion-client v0.0.0-20250224164718-139cb4507b1d github.com/gptscript-ai/cmd v0.0.0-20250122115124-a3d65e9d2432 github.com/gptscript-ai/go-gptscript v0.9.6-0.20250314150104-8d1f06fa87a4 - github.com/gptscript-ai/gptscript v0.9.6-0.20250322192245-31ce029b1eb6 + github.com/gptscript-ai/gptscript v0.9.6-0.20250328171703-550d649b5fe1 github.com/liggitt/tabwriter v0.0.0-20181228230101-89fcab3d43de github.com/mhale/smtpd v0.8.3 github.com/obot-platform/kinm v0.0.0-20250307141751-3a6f13867f67 diff --git a/go.sum b/go.sum index 3f6206de3e..bf079447a2 100644 --- a/go.sum +++ b/go.sum @@ -299,8 +299,8 @@ github.com/gptscript-ai/cmd v0.0.0-20250122115124-a3d65e9d2432 h1:cJh/Hl1HFd1qLp github.com/gptscript-ai/cmd v0.0.0-20250122115124-a3d65e9d2432/go.mod h1:DJAo1xTht1LDkNYFNydVjTHd576TC7MlpsVRl3oloVw= github.com/gptscript-ai/go-gptscript v0.9.6-0.20250314150104-8d1f06fa87a4 h1:V30gwE9c6yEYQmWoKCvrfpGmsTTlEicHr5nGJZV4Uyk= github.com/gptscript-ai/go-gptscript v0.9.6-0.20250314150104-8d1f06fa87a4/go.mod h1:QvGPZoRuAiA8P5EzPI05kTrs+LZ0ipHywUGsKruSknw= -github.com/gptscript-ai/gptscript v0.9.6-0.20250322192245-31ce029b1eb6 h1:Y2LRTmdOgN30tfGOJ5HD/xdeXJGx2Q39w9TCQdXT5iU= -github.com/gptscript-ai/gptscript v0.9.6-0.20250322192245-31ce029b1eb6/go.mod h1:wQ9GU40Po6fSBEciAQI2kxeo32qK4DybbpD6bIOBPtM= +github.com/gptscript-ai/gptscript v0.9.6-0.20250328171703-550d649b5fe1 h1:AMtjmE+yY01McVzEGbQ3TZ6fFxuZh63zgs0xNUGWKDc= +github.com/gptscript-ai/gptscript v0.9.6-0.20250328171703-550d649b5fe1/go.mod h1:wQ9GU40Po6fSBEciAQI2kxeo32qK4DybbpD6bIOBPtM= github.com/gptscript-ai/tui v0.0.0-20250204145344-33cd15de4cee h1:70PHW6Xw70yNNZ5aX936XqcMLwNmfMZpCV3FCOGKpxE= github.com/gptscript-ai/tui v0.0.0-20250204145344-33cd15de4cee/go.mod h1:iwHxuueg2paOak7zIg0ESBWx7A0wIHGopAratbgaPNY= github.com/gregjones/httpcache v0.0.0-20180305231024-9cad4c3443a7 h1:pdN6V1QBWetyv/0+wjACpqVH+eVULgEjkurDLq3goeM= diff --git a/pkg/invoke/invoker.go b/pkg/invoke/invoker.go index c41c109269..2413ac889e 100644 --- a/pkg/invoke/invoker.go +++ b/pkg/invoke/invoker.go @@ -973,7 +973,7 @@ func (i *Invoker) stream(ctx context.Context, c kclient.WithWatch, thread *v1.Th go timeoutAfter(runCtx, cancelRun, timeout) if !isEphemeral(run) { // Don't watch thread abort for ephemeral runs - go watchThreadAbort(runCtx, c, thread, cancelRun) + go i.watchThreadAbort(runCtx, c, thread, cancelRun, runResp) } var ( @@ -1070,10 +1070,19 @@ func (i *Invoker) stream(ctx context.Context, c kclient.WithWatch, thread *v1.Th } } -func watchThreadAbort(ctx context.Context, c kclient.WithWatch, thread *v1.Thread, cancel context.CancelCauseFunc) { +func (i *Invoker) watchThreadAbort(ctx context.Context, c kclient.WithWatch, thread *v1.Thread, cancel context.CancelCauseFunc, run *gptscript.Run) { _, _ = wait.For(ctx, c, thread, func(thread *v1.Thread) (bool, error) { if thread.Spec.Abort { - cancel(fmt.Errorf("thread was aborted, cancelling run")) + // we should abort aggressive in the task so that the next step in task won't continue + if thread.Spec.WorkflowExecutionName != "" { + cancel(fmt.Errorf("thread was aborted, cancelling run")) + return true, nil + } + if err := i.gptClient.AbortRun(ctx, run); err != nil { + return false, err + } + // cancel the context after 30 seconds in case the abort doesn't work + go timeoutAfter(ctx, cancel, 30*time.Second) return true, nil } return false, nil