From 0c64d17381d3bdb5857c9e89db19f7137bbb83dd Mon Sep 17 00:00:00 2001 From: Donnie Adams Date: Fri, 15 Nov 2024 08:14:12 -0500 Subject: [PATCH] fix: check for NotFoundInWorkspaceError to avoid transient errors Signed-off-by: Donnie Adams --- .../handlers/knowledgesource/knowledgesource.go | 11 ++++++----- pkg/controller/handlers/knowledgesource/metadata.go | 2 +- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/pkg/controller/handlers/knowledgesource/knowledgesource.go b/pkg/controller/handlers/knowledgesource/knowledgesource.go index 8aee9ac30..4815e30ae 100644 --- a/pkg/controller/handlers/knowledgesource/knowledgesource.go +++ b/pkg/controller/handlers/knowledgesource/knowledgesource.go @@ -66,14 +66,15 @@ func safeStatusSave(ctx context.Context, c kclient.Client, source *v1.KnowledgeS } func (k *Handler) saveProgress(ctx context.Context, c kclient.Client, source *v1.KnowledgeSource, thread *v1.Thread, complete bool) error { files, syncMetadata, err := k.getMetadata(ctx, source, thread) - if err != nil { + if err != nil || syncMetadata == nil { return err } + apply := apply.New(c) if !complete { apply = apply.WithNoPrune() } - if err := apply.Apply(ctx, source, files...); err != nil { + if err = apply.Apply(ctx, source, files...); err != nil { return err } @@ -226,7 +227,7 @@ func (k *Handler) Sync(req router.Request, _ router.Response) error { source.Status.SyncState = types.KnowledgeSourceStateSyncing source.Status.ThreadName = task.Thread.Name source.Status.RunName = task.Run.Name - if err := req.Client.Status().Update(req.Ctx, source); err != nil { + if err = req.Client.Status().Update(req.Ctx, source); err != nil { return err } @@ -242,7 +243,7 @@ forLoop: break forLoop } case <-ticker.C: - if err := k.saveProgress(req.Ctx, req.Client, source, thread, false); err != nil { + if err = k.saveProgress(req.Ctx, req.Client, source, thread, false); err != nil { // Ignore these errors, hopefully transient log.Errorf("failed to get files for knowledgesource [%s]: %v", source.Name, err) } @@ -251,7 +252,7 @@ forLoop: _, taskErr := task.Result(req.Ctx) - if err := k.saveProgress(req.Ctx, req.Client, source, thread, taskErr == nil); err != nil { + if err = k.saveProgress(req.Ctx, req.Client, source, thread, taskErr == nil); err != nil { log.Errorf("failed to save files for knowledgesource [%s]: %v", source.Name, err) if taskErr == nil { taskErr = err diff --git a/pkg/controller/handlers/knowledgesource/metadata.go b/pkg/controller/handlers/knowledgesource/metadata.go index 7eb32c363..62da7b583 100644 --- a/pkg/controller/handlers/knowledgesource/metadata.go +++ b/pkg/controller/handlers/knowledgesource/metadata.go @@ -47,7 +47,7 @@ func (k *Handler) getMetadata(ctx context.Context, source *v1.KnowledgeSource, t data, err := k.gptClient.ReadFileInWorkspace(ctx, ".metadata.json", gptscript.ReadFileInWorkspaceOptions{ WorkspaceID: thread.Status.WorkspaceID, }) - if errNotFound := new(gptscript.ErrNotFound); errors.As(err, &errNotFound) { + if errNotFound := new(gptscript.NotFoundInWorkspaceError); errors.As(err, &errNotFound) { return nil, nil, nil } else if err != nil { return nil, nil, fmt.Errorf("failed to read metadata.json: %w", err)