Skip to content

Commit 513aa56

Browse files
committed
Fix: gracefully abort thread using sdk
Signed-off-by: Daishan Peng <daishan@acorn.io>
1 parent 8ebf5ae commit 513aa56

File tree

2 files changed

+8
-3
lines changed

2 files changed

+8
-3
lines changed

go.mod

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ go 1.24.0
55
replace (
66
github.com/obot-platform/obot/apiclient => ./apiclient
77
github.com/obot-platform/obot/logger => ./logger
8+
9+
github.com/gptscript-ai/gptscript => ../gptscript
810
)
911

1012
require (

pkg/invoke/invoker.go

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -973,7 +973,7 @@ func (i *Invoker) stream(ctx context.Context, c kclient.WithWatch, thread *v1.Th
973973
go timeoutAfter(runCtx, cancelRun, timeout)
974974
if !isEphemeral(run) {
975975
// Don't watch thread abort for ephemeral runs
976-
go watchThreadAbort(runCtx, c, thread, cancelRun)
976+
go i.watchThreadAbort(runCtx, c, thread, cancelRun, runResp)
977977
}
978978

979979
var (
@@ -1070,10 +1070,13 @@ func (i *Invoker) stream(ctx context.Context, c kclient.WithWatch, thread *v1.Th
10701070
}
10711071
}
10721072

1073-
func watchThreadAbort(ctx context.Context, c kclient.WithWatch, thread *v1.Thread, cancel context.CancelCauseFunc) {
1073+
func (i *Invoker) watchThreadAbort(ctx context.Context, c kclient.WithWatch, thread *v1.Thread, cancel context.CancelCauseFunc, run *gptscript.Run) {
10741074
_, _ = wait.For(ctx, c, thread, func(thread *v1.Thread) (bool, error) {
10751075
if thread.Spec.Abort {
1076-
cancel(fmt.Errorf("thread was aborted, cancelling run"))
1076+
if err := i.gptClient.AbortRun(ctx, run); err != nil {
1077+
return false, err
1078+
}
1079+
go timeoutAfter(ctx, cancel, 30*time.Second)
10771080
return true, nil
10781081
}
10791082
return false, nil

0 commit comments

Comments
 (0)