summaryrefslogtreecommitdiff
path: root/internal/task
diff options
context:
space:
mode:
authorPeter Stone <thepeterstone@gmail.com>2026-03-06 00:07:18 +0000
committerPeter Stone <thepeterstone@gmail.com>2026-03-06 00:07:18 +0000
commit7466b1751c4126735769a3304e1db80dab166a9e (patch)
treec5d0fe9d1018e62e3857480d471a0f6f8ebee104 /internal/task
parenta33211d0ad07f5aaf2d8bb51ba18e6790a153bb4 (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/task')
-rw-r--r--internal/task/task.go5
-rw-r--r--internal/task/task_test.go2
2 files changed, 6 insertions, 1 deletions
diff --git a/internal/task/task.go b/internal/task/task.go
index 3e74a82..587993f 100644
--- a/internal/task/task.go
+++ b/internal/task/task.go
@@ -14,6 +14,7 @@ const (
StateTimedOut State = "TIMED_OUT"
StateCancelled State = "CANCELLED"
StateBudgetExceeded State = "BUDGET_EXCEEDED"
+ StateBlocked State = "BLOCKED"
)
type Priority string
@@ -56,6 +57,7 @@ type Task struct {
DependsOn []string `yaml:"depends_on" json:"depends_on"`
State State `yaml:"-" json:"state"`
RejectionComment string `yaml:"-" json:"rejection_comment,omitempty"`
+ QuestionJSON string `yaml:"-" json:"question,omitempty"`
CreatedAt time.Time `yaml:"-" json:"created_at"`
UpdatedAt time.Time `yaml:"-" json:"updated_at"`
}
@@ -92,10 +94,11 @@ func ValidTransition(from, to State) bool {
transitions := map[State][]State{
StatePending: {StateQueued, StateCancelled},
StateQueued: {StateRunning, StateCancelled},
- StateRunning: {StateReady, StateCompleted, StateFailed, StateTimedOut, StateCancelled, StateBudgetExceeded},
+ StateRunning: {StateReady, StateCompleted, StateFailed, StateTimedOut, StateCancelled, StateBudgetExceeded, StateBlocked},
StateReady: {StateCompleted, StatePending},
StateFailed: {StateQueued}, // retry
StateTimedOut: {StateQueued}, // retry
+ StateBlocked: {StateQueued}, // answer received → re-queue as resume execution
}
for _, allowed := range transitions[from] {
if allowed == to {
diff --git a/internal/task/task_test.go b/internal/task/task_test.go
index 6498271..5d997ac 100644
--- a/internal/task/task_test.go
+++ b/internal/task/task_test.go
@@ -22,6 +22,8 @@ func TestValidTransition_AllowedTransitions(t *testing.T) {
{"running to budget exceeded", StateRunning, StateBudgetExceeded},
{"failed to queued (retry)", StateFailed, StateQueued},
{"timed out to queued (retry)", StateTimedOut, StateQueued},
+ {"running to blocked (question)", StateRunning, StateBlocked},
+ {"blocked to queued (answer resume)", StateBlocked, StateQueued},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {