]> git.giacomolli.uk - onechat/blobdiff - subagent_run.go
Queue external data for the next root turn
[onechat] / subagent_run.go
index e96975c90abd0cec2a59519b2bbcab18811ebcd4..ca45976758b2dfdf08addcb2df73711363c079ff 100644 (file)
@@ -177,11 +177,16 @@ func (r *SubagentRuns) create(ctx context.Context, note, task string, view []str
                return "", fmt.Errorf("create work directory: %w", err)
        }
 
-       return subagent.name, r.start(ctx, &SubagentRun{
+       err = r.start(ctx, &SubagentRun{
                subagent: subagent,
                view:     view,
                effort:   effort,
        })
+       if err != nil {
+               return subagent.name, fmt.Errorf("start created worker: %w", err)
+       }
+
+       return subagent.name, nil
 }
 
 // start runs run in the background and logs its start. Its context keeps the
@@ -210,11 +215,7 @@ func (r *SubagentRuns) start(ctx context.Context, run *SubagentRun) error {
                r.mutex.Unlock()
                run.cancel()
 
-               if err != nil {
-                       return fmt.Errorf("save running workers: %w", err)
-               }
-
-               return nil
+               return fmt.Errorf("save running workers: %w", err)
        }
 
        r.workers.Add(1)
@@ -369,7 +370,12 @@ func (r *SubagentRuns) chain(ctx context.Context, run *SubagentRun) (string, err
                },
        }
 
-       return chain.Run(ctx, input)
+       text, err := chain.Run(ctx, input)
+       if err != nil {
+               return text, fmt.Errorf("run worker chain: %w", err)
+       }
+
+       return text, nil
 }
 
 // take returns the messages of Tell that wait for a request of run, and removes
@@ -440,7 +446,12 @@ func (r *SubagentRuns) Resume(ctx context.Context) error {
        r.mutex.Lock()
        defer r.mutex.Unlock()
 
-       return r.save()
+       err = r.save()
+       if err != nil {
+               return fmt.Errorf("save resumed workers: %w", err)
+       }
+
+       return nil
 }
 
 // load reads the names of work.json. A missing file names none.