Add shared live run graphs, debugging, editor choice and draft cleanup

This commit is contained in:
2026-10-09 19:17:43 +01:00
parent 9b8afc874f
commit 0f80ff4e95
33 changed files with 1162 additions and 72 deletions
+10
View File
@@ -4,9 +4,11 @@ import (
"bytes"
"context"
"encoding/json"
"fmt"
"git.a-wan.net/alan/pipelines/internal/cli"
"git.a-wan.net/alan/pipelines/internal/pipeline"
"git.a-wan.net/alan/pipelines/internal/protocol"
"git.a-wan.net/alan/pipelines/internal/runinspect"
"git.a-wan.net/alan/pipelines/internal/stage"
"net/http/httptest"
"os"
@@ -61,6 +63,14 @@ func TestCLIHeadlessRunInspectionCancellationAndRPC(t *testing.T) {
if response.RunDetail.Workspace != cwd || response.RunDetail.Input["pwd"] != cwd {
t.Fatal("CLI did not use invocation directory", response.RunDetail.Workspace, cwd)
}
debugOutput, err := run("debug", fmt.Sprint(id), "--json")
if err != nil {
t.Fatal("CLI debug query failed", err)
}
var investigation runinspect.Debug
if err := json.Unmarshal([]byte(debugOutput), &investigation); err != nil || investigation.RunID != id || investigation.Workspace != cwd || !strings.Contains(investigation.Prompt, "inspect "+fmt.Sprint(id)+" --json") {
t.Fatal("debug did not retrieve active run context", investigation, err)
}
output, err = run("run", "workflow", "exact task", "--yes", "--json", "--request-key", "same-key")
if err != nil {
t.Fatal(err)
+57
View File
@@ -0,0 +1,57 @@
package server
import (
"context"
"path/filepath"
"strings"
"testing"
"git.a-wan.net/alan/pipelines/internal/pipeline"
"git.a-wan.net/alan/pipelines/internal/protocol"
"git.a-wan.net/alan/pipelines/internal/stage"
)
func TestRetryWaitsForExecutionCleanupEvenAfterTerminalStatus(t *testing.T) {
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
store, err := pipeline.Open(filepath.Join(t.TempDir(), "cleanup.db"))
if err != nil {
t.Fatal(err)
}
defer store.Close()
store.Submit(ctx, "workflow", pipeline.Template([]string{"one"}, true))
items, _ := store.List(ctx)
d, _ := store.Get(ctx, items[0].ID, 1)
r, err := newRunner(ctx, store)
if err != nil {
t.Fatal(err)
}
id, _, err := store.CreateRun(ctx, d, "original", t.TempDir(), false, nil, map[string]any{"prompt": "task"})
if err != nil {
t.Fatal(err)
}
if err := store.FinishRun(ctx, id, "failed", "error", "failure", nil); err != nil {
t.Fatal(err)
}
// Simulate the interval between persisting terminal status and final cleanup.
r.active[id] = func() {}
detail, err := r.getRun(id)
if err != nil || !detail.Executing {
t.Fatal("terminal run not marked executing during cleanup", detail, err)
}
runs, err := r.listRuns()
if err != nil || !runs[0].Executing {
t.Fatal("list advertised stopped run during cleanup", runs, err)
}
if _, err := r.retry(protocol.Message{RunID: id, RequestKey: "retry"}); err == nil || !strings.Contains(err.Error(), "still executing") {
t.Fatal("retry accepted during execution cleanup", err)
}
delete(r.active, id)
r.execute = func(context.Context, stage.Definition, stage.Values) (stage.Result, error) {
return stage.Result{Outcome: "success", Output: stage.Values{"summary": "done"}}, nil
}
if _, err := r.retry(protocol.Message{RunID: id, RequestKey: "retry"}); err != nil {
t.Fatal("retry rejected after cleanup", err)
}
r.wg.Wait()
}
+46 -3
View File
@@ -167,18 +167,61 @@ func (r *runner) start(request protocol.Message, retryOf ...int64) (*protocol.Ru
r.run(ctx, id, d, workspace, request)
}()
}
return r.store.GetRun(r.ctx, id)
detail, err := r.store.GetRun(r.ctx, id)
if detail != nil {
_, detail.Executing = r.active[id]
}
return detail, err
}
func (r *runner) getRun(id int64) (*protocol.RunDetail, error) {
r.mu.Lock()
defer r.mu.Unlock()
d, err := r.store.GetRun(r.ctx, id)
if d != nil {
_, d.Executing = r.active[id]
for _, s := range d.Steps {
if s.AgentActive {
d.Executing = true
}
}
}
return d, err
}
func (r *runner) listRuns() ([]protocol.RunSummary, error) {
r.mu.Lock()
defer r.mu.Unlock()
items, err := r.store.ListRuns(r.ctx)
for i := range items {
_, items[i].Executing = r.active[items[i].ID]
if items[i].Status == "failed" && !items[i].Executing {
d, err := r.store.GetRun(r.ctx, items[i].ID)
if err != nil {
return nil, err
}
for _, step := range d.Steps {
if step.AgentActive {
items[i].Executing = true
}
}
}
}
return items, err
}
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)
original, err := r.getRun(request.RunID)
if err != nil {
return nil, err
}
if original.Status != "failed" {
if original.Executing {
return nil, fmt.Errorf("run %d is still executing; wait for it to stop completely before retrying", original.ID)
}
if original.Status != "failed" || original.FinishedAt == "" {
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)
+3 -3
View File
@@ -132,15 +132,15 @@ func Handler(ctx context.Context, stores ...*pipeline.Store) http.Handler {
response.RunDetail, err = runs.retry(request)
case protocol.ListRuns:
response.Type = protocol.Runs
response.Runs, err = runs.store.ListRuns(ctx)
response.Runs, err = runs.listRuns()
case protocol.GetRun:
response.Type = protocol.Run
response.RunDetail, err = runs.store.GetRun(ctx, request.RunID)
response.RunDetail, err = runs.getRun(request.RunID)
case protocol.CancelRun:
response.Type = protocol.Run
err = runs.cancel(request.RunID)
if err == nil {
response.RunDetail, err = runs.store.GetRun(ctx, request.RunID)
response.RunDetail, err = runs.getRun(request.RunID)
}
}
if err != nil {