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
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -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=
Expand Down
15 changes: 12 additions & 3 deletions pkg/invoke/invoker.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand Down Expand Up @@ -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)
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we add a comment about why this is necessary?

Copy link
Contributor

Choose a reason for hiding this comment

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

I asked for the 30 second thing as a fail safe if the proper abort was to not work for some reason. And yeah add a comment about that.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

added a comment

return true, nil
}
return false, nil
Expand Down