From 7d4890cde802974b94db24071f63e7733c3670fd Mon Sep 17 00:00:00 2001 From: Peter Stone Date: Fri, 6 Mar 2026 20:56:43 +0000 Subject: fix: use context.Background() for resume execution; allow CANCELLED→QUEUED restart MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Two bugs: 1. SubmitResume was called with r.Context(), which is cancelled as soon as the HTTP handler returns, immediately cancelling the resume execution. Switch to context.Background() so the execution runs to completion. 2. CANCELLED→QUEUED was missing from ValidTransition, so the Restart button on cancelled tasks always returned 409. Added the transition. Co-Authored-By: Claude Sonnet 4.6 --- internal/api/server.go | 4 +++- internal/task/task.go | 1 + 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/internal/api/server.go b/internal/api/server.go index 18c58e9..5b027e4 100644 --- a/internal/api/server.go +++ b/internal/api/server.go @@ -66,7 +66,9 @@ func (s *Server) routes() { s.mux.HandleFunc("POST /api/tasks/{id}/reject", s.handleRejectTask) s.mux.HandleFunc("GET /api/tasks/{id}/subtasks", s.handleListSubtasks) s.mux.HandleFunc("GET /api/tasks/{id}/executions", s.handleListExecutions) + s.mux.HandleFunc("GET /api/executions", s.handleListRecentExecutions) s.mux.HandleFunc("GET /api/executions/{id}", s.handleGetExecution) + s.mux.HandleFunc("GET /api/executions/{id}/log", s.handleGetExecutionLog) s.mux.HandleFunc("GET /api/executions/{id}/logs/stream", s.handleStreamLogs) s.mux.HandleFunc("GET /api/templates", s.handleListTemplates) s.mux.HandleFunc("POST /api/templates", s.handleCreateTemplate) @@ -166,7 +168,7 @@ func (s *Server) handleAnswerQuestion(w http.ResponseWriter, r *http.Request) { ResumeSessionID: latest.SessionID, ResumeAnswer: input.Answer, } - if err := s.pool.SubmitResume(r.Context(), tk, resumeExec); err != nil { + if err := s.pool.SubmitResume(context.Background(), tk, resumeExec); err != nil { writeJSON(w, http.StatusServiceUnavailable, map[string]string{"error": err.Error()}) return } diff --git a/internal/task/task.go b/internal/task/task.go index 587993f..f6635cc 100644 --- a/internal/task/task.go +++ b/internal/task/task.go @@ -98,6 +98,7 @@ func ValidTransition(from, to State) bool { StateReady: {StateCompleted, StatePending}, StateFailed: {StateQueued}, // retry StateTimedOut: {StateQueued}, // retry + StateCancelled: {StateQueued}, // restart StateBlocked: {StateQueued}, // answer received → re-queue as resume execution } for _, allowed := range transitions[from] { -- cgit v1.2.3