summaryrefslogtreecommitdiff
path: root/internal/api/server.go
diff options
context:
space:
mode:
authorPeter Stone <thepeterstone@gmail.com>2026-03-06 00:09:34 +0000
committerPeter Stone <thepeterstone@gmail.com>2026-03-06 00:09:34 +0000
commit3672981c4d225bb5b7d965a8945bc7bc6e8b4e9d (patch)
tree0e40902052405b9cf0063f859a017ff3ab62ef3c /internal/api/server.go
parent7466b1751c4126735769a3304e1db80dab166a9e (diff)
fix: implement cancel endpoint and pool cancel mechanism
POST /api/tasks/{id}/cancel now works. Pool tracks a cancel func per running task ID; Cancel(taskID) calls it and returns false if the task isn't running. The execute goroutine registers/deregisters the cancel func around the runner call. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Diffstat (limited to 'internal/api/server.go')
-rw-r--r--internal/api/server.go14
1 files changed, 14 insertions, 0 deletions
diff --git a/internal/api/server.go b/internal/api/server.go
index 5758347..18c58e9 100644
--- a/internal/api/server.go
+++ b/internal/api/server.go
@@ -61,6 +61,7 @@ func (s *Server) routes() {
s.mux.HandleFunc("GET /api/tasks", s.handleListTasks)
s.mux.HandleFunc("GET /api/tasks/{id}", s.handleGetTask)
s.mux.HandleFunc("POST /api/tasks/{id}/run", s.handleRunTask)
+ s.mux.HandleFunc("POST /api/tasks/{id}/cancel", s.handleCancelTask)
s.mux.HandleFunc("POST /api/tasks/{id}/accept", s.handleAcceptTask)
s.mux.HandleFunc("POST /api/tasks/{id}/reject", s.handleRejectTask)
s.mux.HandleFunc("GET /api/tasks/{id}/subtasks", s.handleListSubtasks)
@@ -109,6 +110,19 @@ func (s *Server) BroadcastQuestion(taskID, toolUseID string, questionData json.R
s.hub.Broadcast(data)
}
+func (s *Server) handleCancelTask(w http.ResponseWriter, r *http.Request) {
+ taskID := r.PathValue("id")
+ if _, err := s.store.GetTask(taskID); err != nil {
+ writeJSON(w, http.StatusNotFound, map[string]string{"error": "task not found"})
+ return
+ }
+ if !s.pool.Cancel(taskID) {
+ writeJSON(w, http.StatusConflict, map[string]string{"error": "task is not running"})
+ return
+ }
+ writeJSON(w, http.StatusOK, map[string]string{"status": "cancelling"})
+}
+
func (s *Server) handleAnswerQuestion(w http.ResponseWriter, r *http.Request) {
taskID := r.PathValue("id")