Harden Harness runtime, persistence and execution for Hand
This commit is contained in:
1 parent
09c30fe2d5
commit
0972eed3ea
164 files changed
+15912
-506
No files matched your search
@@ -1,6 +1,10 @@
|
||||
package runtime
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
"github.com/sausheong/harness/session"
|
||||
"os"
|
||||
|
||||
"github.com/sausheong/harness/llm"
|
||||
@@ -51,3 +55,27 @@ func drainKickoffs(kickoffs map[string]chan kickoffResult) {
|
||||
<-ch
|
||||
}
|
||||
}
|
||||
|
||||
// persistKickoff reconciles one joined tool without rewriting a completed
|
||||
// result as cancelled. Persistence must outlive run cancellation so completed
|
||||
// output and image references are not lost when the provider fails.
|
||||
func (r *Runtime) persistKickoff(ctx context.Context, kp kickoffResult, thread *[]Message) error {
|
||||
persistCtx := context.WithoutCancel(ctx)
|
||||
callErr := r.Session.AppendContext(persistCtx, session.ToolCallEntry(kp.tc.ID, kp.tc.Name, kp.tc.Input))
|
||||
entry := session.ToolResultWithArtifactsEntry(kp.tc.ID, kp.result.Output, kp.result.Error, convertToolResultImages(kp.result.Images), resultArtifacts(kp.result))
|
||||
content := kp.result.Output
|
||||
if kp.result.Error != "" {
|
||||
content = "[error] " + kp.result.Error
|
||||
}
|
||||
if kp.aborted {
|
||||
entry = session.AbortedToolResultWithReasonEntry(kp.tc.ID, toolAbortReason(ctx))
|
||||
content = "[error] " + toolAbortReason(ctx)
|
||||
}
|
||||
resultErr := r.Session.AppendContext(persistCtx, entry)
|
||||
if thread != nil {
|
||||
r.kgMu.Lock()
|
||||
*thread = append(*thread, Message{Role: "assistant", Content: fmt.Sprintf("[tool: %s]\n%s", kp.tc.Name, string(kp.tc.Input))}, Message{Role: "user", Content: content})
|
||||
r.kgMu.Unlock()
|
||||
}
|
||||
return errors.Join(callErr, resultErr)
|
||||
}
|
||||
Reference in new issue
Block a user