From 7466b1751c4126735769a3304e1db80dab166a9e Mon Sep 17 00:00:00 2001 From: Peter Stone Date: Fri, 6 Mar 2026 00:07:18 +0000 Subject: feat: blocked task state for agent questions via session resume MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit When an agent needs user input it writes a question to $CLAUDOMATOR_QUESTION_FILE and exits. The runner detects the file and returns BlockedError; the pool transitions the task to BLOCKED and stores the question JSON on the task record. The user answers via POST /api/tasks/{id}/answer. The server looks up the claude session_id from the most recent execution and submits a resume execution (claude --resume ""), freeing the executor slot entirely while waiting. Changes: - task: add StateBlocked, transitions RUNNING→BLOCKED, BLOCKED→QUEUED - storage: add session_id to executions, question_json to tasks; add GetLatestExecution and UpdateTaskQuestion methods - executor: BlockedError type; ClaudeRunner pre-assigns --session-id, sets CLAUDOMATOR_QUESTION_FILE env var, detects question file on exit; buildArgs handles --resume mode; Pool.SubmitResume for resume path - api: handleAnswerQuestion rewritten to create resume execution - preamble: add question protocol instructions for agents - web: BLOCKED state badge (indigo), question text + option buttons or free-text input with Submit on the task card footer Co-Authored-By: Claude Sonnet 4.6 --- internal/storage/db_test.go | 68 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 68 insertions(+) (limited to 'internal/storage/db_test.go') diff --git a/internal/storage/db_test.go b/internal/storage/db_test.go index 4f9069a..395574c 100644 --- a/internal/storage/db_test.go +++ b/internal/storage/db_test.go @@ -421,3 +421,71 @@ func TestUpdateExecution(t *testing.T) { t.Errorf("artifact_dir: want /tmp/exec, got %q", got.ArtifactDir) } } + +func makeTestTask(id string, now time.Time) *task.Task { + return &task.Task{ + ID: id, Name: "T-" + id, Claude: task.ClaudeConfig{Instructions: "x"}, + Priority: task.PriorityNormal, Retry: task.RetryConfig{MaxAttempts: 1, Backoff: "linear"}, + Tags: []string{}, DependsOn: []string{}, + State: task.StatePending, CreatedAt: now, UpdatedAt: now, + } +} + +func TestStorage_SessionID_RoundTrip(t *testing.T) { + db := testDB(t) + now := time.Now().UTC() + db.CreateTask(makeTestTask("sid-task", now)) + + exec := &Execution{ + ID: "sid-exec", TaskID: "sid-task", StartTime: now, Status: "RUNNING", + SessionID: "550e8400-e29b-41d4-a716-446655440000", + } + if err := db.CreateExecution(exec); err != nil { + t.Fatalf("create: %v", err) + } + + got, err := db.GetExecution("sid-exec") + if err != nil { + t.Fatalf("get: %v", err) + } + if got.SessionID != exec.SessionID { + t.Errorf("session_id: want %q, got %q", exec.SessionID, got.SessionID) + } +} + +func TestStorage_UpdateTaskQuestion(t *testing.T) { + db := testDB(t) + now := time.Now().UTC() + tk := makeTestTask("q-task", now) + db.CreateTask(tk) + + q := `{"text":"Which branch?","options":["main","develop"]}` + if err := db.UpdateTaskQuestion("q-task", q); err != nil { + t.Fatalf("update question: %v", err) + } + + got, err := db.GetTask("q-task") + if err != nil { + t.Fatalf("get: %v", err) + } + if got.QuestionJSON != q { + t.Errorf("question_json: want %q, got %q", q, got.QuestionJSON) + } +} + +func TestStorage_GetLatestExecution(t *testing.T) { + db := testDB(t) + now := time.Now().UTC() + db.CreateTask(makeTestTask("le-task", now)) + + db.CreateExecution(&Execution{ID: "le-1", TaskID: "le-task", StartTime: now, Status: "COMPLETED"}) + db.CreateExecution(&Execution{ID: "le-2", TaskID: "le-task", StartTime: now.Add(time.Minute), Status: "RUNNING"}) + + got, err := db.GetLatestExecution("le-task") + if err != nil { + t.Fatalf("get latest: %v", err) + } + if got.ID != "le-2" { + t.Errorf("want le-2, got %q", got.ID) + } +} -- cgit v1.2.3