Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: check for NotFoundInWorkspaceError to avoid transient errors #600

Merged
merged 1 commit into from
Nov 15, 2024
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
11 changes: 6 additions & 5 deletions pkg/controller/handlers/knowledgesource/knowledgesource.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down Expand Up @@ -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
}

Expand All @@ -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)
}
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion pkg/controller/handlers/knowledgesource/metadata.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down