X-Git-Url: https://git.giacomolli.uk/onechat/blobdiff_plain/bd7da3557dc7a17020931f5a49ed5007fa81a645..42b4acd4ba70d3c12da4513d139717e592eefe4a:/subagent_run.go?ds=inline diff --git a/subagent_run.go b/subagent_run.go index e96975c..ca45976 100644 --- a/subagent_run.go +++ b/subagent_run.go @@ -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.