diff options
| author | Peter Stone <thepeterstone@gmail.com> | 2026-03-06 00:07:18 +0000 |
|---|---|---|
| committer | Peter Stone <thepeterstone@gmail.com> | 2026-03-06 00:07:18 +0000 |
| commit | 7466b1751c4126735769a3304e1db80dab166a9e (patch) | |
| tree | c5d0fe9d1018e62e3857480d471a0f6f8ebee104 /internal/storage/db_test.go | |
| parent | a33211d0ad07f5aaf2d8bb51ba18e6790a153bb4 (diff) | |
feat: blocked task state for agent questions via session resume
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 <session-id> "<answer>"), 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 <noreply@anthropic.com>
Diffstat (limited to 'internal/storage/db_test.go')
| -rw-r--r-- | internal/storage/db_test.go | 68 |
1 files changed, 68 insertions, 0 deletions
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) + } +} |
