Record run input directory and retry failed runs with original inputs

This commit is contained in:
2026-10-09 14:23:21 +01:00
parent 42600f6961
commit 6bd0e28ce6
19 changed files with 507 additions and 22 deletions
+19 -2
View File
@@ -4,6 +4,7 @@ import (
"context"
"fmt"
"log"
"maps"
"os"
"path/filepath"
"strings"
@@ -44,7 +45,7 @@ func newRunner(ctx context.Context, s *pipeline.Store) (*runner, error) {
return &runner{ctx: ctx, store: s, active: map[int64]context.CancelFunc{}}, nil
}
func (r *runner) start(request protocol.Message) (*protocol.RunDetail, error) {
func (r *runner) start(request protocol.Message, retryOf ...int64) (*protocol.RunDetail, error) {
if request.Version <= 0 || request.RequestKey == "" || len(request.RequestKey) > 128 {
return nil, fmt.Errorf("an explicit version and request key are required")
}
@@ -97,9 +98,11 @@ func (r *runner) start(request protocol.Message) (*protocol.RunDetail, error) {
return nil, fmt.Errorf("write path must stay within the run directory")
}
}
request.Input = maps.Clone(request.Input)
if request.Input == nil {
request.Input = map[string]any{}
}
request.Input["pwd"] = workspace
if prompt, ok := request.Input["prompt"].(string); !ok || strings.TrimSpace(prompt) == "" {
return nil, fmt.Errorf("a nonempty user prompt is required in input.prompt")
}
@@ -149,7 +152,7 @@ func (r *runner) start(request protocol.Message) (*protocol.RunDetail, error) {
return nil, fmt.Errorf("another run is active; inspect it before starting more work")
}
}
id, created, err := r.store.CreateRun(r.ctx, d, request.RequestKey, workspace, request.AllowTools, request.WritePaths, request.Input)
id, created, err := r.store.CreateRun(r.ctx, d, request.RequestKey, workspace, request.AllowTools, request.WritePaths, request.Input, retryOf...)
if err != nil {
return nil, err
}
@@ -167,6 +170,20 @@ func (r *runner) start(request protocol.Message) (*protocol.RunDetail, error) {
return r.store.GetRun(r.ctx, id)
}
func (r *runner) retry(request protocol.Message) (*protocol.RunDetail, error) {
if request.RunID <= 0 {
return nil, fmt.Errorf("retry requires a positive run ID")
}
original, err := r.store.GetRun(r.ctx, request.RunID)
if err != nil {
return nil, err
}
if original.Status != "failed" {
return nil, fmt.Errorf("only failed runs can be retried (run %d is %s)", original.ID, original.Status)
}
return r.start(protocol.Message{PipelineID: original.PipelineID, Version: original.Version, RequestKey: request.RequestKey, Workspace: original.Workspace, Input: original.Input, AllowTools: original.AllowTools, WritePaths: original.WritePaths}, original.ID)
}
func (r *runner) cancel(id int64) error {
r.mu.Lock()
defer r.mu.Unlock()