Skip to content

Commit

Permalink
bug: no longer track synchronous runs in memory
Browse files Browse the repository at this point in the history
  • Loading branch information
ibuildthecloud committed Dec 7, 2024
1 parent fb55489 commit ae77e8a
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 33 deletions.
9 changes: 2 additions & 7 deletions pkg/controller/handlers/runs/runs.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ func (h *Handler) Resume(req router.Request, _ router.Response) error {

if run.Spec.PreviousRunName != "" {
if err := req.Get(&v1.Run{}, run.Namespace, run.Spec.PreviousRunName); apierrors.IsNotFound(err) {
run.Status.Error = fmt.Sprintf("run %s not found", run.Spec.PreviousRunName)
run.Status.Error = fmt.Sprintf("run %s not found: %s", run.Spec.PreviousRunName, run.Status.Error)
run.Status.State = gptscript.Error
return nil
} else if err != nil {
Expand All @@ -67,12 +67,7 @@ func (h *Handler) Resume(req router.Request, _ router.Response) error {
}

if run.Spec.Synchronous {
if h.invoker.IsSynchronousPending(run.Name) {
return nil
}
run.Status.Error = "run was interrupted most likely due to a system reset"
run.Status.State = gptscript.Error
return req.Client.Status().Update(req.Ctx, run)
return nil
}

return h.invoker.Resume(req.Ctx, req.Client, &thread, run)
Expand Down
26 changes: 0 additions & 26 deletions pkg/invoke/invoker.go
Original file line number Diff line number Diff line change
Expand Up @@ -328,18 +328,6 @@ type runOptions struct {
Timeout time.Duration
}

var (
synchronousPending = map[string]struct{}{}
synchrounousLock sync.Mutex
)

func (i *Invoker) IsSynchronousPending(runName string) bool {
synchrounousLock.Lock()
defer synchrounousLock.Unlock()
_, ok := synchronousPending[runName]
return ok
}

func (i *Invoker) createRun(ctx context.Context, c kclient.WithWatch, thread *v1.Thread, tool any, input string, opts runOptions) (_ *Response, retErr error) {
previousRunName := thread.Status.LastRunName
if opts.PreviousRunName != "" {
Expand Down Expand Up @@ -383,20 +371,6 @@ func (i *Invoker) createRun(ctx context.Context, c kclient.WithWatch, thread *v1
return nil, err
}

if opts.Synchronous {
synchrounousLock.Lock()
synchronousPending[run.Name] = struct{}{}
synchrounousLock.Unlock()
}

defer func() {
if retErr != nil {
synchrounousLock.Lock()
delete(synchronousPending, run.Name)
synchrounousLock.Unlock()
}
}()

if !thread.Spec.SystemTask {
err = retry.RetryOnConflict(retry.DefaultBackoff, func() error {
// Ensure that, regardless of which client is being used, we get an uncached version of the thread for updating.
Expand Down

0 comments on commit ae77e8a

Please sign in to comment.